MakeItDepsImpl.mesa
Copyright © 1986 by Xerox Corporation. All rights reserved.
Eric Nickell, August 19, 1986 11:37:10 am PDT
Mike Spreitzer June 23, 1986 12:06:51 pm PDT
DIRECTORY
BasicTime USING [GMT, Period],
FS USING [ComponentPositions, Error, ExpandName, FileInfo, StreamOpen],
IO USING [Close, EndOfStream, GetLineRope, GetTokenRope, IDProc, PutFR, RIS, STREAM],
MakeDo,
Rope USING [Cat, Find, Match, ROPE, Substr];
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
MakeItData:
TYPE ~
RECORD [
makeItFile: ROPE
];
makeItClass: MakeDo.ActionClass ←
NEW[MakeDo.ActionClassRep ← [
CheckConsistency: CheckMakeItConsistency,
Rederive: RederiveMakeIt
]];
MakeItFind: MakeDo.FinderProc = {
[resultName: ROPE, finderData: REF ANY] RETURNS [found: BOOLEAN, sought: MakeDo.Node, makes: MakeDo.NodeList, cmdFrom: MakeDo.NodeList, from: MakeDo.From, cmd: ROPE, class: MakeDo.ActionClass, foundData: REF ANY]
makeItData: REF MakeItData;
makeItName: ROPE;
resultName ← FS.ExpandName[name: resultName ! FS.Error => GOTO Fail].fullFName;
makeItName ← WithoutVersion[FS.FileInfo[name: Rope.Cat[resultName, ".MakeIt"] ! FS.Error => GOTO Fail].fullFName];
foundData ← makeItData ←
NEW[MakeItData ← [
makeItFile: makeItName
]];
from ← DeriveFrom[makeItData];
cmdFrom ← LIST[MakeDo.GetNode[someName: makeItName, class: MakeDo.fileClass]];
makes ← LIST[sought ← MakeDo.GetNode[someName: resultName, class: MakeDo.fileClass]];
cmd ← DeriveCmd[makeItData];
class ← makeItClass;
found ← TRUE;
EXITS Fail => {
found ← FALSE;
sought ← NIL;
};
};
WithoutVersion:
PROC [with:
ROPE]
RETURNS [without:
ROPE] ~ {
cp: FS.ComponentPositions;
[fullFName: without, cp: cp] ← FS.ExpandName[name: with];
without ← Rope.Substr[base: without, len: cp.ext.start+cp.ext.length];
};
DeriveCmd:
PROC [makeItData:
REF MakeItData]
RETURNS [cmd:
ROPE] ~ {
RETURN [Rope.Cat["SecondSource ", makeItData.makeItFile]];
};
DeriveFrom:
PROC [makeItData:
REF MakeItData]
RETURNS [from: MakeDo.From] ~ {
s: IO.STREAM ← FS.StreamOpen[fileName: makeItData.makeItFile];
line: ROPE;
from ← [mustHave: LIST[MakeDo.GetNode[someName: FS.ExpandName[name: makeItData.makeItFile].fullFName, class: MakeDo.fileClass]], optional: NIL];
UNTIL Rope.Match[pattern: "--*{*}*", object: line ← IO.GetLineRope[s ! IO.EndOfStream => GOTO NotDependentOnAnything]] DO ENDLOOP;
IO.Close[self: s];
Here, line matches the specified pattern
line ← Rope.Substr[base: line, start: Rope.Find[s1: line, s2: "{"]+1]; --Strip thru "{"
line ← Rope.Substr[base: line, len: Rope.Find[s1: line, s2: "}"]]; -- Strip "}", etc.
s ← IO.RIS[rope: line];
DO
token: ROPE ~ FS.ExpandName[IO.GetTokenRope[stream: s, breakProc: IO.IDProc ! IO.EndOfStream => EXIT].token].fullFName;
from.mustHave ← CONS[MakeDo.GetNode[someName: token, class: MakeDo.fileClass], from.mustHave];
ENDLOOP;
IO.Close[self: s];
EXITS NotDependentOnAnything => {};
};
ForceConsistencyReturn: ERROR [setConsistent: BOOL, setReason: ROPE] ~ CODE;
CheckMakeItConsistency: MakeDo.ConsistencyChecker = {
[a: MakeDo.Action, result: MakeDo.Node] RETURNS [consistent: BOOL, reason: ROPE]
PerIngredient:
PROC [n: MakeDo.Node, which: MakeDo.ActionDep, optional:
BOOL] ~ {
nodeTime: BasicTime.GMT ← MakeDo.InnerGetCreated[n];
nodeName: ROPE ~ MakeDo.PublicPartsOfNode[n: n].name;
SELECT
TRUE
FROM
nodeTime = MakeDo.notExistTime => {
IF ~optional THEN ERROR ForceConsistencyReturn[setConsistent: TRUE, setReason: IO.PutFR[format: "ingredient %g doesn't exist", v1: [rope[nodeName]]]];
};
resultTime = MakeDo.notExistTime => {}; --More important than anything below
BasicTime.Period[from: nodeTime, to: resultTime] < 0 => ERROR ForceConsistencyReturn[setConsistent: FALSE, setReason: IO.PutFR[format: "result %g (of %g) predates ingredient %g (of %g)", v1: [rope[resultName]], v2: [time[resultTime]], v3: [rope[nodeName]], v4: [time[nodeTime]]]]
ENDCASE;
};
makeItData: REF MakeItData ~ NARROW[MakeDo.PublicPartsOfAction[a].foundData];
resultTime: MakeDo.Time = result.InnerGetCreated[];
resultName: ROPE = MakeDo.PublicPartsOfNode[n: result].name;
MakeDo.InnerEnumerateSources[a: a, which: data, to: PerIngredient ! ForceConsistencyReturn => {
consistent ← setConsistent;
reason ← setReason;
GOTO Exit;
}];
IF resultTime = MakeDo.notExistTime THEN RETURN [consistent: FALSE, reason: IO.PutFR[format: "result %g doesn't exist", v1: [rope[resultName]]]]
ELSE RETURN [consistent: TRUE, reason: "result dated later than any ingredient"];
EXITS Exit => {};
};
RederiveMakeIt: MakeDo.RederiveProc = {
[a: MakeDo.Action] RETURNS [from: MakeDo.From, cmd: ROPE]
makeItData: REF MakeItData ~ NARROW[MakeDo.PublicPartsOfAction[a].foundData];
from ← DeriveFrom[makeItData];
cmd ← DeriveCmd[makeItData];
};
MakeDo.AddFinder[finder: [name: "MakeIt", finderProc: MakeItFind], end: front];