From 679aefd89c6b0ba74270c5651f26d362935d31da Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Sun, 12 Oct 2014 23:30:32 +0200 Subject: [PATCH 1/5] Prettify compiler output for verbosity=1 Long lines displaying the invocation of the c compiler are replaced with short, readable lines. --- compiler/extccomp.nim | 36 ++++++++++++++++++++++++------------ lib/pure/osproc.nim | 22 +++++++++++++++++++--- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 7d9744bc58..b5519216e3 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -412,8 +412,12 @@ proc addFileToLink*(filename: string) = prependStr(toLink, filename) # BUGFIX: was ``appendStr`` -proc execExternalProgram*(cmd: string) = - if optListCmd in gGlobalOptions or gVerbosity > 0: msgWriteln(cmd) +proc execExternalProgram*(cmd: string, prettyCmd = "") = + if optListCmd in gGlobalOptions or gVerbosity > 0: + if prettyCmd != "": + msgWriteln(prettyCmd) + else: + msgWriteln(cmd) if execCmd(cmd) != 0: rawMessage(errExecutionOfProgramFailed, "") proc generateScript(projectFile: string, script: PRope) = @@ -566,14 +570,16 @@ proc addExternalFileToCompile*(filename: string) = if optForceFullMake in gGlobalOptions or externalFileChanged(filename): appendStr(externalToCompile, filename) -proc compileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq, - isExternal: bool) = +proc compileCFile(list: TLinkedList, script: var PRope, cmds: var TStringSeq, + prettyCmds: var TStringSeq, isExternal: bool) = var it = PStrEntry(list.head) while it != nil: inc(fileCounter) # call the C compiler for the .c file: var compileCmd = getCompileCFileCmd(it.data, isExternal) if optCompileOnly notin gGlobalOptions: add(cmds, compileCmd) + let (dir, name, ext) = splitFile(it.data) + add(prettyCmds, "CC: " & name) if optGenScript in gGlobalOptions: app(script, compileCmd) app(script, tnl) @@ -589,19 +595,22 @@ proc callCCompiler*(projectfile: string) = var c = cCompiler var script: PRope = nil var cmds: TStringSeq = @[] - compileCFile(toCompile, script, cmds, false) - compileCFile(externalToCompile, script, cmds, true) + var prettyCmds: TStringSeq = @[] + compileCFile(toCompile, script, cmds, prettyCmds, false) + compileCFile(externalToCompile, script, cmds, prettyCmds, true) + if gVerbosity != 1: + prettyCmds = @[] if optCompileOnly notin gGlobalOptions: if gNumberOfProcessors == 0: gNumberOfProcessors = countProcessors() var res = 0 if gNumberOfProcessors <= 1: for i in countup(0, high(cmds)): res = max(execCmd(cmds[i]), res) elif optListCmd in gGlobalOptions or gVerbosity > 0: - res = execProcesses(cmds, {poEchoCmd, poUseShell, poParentStreams}, - gNumberOfProcessors) + res = execProcesses(cmds, {poEchoCmd, poUseShell, poParentStreams}, + gNumberOfProcessors, prettyCmds) else: - res = execProcesses(cmds, {poUseShell, poParentStreams}, - gNumberOfProcessors) + res = execProcesses(cmds, {poUseShell, poParentStreams}, + gNumberOfProcessors, prettyCmds) if res != 0: if gNumberOfProcessors <= 1: rawMessage(errExecutionOfProgramFailed, []) @@ -622,7 +631,6 @@ proc callCCompiler*(projectfile: string) = if optGenStaticLib in gGlobalOptions: linkCmd = CC[c].buildLib % ["libfile", (libNameTmpl() % gProjectName), "objfiles", objfiles] - if optCompileOnly notin gGlobalOptions: execExternalProgram(linkCmd) else: var linkerExe = getConfigVar(c, ".linkerexe") if len(linkerExe) == 0: linkerExe = c.getLinkerExe @@ -654,7 +662,11 @@ proc callCCompiler*(projectfile: string) = "objfiles", objfiles, "exefile", exefile, "nimrod", quoteShell(getPrefixDir()), "lib", quoteShell(libpath)]) - if optCompileOnly notin gGlobalOptions: execExternalProgram(linkCmd) + if optCompileOnly notin gGlobalOptions: + if gVerbosity == 1: + execExternalProgram(linkCmd, "[Linking]") + else: + execExternalProgram(linkCmd) else: linkCmd = "" if optGenScript in gGlobalOptions: diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index f47df73ca0..56b758ad83 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -235,22 +235,32 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, - n = countProcessors()): int {.rtl, extern: "nosp$1", + n = countProcessors(), + prettyCmds: openArray[string] = @[]): 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. + ## 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): # poParentStreams causes problems on Posix, so we simply disable it: - var options = options - {poParentStreams} + options = options - {poParentStreams} assert n > 0 + var usePrettyPrintouts = false + if prettyCmds.len == cmds.len: + options = options - {poEchoCmd} + usePrettyPrintouts = true if n > 1: var q: seq[Process] newSeq(q, n) var m = min(n, cmds.len) for i in 0..m-1: q[i] = startCmd(cmds[i], options=options) + if usePrettyPrintouts: + echo prettyCmds[i] when defined(noBusyWaiting): var r = 0 for i in m..high(cmds): @@ -264,6 +274,8 @@ proc execProcesses*(cmds: openArray[string], result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) q[r] = startCmd(cmds[i], options=options) + if usePrettyPrintouts: + echo prettyCmds[i] r = (r + 1) mod n else: var i = m @@ -275,6 +287,8 @@ proc execProcesses*(cmds: openArray[string], result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) q[r] = startCmd(cmds[i], options=options) + if usePrettyPrintouts: + echo prettyCmds[i] inc(i) if i > high(cmds): break for j in 0..m-1: @@ -283,6 +297,8 @@ proc execProcesses*(cmds: openArray[string], else: for i in 0..high(cmds): var p = startCmd(cmds[i], options=options) + if usePrettyPrintouts: + echo prettyCmds[i] result = max(waitForExit(p), result) close(p) From 06c32aab29b0e33653aa9c144bfe4994e706a84e Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Mon, 13 Oct 2014 01:54:44 +0200 Subject: [PATCH 2/5] Tidy up the prettification of the default verbosity c compilation output --- compiler/extccomp.nim | 15 +++++++++------ lib/pure/osproc.nim | 38 +++++++++++++++++++------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index b5519216e3..f19b3e7ce0 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -596,21 +596,24 @@ proc callCCompiler*(projectfile: string) = var script: PRope = nil var cmds: TStringSeq = @[] var prettyCmds: TStringSeq = @[] + let prettyCb = proc (idx: int) = + echo prettyCmds[idx] compileCFile(toCompile, script, cmds, prettyCmds, false) compileCFile(externalToCompile, script, cmds, prettyCmds, true) - if gVerbosity != 1: - prettyCmds = @[] if optCompileOnly notin gGlobalOptions: if gNumberOfProcessors == 0: gNumberOfProcessors = countProcessors() var res = 0 if gNumberOfProcessors <= 1: 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}, - gNumberOfProcessors, prettyCmds) - else: + gNumberOfProcessors) + elif gVerbosity == 1: res = execProcesses(cmds, {poUseShell, poParentStreams}, - gNumberOfProcessors, prettyCmds) + gNumberOfProcessors, prettyCb) + else: + res = execProcesses(cmds, {poUseShell, poParentStreams}, + gNumberOfProcessors) if res != 0: if gNumberOfProcessors <= 1: rawMessage(errExecutionOfProgramFailed, []) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 56b758ad83..35183c37c8 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -236,31 +236,23 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, n = countProcessors(), - prettyCmds: openArray[string] = @[]): int - {.rtl, extern: "nosp$1", - tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} = + beforeRunEvent: proc(idx: int){.closure.}): int + {.rtl, 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. If `prettyCmds` are provided, prints them on the console - ## instead of the real commands (for prettier output). - var options = options + ## is returned. Runs `beforeRunEvent` before running each command. when defined(posix): # poParentStreams causes problems on Posix, so we simply disable it: - options = options - {poParentStreams} + var options = options - {poParentStreams} assert n > 0 - var usePrettyPrintouts = false - if prettyCmds.len == cmds.len: - options = options - {poEchoCmd} - usePrettyPrintouts = true if n > 1: var q: seq[Process] newSeq(q, n) var m = min(n, cmds.len) for i in 0..m-1: + beforeRunEvent(i) q[i] = startCmd(cmds[i], options=options) - if usePrettyPrintouts: - echo prettyCmds[i] when defined(noBusyWaiting): var r = 0 for i in m..high(cmds): @@ -273,9 +265,8 @@ proc execProcesses*(cmds: openArray[string], echo(err) result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) + beforeRunEvent(i) q[r] = startCmd(cmds[i], options=options) - if usePrettyPrintouts: - echo prettyCmds[i] r = (r + 1) mod n else: var i = m @@ -286,9 +277,8 @@ proc execProcesses*(cmds: openArray[string], #echo(outputStream(q[r]).readLine()) result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) + beforeRunEvent(i) q[r] = startCmd(cmds[i], options=options) - if usePrettyPrintouts: - echo prettyCmds[i] inc(i) if i > high(cmds): break for j in 0..m-1: @@ -296,12 +286,22 @@ proc execProcesses*(cmds: openArray[string], if q[j] != nil: close(q[j]) else: for i in 0..high(cmds): + beforeRunEvent(i) var p = startCmd(cmds[i], options=options) - if usePrettyPrintouts: - echo prettyCmds[i] result = max(waitForExit(p), result) 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 ## `select` with a sensible Nim interface. `timeout` is in miliseconds. ## Specify -1 for no timeout. Returns the number of processes that are From 2f3add99bb1928b7dbc483c711ae17028f913804 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Sun, 2 Nov 2014 15:55:33 +0100 Subject: [PATCH 3/5] Change empty callback into nil --- lib/pure/osproc.nim | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 35183c37c8..d51a2b2243 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -236,8 +236,8 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, n = countProcessors(), - beforeRunEvent: proc(idx: int){.closure.}): int - {.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect]} = + beforeRunEvent: proc(idx: int)): int + {.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = ## executes the commands `cmds` in parallel. Creates `n` processes ## that execute in parallel. The highest return value of all processes ## is returned. Runs `beforeRunEvent` before running each command. @@ -251,7 +251,8 @@ proc execProcesses*(cmds: openArray[string], newSeq(q, n) var m = min(n, cmds.len) for i in 0..m-1: - beforeRunEvent(i) + if beforeRunEvent != nil: + beforeRunEvent(i) q[i] = startCmd(cmds[i], options=options) when defined(noBusyWaiting): var r = 0 @@ -265,7 +266,8 @@ proc execProcesses*(cmds: openArray[string], echo(err) result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) - beforeRunEvent(i) + if beforeRunEvent != nil: + beforeRunEvent(i) q[r] = startCmd(cmds[i], options=options) r = (r + 1) mod n else: @@ -277,7 +279,8 @@ proc execProcesses*(cmds: openArray[string], #echo(outputStream(q[r]).readLine()) result = max(waitForExit(q[r]), result) if q[r] != nil: close(q[r]) - beforeRunEvent(i) + if beforeRunEvent != nil: + beforeRunEvent(i) q[r] = startCmd(cmds[i], options=options) inc(i) if i > high(cmds): break @@ -286,21 +289,21 @@ proc execProcesses*(cmds: openArray[string], if q[j] != nil: close(q[j]) else: for i in 0..high(cmds): - beforeRunEvent(i) + if beforeRunEvent != nil: + beforeRunEvent(i) var p = startCmd(cmds[i], options=options) result = max(waitForExit(p), result) 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]} = + tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = ## 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) + return execProcesses(cmds, options, n, nil) proc select*(readfds: var seq[Process], timeout = 500): int ## `select` with a sensible Nim interface. `timeout` is in miliseconds. From 49e93326615e0201ab2ba031e9aa3a1392818aa9 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Sun, 2 Nov 2014 16:06:01 +0100 Subject: [PATCH 4/5] Use defaut nil callback for execProcesses --- lib/pure/osproc.nim | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index d51a2b2243..71ca51764c 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -236,7 +236,7 @@ proc countProcessors*(): int {.rtl, extern: "nosp$1".} = proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, n = countProcessors(), - beforeRunEvent: proc(idx: int)): int + beforeRunEvent: proc(idx: int) = nil): int {.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = ## executes the commands `cmds` in parallel. Creates `n` processes ## that execute in parallel. The highest return value of all processes @@ -295,16 +295,6 @@ proc execProcesses*(cmds: openArray[string], result = max(waitForExit(p), result) close(p) -proc execProcesses*(cmds: openArray[string], - options = {poStdErrToStdOut, poParentStreams}, - n = countProcessors()): int - {.rtl, extern: "nosp$1", - tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = - ## 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, nil) - proc select*(readfds: var seq[Process], timeout = 500): int ## `select` with a sensible Nim interface. `timeout` is in miliseconds. ## Specify -1 for no timeout. Returns the number of processes that are From c3a4cc87ca8aac8138da2aa083ac3a68dda98b14 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Sun, 2 Nov 2014 16:11:17 +0100 Subject: [PATCH 5/5] Forgot to keep extern pragma for execProcesses --- lib/pure/osproc.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 71ca51764c..59eecf88db 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -237,7 +237,8 @@ proc execProcesses*(cmds: openArray[string], options = {poStdErrToStdOut, poParentStreams}, n = countProcessors(), beforeRunEvent: proc(idx: int) = nil): int - {.rtl, tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = + {.rtl, extern: "nosp$1", + tags: [ExecIOEffect, TimeEffect, ReadEnvEffect, RootEffect]} = ## executes the commands `cmds` in parallel. Creates `n` processes ## that execute in parallel. The highest return value of all processes ## is returned. Runs `beforeRunEvent` before running each command.