GenMap: Commander.CommandProc = {
[cmd: Handle] RETURNS [result: REF ← NIL, msg: ROPE ← NIL]
ris: STREAM = IO.RIS[cmd.commandLine];
token: ROPE ← "CurrentCedar";
dump: BOOL ← TRUE;
dumpDebug: BOOL ← TRUE;
namesOnly: BOOL ← FALSE;
remoteOpened: BOOL ← FALSE;
pos,bang,dot: INT ← 0;
inName,sourceName,objectName,outPrefix: ROPE ← NIL;
command: ROPE ← cmd.command;
forkers: NAT ← 0;
results: GenerateDFClosure.ClosureInfo;
myData: MyData;
sourceMap: Map ← NIL;
objectMap: Map ← NIL;
checkRemote: BOOL ← TRUE;
inLog,outLog: STREAM ← NIL;
genMaps: BOOL ← FALSE; -- gen regular version maps if TRUE
trustOld: BOOL ← FALSE; -- trust old version maps if TRUE
token ← IO.GetTokenRope[ris, IO.IDProc ! IO.EndOfStream => CONTINUE].token;
[pos,bang,dot] ← ScanName[inName ← token];
IF bang = Rope.Size[inName]
-- no version stuff
AND (bang-dot # 3 OR Rope.Run[inName, dot, ".df", 0, FALSE] # 3) -- no DF extension
THEN inName ← Rope.Concat[token, ".df"];
inName ←
FS.FileInfo[inName
!
FS.Error =>
IF error.group # bug
THEN {
IO.PutF[
cmd.out, "\nCan't open %g\n %g\n",
[rope[inName]], [rope[error.explanation]]];
GO TO quit;
};
].fullFName;
[inLog,outLog] ← ViewerIO.CreateViewerStreams[
"VersionMapBuilder.log", NIL, "VersionMapBuilder.log", FALSE];
[pos,bang,dot] ← ScanName[inName];
outPrefix ← Rope.Flatten[inName, pos, dot-pos];
IO.PutF[outLog, "\nVersion Map Builder started at %g", [time[BasicTime.Now[]]]];
IO.PutF[outLog, "\n\nInput from: %g\n", [rope[inName]]];
sourceName ← Rope.Concat[outPrefix, ".sourceMap"];
objectName ← Rope.Concat[outPrefix, ".objectMap"];
TRUSTED {IFSFile.Initialize[]};
{
ENABLE
UNWIND => {
FinalizeRemoteHandle[myData];
};
SELECT
TRUE
FROM
Rope.Equal[command, "TestMap",
FALSE] => {
forkers ← 0;
};
Rope.Equal[command, "TestMap1",
FALSE] => {
forkers ← 1;
};
Rope.Equal[command, "TestMap2",
FALSE] => {
forkers ← 2;
};
Rope.Equal[command, "TestMap3",
FALSE] => {
forkers ← 3;
};
Rope.Equal[command, "TestMap4",
FALSE] => {
forkers ← 4;
};
Rope.Equal[command, "TestMap8",
FALSE] => {
forkers ← 8;
};
Rope.Equal[command, "GenMap",
FALSE] => {
forkers ← 2;
genMaps ← TRUE;
};
Rope.Equal[command, "MergeMap",
FALSE] => {
forkers ← 2;
trustOld ← genMaps ← TRUE;
};
Rope.Equal[command, "GenCedarMap",
FALSE] => {
forkers ← 2;
genMaps ← TRUE;
outPrefix ← "Cedar";
};
Rope.Equal[command, "MergeCedarMap",
FALSE] => {
forkers ← 2;
trustOld ← genMaps ← TRUE;
outPrefix ← "Cedar";
};
ENDCASE;
myData ←
NEW[MyDataRep ← [
sourceQueue: PriorityQueue.Predict[2000, EntrySortPred],
objectQueue: PriorityQueue.Predict[1500, EntrySortPred],
errs: outLog,
checkRemote: checkRemote
]];
IF genMaps
THEN {
sourceName ← Rope.Concat[outPrefix, "Source.VersionMap"];
objectName ← Rope.Concat[outPrefix, "Symbols.VersionMap"];
};
IF trustOld
THEN {
Setup the old maps (if any); also make an index for the object map.
IO.PutRope[outLog, "\nReading old maps."];
myData.oldSourceMap ←
LIST[
VersionMap.RestoreMapFromFile[sourceName
!
FS.Error => {
IO.PutRope[outLog, "\nWarning, can't read "];
IO.PutRope[outLog, sourceName];
CONTINUE}]
];
myData.oldObjectMap ←
LIST[
VersionMap.RestoreMapFromFile[objectName
!
FS.Error => {
IO.PutRope[outLog, "\nWarning, can't read "];
IO.PutRope[outLog, objectName];
GO TO exit}]
];
EXITS exit => {};
};
CheckAbort[myData];
myData.which ← both;
IO.PutRope[outLog, "\nGenerating DF closure."];
results ← GenerateDFClosure.GenerateClosureToProc[
inName, outLog, EachFile, myData, [toFork: forkers]];
};
FinalizeRemoteHandle[myData];
IO.PutF[outLog, "\n\n%g DF files, %g source files, %g object files.\n",
[integer[results.dfFiles]], [integer[myData.sourceFiles]], [integer[myData.objectFiles]]];
IO.PutRope[outLog, "\nMaking short name index for source map."];
sourceMap ← VersionMapFromPQ[myData.sourceQueue, myData.prefix, myData];
CheckAbort[myData];
IO.PutRope[outLog, "\n\nWriting "];
IO.PutRope[outLog, sourceName];
IO.PutRope[outLog, "\n"];
IF genMaps
THEN VersionMap.SaveMapToFile[sourceMap, sourceName]
ELSE WriteMapToFile[sourceMap, sourceName];
IO.PutRope[outLog, "\nMaking short name index for object map."];
objectMap ← VersionMapFromPQ[myData.objectQueue, myData.prefix, myData];
CheckAbort[myData];
IO.PutRope[outLog, "\n\nWriting "];
IO.PutRope[outLog, objectName];
IO.PutRope[outLog, "\n"];
IF genMaps
THEN VersionMap.SaveMapToFile[objectMap, objectName]
ELSE WriteMapToFile[objectMap, objectName];
IO.PutF[outLog, "\n\nVersion maps built at %g\n\n", [time[BasicTime.Now[]]]];
IO.Close[inLog];
IO.Close[outLog];
EXITS quit => {};
};