LupineDeps.Mesa
Last Edited by: Spreitzer, September 13, 1985 6:33:19 pm 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;
LupineAction: TYPE = REF LupineActionRep;
LupineActionRep: TYPE = RECORD [
interfaceName, resultPrefix: ROPE,
sourceNode, switchesNode: MakeDo.Node
];
lupineClass: MakeDo.ActionClass ← NEW [MakeDo.ActionClassRep ← [
CheckConsistency: CheckLupineConsistency,
Rederive: RederiveLupine
]];
LupineFind: PROC [resultName: ROPE, finderData: REF ANY] RETURNS [found: BOOLEAN, sought: MakeDo.Node, makes, cmdFrom: MakeDo.NodeList, from: MakeDo.From, cmd: ROPE, class: MakeDo.ActionClass, 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;
la: LupineAction;
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 ← LIST[
sourceNode ← MakeDo.GetNode[sourceName ← resultPrefix.Cat[".BCD"], MakeDo.fileClass],
switchesNode ← MakeDo.GetNode[resultPrefix.Cat[".LupineSwitches"], MakeDo.fileClass]
];
foundData ← la ← NEW [LupineActionRep ← [
interfaceName: interfaceName,
resultPrefix: resultPrefix,
sourceNode: sourceNode,
switchesNode: switchesNode
]];
cmd ← DeriveCmd[la];
makes ← LIST[
Tail["RpcControl.Mesa"],
Tail["RpcClientImpl.Mesa"],
Tail["RpcBinderImpl.Mesa"],
Tail["RpcServerImpl.Mesa"]];
IF sought = NIL THEN ERROR;
from ← DeriveFrom[la];
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 [la: LupineAction] RETURNS [from: MakeDo.From] =
BEGIN
from ← [mustHave: LIST[la.sourceNode], optional: NIL];
END;
DeriveCmd: PROC [la: LupineAction] RETURNS [cmd: ROPE] = {
cmd ← IO.PutFR[
"Lupine %g TranslateInterface[%g]",
IO.rope[GetSwitches[la.resultPrefix]],
IO.rope[la.interfaceName]
]
};
RederiveLupine: PROC [a: MakeDo.Action] RETURNS [from: MakeDo.From, cmd: ROPE] --MakeDo.RederiveProc-- = {
la: LupineAction ← NARROW[a.PublicPartsOfAction[].foundData];
from ← DeriveFrom[la];
cmd ← DeriveCmd[la];
};
FindLatestIngredient: PROC [a: MakeDo.Action] RETURNS [missingIngredient, latestIngredientNode: MakeDo.Node, latestIngredientTime: MakeDo.Time] = {
PerSource: PROC [n: MakeDo.Node, which: MakeDo.ActionDep, optional: BOOL] = {
fromTime: BasicTime.GMT ← MakeDo.InnerGetCreated[n];
IF fromTime = MakeDo.notExistTime THEN {IF NOT optional THEN missingIngredient ← n}
ELSE IF latestIngredientTime.Period[fromTime] > 0 THEN {
latestIngredientTime ← fromTime;
latestIngredientNode ← n;
};
};
missingIngredient ← latestIngredientNode ← NIL;
latestIngredientTime ← BasicTime.earliestGMT;
MakeDo.InnerEnumerateSources[a, data, PerSource];
a ← a;
};
CheckLupineConsistency: PROC [a: MakeDo.Action, result: MakeDo.Node] RETURNS [consistent: BOOL, reason: ROPE] --MakeDo.ConsistencyChecker-- =
BEGIN
la: LupineAction = NARROW[a.PublicPartsOfAction[].foundData];
resultTime: MakeDo.Time = result.InnerGetCreated[];
resultName: ROPE = result.PublicPartsOfNode[].name;
missingIngredient, latestIngredientNode: MakeDo.Node;
latestIngredientTime: MakeDo.Time;
[missingIngredient, latestIngredientNode, latestIngredientTime] ← FindLatestIngredient[a];
IF missingIngredient#NIL THEN RETURN [
TRUE,
IO.PutFR[
"ingredient %g doesn't exist",
[rope[missingIngredient.PublicPartsOfNode[].name]]
]];
IF latestIngredientNode = NIL THEN ERROR;
IF resultTime = MakeDo.notExistTime THEN RETURN [
FALSE,
IO.PutFR[
"result %g doesn't exist",
[rope[resultName]]
]];
IF latestIngredientTime.Period[resultTime] < 0 THEN RETURN [
FALSE,
IO.PutFR[
"result %g (of %g) predates ingredient %g (of %g)",
[rope[resultName]],
[time[resultTime]],
[rope[latestIngredientNode.PublicPartsOfNode[].name]],
[time[latestIngredientTime]]
]];
RETURN [TRUE, "result dated later than any ingredient"];
END;
MakeDo.AddFinder[["Lupine", LupineFind], back];
END.