From 679aefd89c6b0ba74270c5651f26d362935d31da Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Sun, 12 Oct 2014 23:30:32 +0200 Subject: [PATCH 01/10] 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 02/10] 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 3939e674d028b63492aaadd9b892c82095acfaf0 Mon Sep 17 00:00:00 2001 From: Clay Sweetser Date: Wed, 29 Oct 2014 14:29:09 -0400 Subject: [PATCH 03/10] Fix #1599 Compiler-specific options are now read with the '{compiler}.cpp' prefix in C++ mode. GCC C++ mode is fixed. --- compiler/extccomp.nim | 38 ++++++++++++++++++++++++++++---------- config/nim.cfg | 14 +++++++------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 7d9744bc58..1e585fbccf 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -7,8 +7,10 @@ # distribution, for details about the copyright. # -# module for calling the different external C compilers -# some things are read in from the configuration file +# Module providing functions for calling the different external C compilers +# Uses some hard-wired facts about each C/C++ compiler, plus options read +# from a configuration file, to provide generalized procedures to compile +# nim files. import lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, crc @@ -59,6 +61,7 @@ type template compiler(name: expr, settings: stmt): stmt {.immediate.} = proc name: TInfoCC {.compileTime.} = settings +# GNU C and C++ Compiler compiler gcc: result = ( name: "gcc", @@ -84,21 +87,24 @@ compiler gcc: props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm, hasNakedAttribute}) +# LLVM Frontend for GCC/G++ compiler llvmGcc: - result = gcc() - + result = gcc() # Uses settings from GCC + result.name = "llvm_gcc" result.compilerExe = "llvm-gcc" result.cppCompiler = "llvm-g++" result.buildLib = "llvm-ar rcs $libfile $objfiles" +# Clang (LLVM) C/C++ Compiler compiler clang: - result = llvmGcc() + result = llvmGcc() # Uses settings from llvmGcc result.name = "clang" result.compilerExe = "clang" result.cppCompiler = "clang++" +# Microsoft Visual C/C++ Compiler compiler vcc: result = ( name: "vcc", @@ -123,6 +129,7 @@ compiler vcc: packedPragma: "#pragma pack(1)", props: {hasCpp, hasAssume, hasNakedDeclspec}) +# Intel C/C++ Compiler compiler icl: # Intel compilers try to imitate the native ones (gcc and msvc) when defined(windows): @@ -134,6 +141,7 @@ compiler icl: result.compilerExe = "icl" result.linkerExe = "icl" +# Local C Compiler compiler lcc: result = ( name: "lcc", @@ -158,6 +166,7 @@ compiler lcc: packedPragma: "", # XXX: not supported yet props: {}) +# Borland C Compiler compiler bcc: result = ( name: "bcc", @@ -182,6 +191,7 @@ compiler bcc: packedPragma: "", # XXX: not supported yet props: {hasCpp}) +# Digital Mars C Compiler compiler dmc: result = ( name: "dmc", @@ -206,6 +216,7 @@ compiler dmc: packedPragma: "#pragma pack(1)", props: {hasCpp}) +# Watcom C Compiler compiler wcc: result = ( name: "wcc", @@ -230,6 +241,7 @@ compiler wcc: packedPragma: "", # XXX: not supported yet props: {hasCpp}) +# Tiny C Compiler compiler tcc: result = ( name: "tcc", @@ -254,6 +266,7 @@ compiler tcc: packedPragma: "", # XXX: not supported yet props: {hasSwitchRange, hasComputedGoto}) +# Pelles C Compiler compiler pcc: # Pelles C result = ( @@ -279,6 +292,7 @@ compiler pcc: packedPragma: "", # XXX: not supported yet props: {}) +# Your C Compiler compiler ucc: result = ( name: "ucc", @@ -339,7 +353,9 @@ var compileOptions: string = "" ccompilerpath: string = "" -proc nameToCC*(name: string): TSystemCC = +proc nameToCC*(name: string): TSystemCC = + ## Returns the kind of compiler referred to by `name`, or ccNone + ## if the name doesn't refer to any known compiler. for i in countup(succ(ccNone), high(TSystemCC)): if cmpIgnoreStyle(name, CC[i].name) == 0: return i @@ -348,17 +364,18 @@ proc nameToCC*(name: string): TSystemCC = proc getConfigVar(c: TSystemCC, suffix: string): string = # use ``cpu.os.cc`` for cross compilation, unless ``--compileOnly`` is given # for niminst support + let fullSuffix = (if gCmd == cmdCompileToCpp: ".cpp" & suffix else: suffix) if (platform.hostOS != targetOS or platform.hostCPU != targetCPU) and optCompileOnly notin gGlobalOptions: let fullCCname = platform.CPU[targetCPU].name & '.' & platform.OS[targetOS].name & '.' & - CC[c].name & suffix + CC[c].name & fullSuffix result = getConfigVar(fullCCname) if result.len == 0: # not overriden for this cross compilation setting? - result = getConfigVar(CC[c].name & suffix) + result = getConfigVar(CC[c].name & fullSuffix) else: - result = getConfigVar(CC[c].name & suffix) + result = getConfigVar(CC[c].name & fullSuffix) proc setCC*(ccname: string) = cCompiler = nameToCC(ccname) @@ -482,7 +499,7 @@ proc getLinkOptions: string = proc needsExeExt(): bool {.inline.} = result = (optGenScript in gGlobalOptions and targetOS == osWindows) or - (platform.hostOS == osWindows) + (platform.hostOS == osWindows) proc getCompilerExe(compiler: TSystemCC): string = result = if gCmd == cmdCompileToCpp: CC[compiler].cppCompiler @@ -539,6 +556,7 @@ proc getCompileCFileCmd*(cfilename: string, isExternal = false): string = "lib", quoteShell(libpath)]) proc footprint(filename: string): TCrc32 = + # note, '><' further modifies a crc value with a string. result = crcFromFile(filename) >< platform.OS[targetOS].name >< platform.CPU[targetCPU].name >< diff --git a/config/nim.cfg b/config/nim.cfg index 6ec32cb7bc..62fe3307eb 100644 --- a/config/nim.cfg +++ b/config/nim.cfg @@ -71,7 +71,7 @@ hint[LineTooLong]=off @if not bsd: # -fopenmp gcc.options.linker = "-ldl" - gpp.options.linker = "-ldl" + gcc.cpp.options.linker = "-ldl" clang.options.linker = "-ldl" tcc.options.linker = "-ldl" @end @@ -101,19 +101,19 @@ hint[LineTooLong]=off cc = clang tlsEmulation:on gcc.options.always = "-w -fasm-blocks" - gpp.options.always = "-w -fasm-blocks -fpermissive" + gcc.cpp.options.always = "-w -fasm-blocks -fpermissive" @else: - gcc.options.always = "-w" - gpp.options.always = "-w -fpermissive" + gcc.options.always = "-w" + gcc.cpp.options.always = "-w -fpermissive" @end gcc.options.speed = "-O3 -fno-strict-aliasing" gcc.options.size = "-Os" gcc.options.debug = "-g3 -O0" -gpp.options.speed = "-O3 -fno-strict-aliasing" -gpp.options.size = "-Os" -gpp.options.debug = "-g3 -O0" +gcc.cpp.options.speed = "-O3 -fno-strict-aliasing" +gcc.cpp.options.size = "-Os" +gcc.cpp.options.debug = "-g3 -O0" #passl = "-pg" # Configuration for the LLVM GCC compiler: From a77dc8e46c48ee6d999e3dc249d3d8f42dc1d286 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Sat, 1 Nov 2014 17:12:45 -0400 Subject: [PATCH 04/10] Remove extra trailing zero --- lib/pure/oids.nim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index 7c58a2ddab..06e049d46f 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -52,10 +52,9 @@ proc oidToString*(oid: Oid, str: cstring) = str[2 * i] = hex[(b and 0xF0) shr 4] str[2 * i + 1] = hex[b and 0xF] inc(i) - str[24] = '\0' proc `$`*(oid: Oid): string = - result = newString(25) + result = newString(24) oidToString(oid, result) var From cbe733afa25c262cc77781d87cda11efbcbb9fa8 Mon Sep 17 00:00:00 2001 From: Varriount Date: Sat, 1 Nov 2014 17:52:00 -0400 Subject: [PATCH 05/10] Revert "Remove extra trailing zero" --- lib/pure/oids.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index 06e049d46f..7c58a2ddab 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -52,9 +52,10 @@ proc oidToString*(oid: Oid, str: cstring) = str[2 * i] = hex[(b and 0xF0) shr 4] str[2 * i + 1] = hex[b and 0xF] inc(i) + str[24] = '\0' proc `$`*(oid: Oid): string = - result = newString(24) + result = newString(25) oidToString(oid, result) var From 2f3add99bb1928b7dbc483c711ae17028f913804 Mon Sep 17 00:00:00 2001 From: Erwan Ameil Date: Sun, 2 Nov 2014 15:55:33 +0100 Subject: [PATCH 06/10] 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 07/10] 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 08/10] 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. From 771e3db869f14fe49a6b41f02623867fe931d5d8 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Sun, 2 Nov 2014 17:05:23 -0500 Subject: [PATCH 09/10] Remove extra trailing zero from oid `$` would return a string of length 25, including the trailing null String length changed to 24, avoiding an extra null byte in the output --- lib/pure/oids.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index 7c58a2ddab..0dc8e3c15f 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -55,7 +55,7 @@ proc oidToString*(oid: Oid, str: cstring) = str[24] = '\0' proc `$`*(oid: Oid): string = - result = newString(25) + result = newString(24) oidToString(oid, result) var From 1b4dd6f61e311e774b218173b9b4f47c9a78ac8d Mon Sep 17 00:00:00 2001 From: Varriount Date: Mon, 3 Nov 2014 01:51:54 -0500 Subject: [PATCH 10/10] Update buildbat.tmpl Batch scripts generated by `koch csources` now return proper error codes, and stop when there is an error. --- tools/niminst/buildbat.tmpl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/niminst/buildbat.tmpl b/tools/niminst/buildbat.tmpl index 9a19fc70b8..415574273b 100644 --- a/tools/niminst/buildbat.tmpl +++ b/tools/niminst/buildbat.tmpl @@ -20,6 +20,7 @@ REM call the compiler: ECHO %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} %CC% %COMP_FLAGS% -Ic_code -c ?{f} -o ?{changeFileExt(f, "o")} # linkCmd.add(" " & changeFileExt(f, "o")) +IF ERRORLEVEL 1 (GOTO:END) # end for ECHO %LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS% @@ -27,4 +28,14 @@ ECHO %LINKER% -o ?{"%BIN_DIR%"\toLower(c.name)}.exe ?linkCmd %LINK_FLAGS% # end block -ECHO SUCCESS +:END +IF ERRORLEVEL 1 ( + ECHO FAILURE + ECHO. + ECHO CSource compilation failed. Please check that the gcc compiler is in + ECHO the PATH environment variable, and that you are calling the batch script + ECHO that matches the target architecture of the compiler. +) ELSE ( + ECHO SUCCESS +) +exit /b %ERRORLEVEL%