Prettify compiler output for verbosity=1

Long lines displaying the invocation of the c compiler are replaced
with short, readable lines.
This commit is contained in:
Erwan Ameil 2014-10-12 23:30:32 +02:00
commit 679aefd89c
2 changed files with 43 additions and 15 deletions

View file

@ -412,8 +412,12 @@ proc addFileToLink*(filename: string) =
prependStr(toLink, filename) prependStr(toLink, filename)
# BUGFIX: was ``appendStr`` # BUGFIX: was ``appendStr``
proc execExternalProgram*(cmd: string) = proc execExternalProgram*(cmd: string, prettyCmd = "") =
if optListCmd in gGlobalOptions or gVerbosity > 0: msgWriteln(cmd) if optListCmd in gGlobalOptions or gVerbosity > 0:
if prettyCmd != "":
msgWriteln(prettyCmd)
else:
msgWriteln(cmd)
if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "") if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "")
proc generateScript(projectFile: string, script: PRope) = proc generateScript(projectFile: string, script: PRope) =
@ -567,13 +571,15 @@ proc addExternalFileToCompile*(filename: string) =
appendStr(externalToCompile, filename) appendStr(externalToCompile, filename)
proc compileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq, proc compileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq,
isExternal: bool) = prettyCmds: var TStringSeq, isExternal: bool) =
var it = PStrEntry(list.head) var it = PStrEntry(list.head)
while it != nil: while it != nil:
inc(fileCounter) # call the C compiler for the .c file: inc(fileCounter) # call the C compiler for the .c file:
var compileCmd = getCompileCFileCmd(it.data, isExternal) var compileCmd = getCompileCFileCmd(it.data, isExternal)
if optCompileOnly notin gGlobalOptions: if optCompileOnly notin gGlobalOptions:
add(cmds, compileCmd) add(cmds, compileCmd)
let (dir, name, ext) = splitFile(it.data)
add(prettyCmds, "CC: " & name)
if optGenScript in gGlobalOptions: if optGenScript in gGlobalOptions:
app(script, compileCmd) app(script, compileCmd)
app(script, tnl) app(script, tnl)
@ -589,8 +595,11 @@ proc callCCompiler*(projectfile: string) =
var c = cCompiler var c = cCompiler
var script: PRope = nil var script: PRope = nil
var cmds: TStringSeq = @[] var cmds: TStringSeq = @[]
compileCFile(toCompile, script, cmds, false) var prettyCmds: TStringSeq = @[]
compileCFile(externalToCompile, script, cmds, true) compileCFile(toCompile, script, cmds, prettyCmds, false)
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
@ -598,10 +607,10 @@ proc callCCompiler*(projectfile: string) =
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 > 0:
res = execProcesses(cmds, {poEchoCmd, poUseShell, poParentStreams}, res = execProcesses(cmds, {poEchoCmd, poUseShell, poParentStreams},
gNumberOfProcessors) gNumberOfProcessors, prettyCmds)
else: else:
res = execProcesses(cmds, {poUseShell, poParentStreams}, res = execProcesses(cmds, {poUseShell, poParentStreams},
gNumberOfProcessors) gNumberOfProcessors, prettyCmds)
if res != 0: if res != 0:
if gNumberOfProcessors <= 1: if gNumberOfProcessors <= 1:
rawMessage(errExecutionOfProgramFailed, []) rawMessage(errExecutionOfProgramFailed, [])
@ -622,7 +631,6 @@ proc callCCompiler*(projectfile: string) =
if optGenStaticLib in gGlobalOptions: if optGenStaticLib in gGlobalOptions:
linkCmd = CC[c].buildLib % ["libfile", (libNameTmpl() % gProjectName), linkCmd = CC[c].buildLib % ["libfile", (libNameTmpl() % gProjectName),
"objfiles", objfiles] "objfiles", objfiles]
if optCompileOnly notin gGlobalOptions: execExternalProgram(linkCmd)
else: else:
var linkerExe = getConfigVar(c, ".linkerexe") var linkerExe = getConfigVar(c, ".linkerexe")
if len(linkerExe) == 0: linkerExe = c.getLinkerExe if len(linkerExe) == 0: linkerExe = c.getLinkerExe
@ -654,7 +662,11 @@ proc callCCompiler*(projectfile: string) =
"objfiles", objfiles, "exefile", exefile, "objfiles", objfiles, "exefile", exefile,
"nimrod", quoteShell(getPrefixDir()), "nimrod", quoteShell(getPrefixDir()),
"lib", quoteShell(libpath)]) "lib", quoteShell(libpath)])
if optCompileOnly notin gGlobalOptions: execExternalProgram(linkCmd) if optCompileOnly notin gGlobalOptions:
if gVerbosity == 1:
execExternalProgram(linkCmd, "[Linking]")
else:
execExternalProgram(linkCmd)
else: else:
linkCmd = "" linkCmd = ""
if optGenScript in gGlobalOptions: if optGenScript in gGlobalOptions:

View file

@ -235,22 +235,32 @@ 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()): int {.rtl, extern: "nosp$1", n = countProcessors(),
prettyCmds: openArray[string] = @[]): int
{.rtl, extern: "nosp$1",
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. ## is returned. If `prettyCmds` are provided, prints them on the console
## 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:
var options = options - {poParentStreams} 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:
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):
@ -264,6 +274,8 @@ proc execProcesses*(cmds: openArray[string],
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])
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
@ -275,6 +287,8 @@ proc execProcesses*(cmds: openArray[string],
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])
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:
@ -283,6 +297,8 @@ proc execProcesses*(cmds: openArray[string],
else: else:
for i in 0..high(cmds): for i in 0..high(cmds):
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)