LupineDeps.Mesa
Last Edited by: Spreitzer, September 4, 1985 1:11:47 am PDT
Last Edited by: Pavel, May 28, 1984 3:06:54 pm PDT
DIRECTORY BasicTime, FS, IO, MakeDo, Rope;
LupineDeps: CEDAR PROGRAM
IMPORTS BasicTime, FS, IO, MakeDo, Rope =
BEGIN
ROPE: TYPE = Rope.ROPE;
LupineCommand: TYPE = REF LupineCommandRep;
LupineCommandRep: TYPE = RECORD [
resultPrefix: ROPE,
sourceNode, switchesNode: MakeDo.Node,
earliestResultNode, lateIngredientNode: MakeDo.Node ← NIL,
earliestResultTime, lateIngredientTime: BasicTime.GMT ← BasicTime.nullGMT,
cmd: ROPENIL];
lupineClass: MakeDo.CommandClass ← NEW [MakeDo.CommandClassRep ← [
NotCurrent: LupineNotCurrent,
Rederive: RederiveLupine,
Explain: ExplainLupine
]];
LupineFind: PROC [resultName: ROPE, finderData: REF ANY] RETURNS [found: BOOLEAN, sought: MakeDo.Node, makes: MakeDo.NodeList, from, cmdFrom: MakeDo.From, cmd: ROPE, class: MakeDo.CommandClass, foundData: REF ANY] -- MakeDo.FinderProc -- =
BEGIN
EndsIn: PROC [ending: ROPE] RETURNS [ans: BOOL] = {
elen: INT = ending.Length[];
IF elen > slen THEN RETURN [FALSE];
IF (ans ← resultShort.Substr[start: slen - elen, len: elen].Equal[s2: ending, case: FALSE]) THEN {plen ← slen - elen; sending ← ending}};
Tail: PROC [ending: ROPE] RETURNS [node: MakeDo.Node] = {
node ← MakeDo.GetNode[resultPrefix.Cat[ending], MakeDo.fileClass];
IF ending.Equal[sending] THEN sought ← node};
resultCP: FS.ComponentPositions;
resultFull, resultPrefix, resultShort, interfaceName, sourceName, sending: ROPE;
sourceNode, switchesNode: MakeDo.Node;
lc: LupineCommand;
slen, plen: INT;
sought ← NIL;
found ← TRUE;
[resultFull, resultCP, ] ← FS.ExpandName[resultName !FS.Error => {found ← FALSE; CONTINUE}];
IF NOT found THEN RETURN;
resultShort ← resultFull.Substr[start: resultCP.base.start, len: (resultCP.ext.start + resultCP.ext.length) - resultCP.base.start];
slen ← resultShort.Length[];
found ← EndsIn["RpcControl.Mesa"] OR EndsIn["RpcClientImpl.Mesa"] OR EndsIn["RpcBinderImpl.Mesa"] OR EndsIn["RpcServerImpl.Mesa"];
IF NOT found THEN RETURN;
interfaceName ← resultShort.Substr[start: 0, len: plen];
resultPrefix ← resultFull.Substr[start: 0, len: resultCP.base.start].Concat[interfaceName];
cmdFrom ← [
mustHave: NIL,
optional: LIST[
sourceNode ← MakeDo.GetNode[sourceName ← resultPrefix.Cat[".BCD"], MakeDo.fileClass],
switchesNode ← MakeDo.GetNode[resultPrefix.Cat[".LupineSwitches"], MakeDo.fileClass]
]
];
foundData ← lc ← NEW [LupineCommandRep ← [
resultPrefix: resultPrefix,
sourceNode: sourceNode,
switchesNode: switchesNode,
cmd: cmd ← IO.PutFR["Lupine %g TranslateInterface[%g]", IO.rope[GetSwitches[resultPrefix]], IO.rope[interfaceName]]
]];
makes ← LIST[
Tail["RpcControl.Mesa"],
Tail["RpcClientImpl.Mesa"],
Tail["RpcBinderImpl.Mesa"],
Tail["RpcServerImpl.Mesa"]];
IF sought = NIL THEN ERROR;
from ← DeriveFrom[lc];
class ← lupineClass;
END;
GetSwitches: PROC [resultPrefix: ROPE] RETURNS [switches: ROPE] = {
ss: IO.STREAMNIL;
ss ← FS.StreamOpen[resultPrefix.Cat[".LupineSwitches"] !FS.Error => CONTINUE];
IF ss = NIL THEN RETURN [NIL];
[] ← ss.SkipWhitespace[];
IF ss.EndOf[] THEN RETURN [NIL];
switches ← ss.GetLineRope[];
ss.Close[];
};
DeriveFrom: PROC [lc: LupineCommand] RETURNS [from: MakeDo.From] =
BEGIN
from ← [mustHave: LIST[lc.sourceNode], optional: NIL];
END;
RederiveLupine: PROC [c: MakeDo.Command] RETURNS [from: MakeDo.From, cmd: ROPE] --MakeDo.RederiveProc-- = {
lc: LupineCommand ← NARROW[c.PublicPartsOfCommand[].foundData];
from ← DeriveFrom[lc];
cmd ← lc.cmd};
LupineNotCurrent: PROC [c: MakeDo.Command, Needed: PROC [MakeDo.Node] RETURNS [BOOL]] RETURNS [whyNotCurrent: ROPE--NIL means all outputs up-to-date--] --MakeDo.NotCurrentProc-- =
BEGIN
lc: LupineCommand = NARROW[c.PublicPartsOfCommand[].foundData];
PerSource: PROC [n: MakeDo.Node, which: MakeDo.CmdDep, optional: BOOL] = {
fromTime: BasicTime.GMT ← MakeDo.GetCreated[n];
IF (fromTime # MakeDo.notExistTime) AND (lc.lateIngredientTime.Period[fromTime] > 0) THEN {
lc.lateIngredientTime ← fromTime;
lc.lateIngredientNode ← n;
};
};
PerResult: PROC [made: MakeDo.Node] = {
thisTime: BasicTime.GMT;
IF NOT Needed[made] THEN RETURN;
thisTime ← MakeDo.GetCreated[made];
IF thisTime # MakeDo.notExistTime AND thisTime.Period[lc.earliestResultTime] > 0
THEN {lc.earliestResultTime ← thisTime; lc.earliestResultNode ← made};
};
whyNotCurrent ← NIL;
lc.earliestResultTime ← BasicTime.latestGMT;
lc.lateIngredientTime ← BasicTime.earliestGMT;
lc.earliestResultNode ← lc.lateIngredientNode ← NIL;
MakeDo.EnumerateResults[c, PerResult];
IF lc.earliestResultNode = NIL THEN RETURN;
MakeDo.InnerEnumerateSources[c, data, PerSource];
IF (lc.lateIngredientTime # BasicTime.earliestGMT) AND (lc.lateIngredientTime.Period[lc.earliestResultTime] < 0) THEN {
whyNotCurrent ← IO.PutFR[
"result %g (of %g) predates ingredient %g (of %g)",
[rope[lc.earliestResultNode.PublicPartsOfNode[].name]],
[time[lc.earliestResultTime]],
[rope[lc.lateIngredientNode.PublicPartsOfNode[].name]],
[time[lc.lateIngredientTime]]
];
};
END;
ExplainLupine: PROC [c: MakeDo.Command, to: IO.STREAM] --MakeDo.ExplainProc-- =
BEGIN
lc: LupineCommand = NARROW[c.PublicPartsOfCommand[].foundData];
NeedAll: PROC [MakeDo.Node] RETURNS [BOOL] = {RETURN [TRUE]};
whyNotCurrent: ROPE ← LupineNotCurrent[c, NeedAll];
IF lc.earliestResultNode = NIL THEN to.PutRope["\tno result files exist.\n"]
ELSE IF lc.lateIngredientNode = NIL THEN to.PutRope["\tno ingredients exist.\n"]
ELSE IF whyNotCurrent # NIL THEN to.PutF["\t%g.\n", IO.rope[whyNotCurrent]]
ELSE to.PutRope["\tall result files are dated later than any ingredient file.\n"];
END;
MakeDo.AddFinder[["Lupine", LupineFind], back];
END.