MODULEFor FATAL; IMPORT File, Rd, Process, FS, FileRd, OSError, RdExtras, ASCII; IMPORT M3Extension; IMPORT M3DepFindFile; M3DepGenFinder
IMPORT Thread; <*FATAL Rd.EndOfFile, Thread.Alerted*> PROCEDURENew (overrides := FALSE): M3DepFindFile.T= <*FATAL OSError.E*> VAR rd: Rd.T; stdout: File.T; ix := 1; result: M3DepFindFile.T := NIL; CONST Arg2 = ARRAY OF TEXT{"srcmap", "-O"}; BEGIN IF overrides THEN ix := 2; END; stdout := FS.OpenFile(".M3SRCMAP"); TRY IF NOT RunProcess("m3build", SUBARRAY(Arg2, 0, ix), xstdout := stdout) THEN RETURN NIL END; FINALLY stdout.close() END; TRY TRY rd := FileRd.Open(".M3SRCMAP"); (* skip noise output by m3build *) EVAL RdExtras.GetText(rd, terminate := ASCII.Set{'@'}); result := NEW(M3DepFindFile.T).init(M3Extension.All, rd, NIL); FINALLY Rd.Close(rd); END; EXCEPT | Rd.Failure => END; RETURN result; END New; PROCEDURERunProcess (cmd: TEXT; READONLY args: ARRAY OF TEXT; xstdin, xstdout, xstderr: File.T := NIL): BOOLEAN= VAR stdin, stdout, stderr: File.T; p: Process.T; BEGIN Process.GetStandardFileHandles(stdin, stdout, stderr); IF xstdin # NIL THEN stdin := xstdin END; IF xstdout # NIL THEN stdout := xstdout END; IF xstderr # NIL THEN stderr := xstderr END; TRY p := Process.Create(cmd, args, NIL, NIL, stdin, stdout, stderr); IF Process.Wait(p) # 0 THEN END; EXCEPT | OSError.E => RETURN FALSE END; RETURN TRUE; END RunProcess; BEGIN END M3DepGenFinder.