Tidy up the prettification of the default verbosity c compilation output
This commit is contained in:
parent
679aefd89c
commit
06c32aab29
2 changed files with 28 additions and 25 deletions
|
|
@ -596,21 +596,24 @@ proc callCCompiler*(projectfile: string) =
|
||||||
var script: PRope = nil
|
var script: PRope = nil
|
||||||
var cmds: TStringSeq = @[]
|
var cmds: TStringSeq = @[]
|
||||||
var prettyCmds: TStringSeq = @[]
|
var prettyCmds: TStringSeq = @[]
|
||||||
|
let prettyCb = proc (idx: int) =
|
||||||
|
echo prettyCmds[idx]
|
||||||
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 gVerbosity != 1:
|
|
||||||
prettyCmds = @[]
|
|
||||||
if optCompileOnly notin gGlobalOptions:
|
if optCompileOnly notin gGlobalOptions:
|
||||||
if gNumberOfProcessors == 0: gNumberOfProcessors = countProcessors()
|
if gNumberOfProcessors == 0: gNumberOfProcessors = countProcessors()
|
||||||
var res = 0
|
var res = 0
|
||||||
if gNumberOfProcessors <= 1:
|
if gNumberOfProcessors <= 1:
|
||||||
for i in countup(0, high(cmds)): res = max(execCmd(cmds[i]), res)
|
for i in countup(0, high(cmds)): res = max(execCmd(cmds[i]), res)
|
||||||
elif optListCmd in gGlobalOptions or gVerbosity > 0:
|
elif optListCmd in gGlobalOptions or gVerbosity > 1:
|
||||||
res = execProcesses(cmds, {poEchoCmd, poUseShell, poParentStreams},
|
res = execProcesses(cmds, {poEchoCmd, poUseShell, poParentStreams},
|
||||||
gNumberOfProcessors, prettyCmds)
|
gNumberOfProcessors)
|
||||||
else:
|
elif gVerbosity == 1:
|
||||||
res = execProcesses(cmds, {poUseShell, poParentStreams},
|
res = execProcesses(cmds, {poUseShell, poParentStreams},
|
||||||
gNumberOfProcessors, prettyCmds)
|
gNumberOfProcessors, prettyCb)
|
||||||
|
else:
|
||||||
|
res = execProcesses(cmds, {poUseShell, poParentStreams},
|
||||||
|
gNumberOfProcessors)
|
||||||
if res != 0:
|
if res != 0:
|
||||||
if gNumberOfProcessors <= 1:
|
if gNumberOfProcessors <= 1:
|
||||||
rawMessage(errExecutionOfProgramFailed, [])
|
rawMessage(errExecutionOfProgramFailed, [])
|
||||||
|
|
|
||||||
|
|
@ -236,31 +236,23 @@ 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(),
|
||||||
prettyCmds: openArray[string] = @[]): int
|
beforeRunEvent: proc(idx: int){.closure.}): int
|
||||||
{.rtl, extern: "nosp$1",
|
{.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
|
||||||
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
|
|
||||||
## executes the commands `cmds` in parallel. Creates `n` processes
|
## executes the commands `cmds` in parallel. Creates `n` processes
|
||||||
## that execute in parallel. The highest return value of all processes
|
## that execute in parallel. The highest return value of all processes
|
||||||
## is returned. If `prettyCmds` are provided, prints them on the console
|
## is returned. Runs `beforeRunEvent` before running each command.
|
||||||
## instead of the real commands (for prettier output).
|
|
||||||
var options = options
|
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
# poParentStreams causes problems on Posix, so we simply disable it:
|
# poParentStreams causes problems on Posix, so we simply disable it:
|
||||||
options = options - {poParentStreams}
|
var options = options - {poParentStreams}
|
||||||
|
|
||||||
assert n > 0
|
assert n > 0
|
||||||
var usePrettyPrintouts = false
|
|
||||||
if prettyCmds.len == cmds.len:
|
|
||||||
options = options - {poEchoCmd}
|
|
||||||
usePrettyPrintouts = true
|
|
||||||
if n > 1:
|
if n > 1:
|
||||||
var q: seq[Process]
|
var q: seq[Process]
|
||||||
newSeq(q, n)
|
newSeq(q, n)
|
||||||
var m = min(n, cmds.len)
|
var m = min(n, cmds.len)
|
||||||
for i in 0..m-1:
|
for i in 0..m-1:
|
||||||
|
beforeRunEvent(i)
|
||||||
q[i] = startCmd(cmds[i], options=options)
|
q[i] = startCmd(cmds[i], options=options)
|
||||||
if usePrettyPrintouts:
|
|
||||||
echo prettyCmds[i]
|
|
||||||
when defined(noBusyWaiting):
|
when defined(noBusyWaiting):
|
||||||
var r = 0
|
var r = 0
|
||||||
for i in m..high(cmds):
|
for i in m..high(cmds):
|
||||||
|
|
@ -273,9 +265,8 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
echo(err)
|
echo(err)
|
||||||
result = max(waitForExit(q[r]), result)
|
result = max(waitForExit(q[r]), result)
|
||||||
if q[r] != nil: close(q[r])
|
if q[r] != nil: close(q[r])
|
||||||
|
beforeRunEvent(i)
|
||||||
q[r] = startCmd(cmds[i], options=options)
|
q[r] = startCmd(cmds[i], options=options)
|
||||||
if usePrettyPrintouts:
|
|
||||||
echo prettyCmds[i]
|
|
||||||
r = (r + 1) mod n
|
r = (r + 1) mod n
|
||||||
else:
|
else:
|
||||||
var i = m
|
var i = m
|
||||||
|
|
@ -286,9 +277,8 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
#echo(outputStream(q[r]).readLine())
|
#echo(outputStream(q[r]).readLine())
|
||||||
result = max(waitForExit(q[r]), result)
|
result = max(waitForExit(q[r]), result)
|
||||||
if q[r] != nil: close(q[r])
|
if q[r] != nil: close(q[r])
|
||||||
|
beforeRunEvent(i)
|
||||||
q[r] = startCmd(cmds[i], options=options)
|
q[r] = startCmd(cmds[i], options=options)
|
||||||
if usePrettyPrintouts:
|
|
||||||
echo prettyCmds[i]
|
|
||||||
inc(i)
|
inc(i)
|
||||||
if i > high(cmds): break
|
if i > high(cmds): break
|
||||||
for j in 0..m-1:
|
for j in 0..m-1:
|
||||||
|
|
@ -296,12 +286,22 @@ proc execProcesses*(cmds: openArray[string],
|
||||||
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):
|
||||||
|
beforeRunEvent(i)
|
||||||
var p = startCmd(cmds[i], options=options)
|
var p = startCmd(cmds[i], options=options)
|
||||||
if usePrettyPrintouts:
|
|
||||||
echo prettyCmds[i]
|
|
||||||
result = max(waitForExit(p), result)
|
result = max(waitForExit(p), result)
|
||||||
close(p)
|
close(p)
|
||||||
|
|
||||||
|
let emptyCb = proc(idx: int) {.closure.} = discard
|
||||||
|
proc execProcesses*(cmds: openArray[string],
|
||||||
|
options = {poStdErrToStdOut, poParentStreams},
|
||||||
|
n = countProcessors()): int
|
||||||
|
{.rtl, extern: "nosp$1",
|
||||||
|
tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} =
|
||||||
|
## executes the commands `cmds` in parallel. Creates `n` processes
|
||||||
|
## that execute in parallel. The highest return value of all processes
|
||||||
|
## is returned.
|
||||||
|
return execProcesses(cmds, options, n, emptyCb)
|
||||||
|
|
||||||
proc select*(readfds: var seq[Process], timeout = 500): int
|
proc select*(readfds: var seq[Process], timeout = 500): int
|
||||||
## `select` with a sensible Nim interface. `timeout` is in miliseconds.
|
## `select` with a sensible Nim interface. `timeout` is in miliseconds.
|
||||||
## Specify -1 for no timeout. Returns the number of processes that are
|
## Specify -1 for no timeout. Returns the number of processes that are
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue