Merge pull request #3402 from tmm1/exec-processes-after-cb
Add afterRunEvent callback to execProcesses()
This commit is contained in:
commit
c85fbb6fd4
3 changed files with 21 additions and 13 deletions
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs,
|
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs,
|
||||||
securehash
|
securehash, streams
|
||||||
|
|
||||||
type
|
type
|
||||||
TSystemCC* = enum
|
TSystemCC* = enum
|
||||||
|
|
@ -672,6 +672,12 @@ proc callCCompiler*(projectfile: string) =
|
||||||
var prettyCmds: TStringSeq = @[]
|
var prettyCmds: TStringSeq = @[]
|
||||||
let prettyCb = proc (idx: int) =
|
let prettyCb = proc (idx: int) =
|
||||||
echo prettyCmds[idx]
|
echo prettyCmds[idx]
|
||||||
|
let runCb = proc (idx: int, p: Process) =
|
||||||
|
let exitCode = p.peekExitCode
|
||||||
|
if exitCode != 0:
|
||||||
|
rawMessage(errGenerated, "execution of an external compiler program '" &
|
||||||
|
cmds[idx] & "' failed with exit code: " & $exitCode & "\n\n" &
|
||||||
|
p.outputStream.readAll.strip)
|
||||||
compileCFile(toCompile, script, cmds, prettyCmds, false)
|
compileCFile(toCompile, script, cmds, prettyCmds, false)
|
||||||
compileCFile(externalToCompile, script, cmds, prettyCmds, true)
|
compileCFile(externalToCompile, script, cmds, prettyCmds, true)
|
||||||
if optCompileOnly notin gGlobalOptions:
|
if optCompileOnly notin gGlobalOptions:
|
||||||
|
|
@ -682,22 +688,17 @@ proc callCCompiler*(projectfile: string) =
|
||||||
res = execWithEcho(cmds[i])
|
res = execWithEcho(cmds[i])
|
||||||
if res != 0: rawMessage(errExecutionOfProgramFailed, cmds[i])
|
if res != 0: rawMessage(errExecutionOfProgramFailed, cmds[i])
|
||||||
elif optListCmd in gGlobalOptions or gVerbosity > 1:
|
elif optListCmd in gGlobalOptions or gVerbosity > 1:
|
||||||
res = execProcesses(cmds, {poEchoCmd, poUsePath, poParentStreams},
|
res = execProcesses(cmds, {poEchoCmd, poStdErrToStdOut, poUsePath, poParentStreams},
|
||||||
gNumberOfProcessors)
|
gNumberOfProcessors, afterRunEvent=runCb)
|
||||||
elif gVerbosity == 1:
|
elif gVerbosity == 1:
|
||||||
res = execProcesses(cmds, {poUsePath, poParentStreams},
|
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
|
||||||
gNumberOfProcessors, prettyCb)
|
gNumberOfProcessors, prettyCb, afterRunEvent=runCb)
|
||||||
else:
|
else:
|
||||||
res = execProcesses(cmds, {poUsePath, poParentStreams},
|
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
|
||||||
gNumberOfProcessors)
|
gNumberOfProcessors, afterRunEvent=runCb)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
if gNumberOfProcessors <= 1:
|
if gNumberOfProcessors <= 1:
|
||||||
rawMessage(errExecutionOfProgramFailed, cmds.join())
|
rawMessage(errExecutionOfProgramFailed, cmds.join())
|
||||||
else:
|
|
||||||
rawMessage(errGenerated,
|
|
||||||
" execution of an external compiler program failed: " &
|
|
||||||
cmds.join() & "; " &
|
|
||||||
"rerun with --parallelBuild:1 to see the error message")
|
|
||||||
if optNoLinking notin gGlobalOptions:
|
if optNoLinking notin gGlobalOptions:
|
||||||
# call the linker:
|
# call the linker:
|
||||||
var it = PStrEntry(toLink.head)
|
var it = PStrEntry(toLink.head)
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,8 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} =
|
||||||
proc execProcesses*(cmds: openArray[string],
|
proc execProcesses*(cmds: openArray[string],
|
||||||
options = {poStdErrToStdOut, poParentStreams},
|
options = {poStdErrToStdOut, poParentStreams},
|
||||||
n = countProcessors(),
|
n = countProcessors(),
|
||||||
beforeRunEvent: proc(idx: int) = nil): int
|
beforeRunEvent: proc(idx: int) = nil,
|
||||||
|
afterRunEvent: proc(idx: int, p: Process) = nil): int
|
||||||
{.rtl, extern: "nosp$1",
|
{.rtl, extern: "nosp$1",
|
||||||
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} =
|
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} =
|
||||||
## executes the commands `cmds` in parallel. Creates `n` processes
|
## executes the commands `cmds` in parallel. Creates `n` processes
|
||||||
|
|
@ -278,6 +279,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
err.add("\n")
|
err.add("\n")
|
||||||
echo(err)
|
echo(err)
|
||||||
result = max(waitForExit(q[r]), result)
|
result = max(waitForExit(q[r]), result)
|
||||||
|
if afterRunEvent != nil: afterRunEvent(r, q[r])
|
||||||
if q[r] != nil: close(q[r])
|
if q[r] != nil: close(q[r])
|
||||||
if beforeRunEvent != nil:
|
if beforeRunEvent != nil:
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
|
|
@ -291,6 +293,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
if not running(q[r]):
|
if not running(q[r]):
|
||||||
#echo(outputStream(q[r]).readLine())
|
#echo(outputStream(q[r]).readLine())
|
||||||
result = max(waitForExit(q[r]), result)
|
result = max(waitForExit(q[r]), result)
|
||||||
|
if afterRunEvent != nil: afterRunEvent(r, q[r])
|
||||||
if q[r] != nil: close(q[r])
|
if q[r] != nil: close(q[r])
|
||||||
if beforeRunEvent != nil:
|
if beforeRunEvent != nil:
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
|
|
@ -299,6 +302,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
if i > high(cmds): break
|
if i > high(cmds): break
|
||||||
for j in 0..m-1:
|
for j in 0..m-1:
|
||||||
result = max(waitForExit(q[j]), result)
|
result = max(waitForExit(q[j]), result)
|
||||||
|
if afterRunEvent != nil: afterRunEvent(j, q[j])
|
||||||
if q[j] != nil: close(q[j])
|
if q[j] != nil: close(q[j])
|
||||||
else:
|
else:
|
||||||
for i in 0..high(cmds):
|
for i in 0..high(cmds):
|
||||||
|
|
@ -306,6 +310,7 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
beforeRunEvent(i)
|
beforeRunEvent(i)
|
||||||
var p = startProcess(cmds[i], options=options + {poEvalCommand})
|
var p = startProcess(cmds[i], options=options + {poEvalCommand})
|
||||||
result = max(waitForExit(p), result)
|
result = max(waitForExit(p), result)
|
||||||
|
if afterRunEvent != nil: afterRunEvent(i, p)
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
proc select*(readfds: var seq[Process], timeout = 500): int {.benign.}
|
proc select*(readfds: var seq[Process], timeout = 500): int {.benign.}
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,8 @@ proc compilerOutputTests(test: TTest, given: var TSpec, expected: TSpec;
|
||||||
expectedmsg = expected.nimout
|
expectedmsg = expected.nimout
|
||||||
givenmsg = given.nimout.strip
|
givenmsg = given.nimout.strip
|
||||||
nimoutCheck(test, expectedmsg, given)
|
nimoutCheck(test, expectedmsg, given)
|
||||||
|
else:
|
||||||
|
givenmsg = given.nimout.strip
|
||||||
if given.err == reSuccess: inc(r.passed)
|
if given.err == reSuccess: inc(r.passed)
|
||||||
r.addResult(test, expectedmsg, givenmsg, given.err)
|
r.addResult(test, expectedmsg, givenmsg, given.err)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue