Make listCmd honor hint:cc:off (#13606)

* Make listCmd honor hint:cc:off

* Tiny cleanup

* Tiny tiny cleanup

* VERY IMPORTANT: --hint:cc:on will overwrite --verbosity:0 :p

* Tiny cleanup

* Stupid

* Move displayProgressCC to where its required

* Tiny cleanup
This commit is contained in:
Clyybber 2020-03-11 23:04:33 +01:00 • committed by GitHub
commit 6b3098c378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -623,7 +623,7 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
var objfile = var objfile =
if cfile.obj.isEmpty: if cfile.obj.isEmpty:
if not cfile.flags.contains(CfileFlag.External) or noAbsolutePaths(conf): if CfileFlag.External notin cfile.flags or noAbsolutePaths(conf):
toObjFile(conf, cf).string toObjFile(conf, cf).string
else: else:
completeCfilePath(conf, toObjFile(conf, cf)).string completeCfilePath(conf, toObjFile(conf, cf)).string
@ -705,26 +705,6 @@ proc addExternalFileToCompile*(conf: ConfigRef; filename: AbsoluteFile) =
flags: {CfileFlag.External}) flags: {CfileFlag.External})
addExternalFileToCompile(conf, c) addExternalFileToCompile(conf, c)
proc displayProgressCC(conf: ConfigRef, path: string): string =
if conf.hasHint(hintCC):
let (_, name, _) = splitFile(path)
result = MsgKindToStr[hintCC] % demanglePackageName(name)
proc compileCFiles(conf: ConfigRef; list: CfileList, script: var Rope, cmds: var TStringSeq,
prettyCmds: var TStringSeq) =
var currIdx = 0
for it in list:
# call the C compiler for the .c file:
if it.flags.contains(CfileFlag.Cached): continue
var compileCmd = getCompileCFileCmd(conf, it, currIdx == list.len - 1, produceOutput=true)
inc currIdx
if optCompileOnly notin conf.globalOptions:
cmds.add(compileCmd)
prettyCmds.add displayProgressCC(conf, $it.cname)
if optGenScript in conf.globalOptions:
script.add(compileCmd)
script.add("\n")
proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile, proc getLinkCmd(conf: ConfigRef; output: AbsoluteFile,
objfiles: string, isDllBuild: bool): string = objfiles: string, isDllBuild: bool): string =
if optGenStaticLib in conf.globalOptions: if optGenStaticLib in conf.globalOptions:
@ -862,15 +842,8 @@ proc execCmdsInParallel(conf: ConfigRef; cmds: seq[string]; prettyCb: proc (idx:
cmds[i]) cmds[i])
else: else:
tryExceptOSErrorMessage(conf, "invocation of external compiler program failed."): tryExceptOSErrorMessage(conf, "invocation of external compiler program failed."):
if optListCmd in conf.globalOptions or conf.verbosity > 1: res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
res = execProcesses(cmds, {poEchoCmd, poStdErrToStdOut, poUsePath, poParentStreams},
conf.numberOfProcessors, afterRunEvent=runCb)
elif conf.verbosity == 1:
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
conf.numberOfProcessors, prettyCb, afterRunEvent=runCb) conf.numberOfProcessors, prettyCb, afterRunEvent=runCb)
else:
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
conf.numberOfProcessors, afterRunEvent=runCb)
if res != 0: if res != 0:
if conf.numberOfProcessors <= 1: if conf.numberOfProcessors <= 1:
rawMessage(conf, errGenerated, "execution of an external program failed: '$1'" % rawMessage(conf, errGenerated, "execution of an external program failed: '$1'" %
@ -912,10 +885,12 @@ proc hcrLinkTargetName(conf: ConfigRef, objFile: string, isMain = false): Absolu
else: platform.OS[conf.target.targetOS].dllFrmt % basename else: platform.OS[conf.target.targetOS].dllFrmt % basename
result = conf.getNimcacheDir / RelativeFile(targetName) result = conf.getNimcacheDir / RelativeFile(targetName)
template callbackPrettyCmd(cmd) = proc displayProgressCC(conf: ConfigRef, path, compileCmd: string): string =
when declared(echo): if conf.hasHint(hintCC):
let cmd2 = cmd if optListCmd in conf.globalOptions or conf.verbosity > 1:
if cmd2.len > 0: echo cmd2 result = MsgKindToStr[hintCC] % (demanglePackageName(path.splitFile.name) & ": " & compileCmd)
else:
result = MsgKindToStr[hintCC] % demanglePackageName(path.splitFile.name)
proc callCCompiler*(conf: ConfigRef) = proc callCCompiler*(conf: ConfigRef) =
var var
@ -925,10 +900,22 @@ proc callCCompiler*(conf: ConfigRef) =
# generated # generated
#var c = cCompiler #var c = cCompiler
var script: Rope = nil var script: Rope = nil
var cmds: TStringSeq = @[] var cmds: TStringSeq
var prettyCmds: TStringSeq = @[] var prettyCmds: TStringSeq
let prettyCb = proc (idx: int) = callbackPrettyCmd(prettyCmds[idx]) let prettyCb = proc (idx: int) =
compileCFiles(conf, conf.toCompile, script, cmds, prettyCmds) if prettyCmds[idx].len > 0: echo prettyCmds[idx]
for idx, it in conf.toCompile:
# call the C compiler for the .c file:
if CfileFlag.Cached in it.flags: continue
let compileCmd = getCompileCFileCmd(conf, it, idx == conf.toCompile.len - 1, produceOutput=true)
if optCompileOnly notin conf.globalOptions:
cmds.add(compileCmd)
prettyCmds.add displayProgressCC(conf, $it.cname, compileCmd)
if optGenScript in conf.globalOptions:
script.add(compileCmd)
script.add("\n")
if optCompileOnly notin conf.globalOptions: if optCompileOnly notin conf.globalOptions:
execCmdsInParallel(conf, cmds, prettyCb) execCmdsInParallel(conf, cmds, prettyCb)
if optNoLinking notin conf.globalOptions: if optNoLinking notin conf.globalOptions:
@ -947,7 +934,7 @@ proc callCCompiler*(conf: ConfigRef) =
# don't relink each of the many binaries (one for each source file) if the nim code is # don't relink each of the many binaries (one for each source file) if the nim code is
# cached because that would take too much time for small changes - the only downside to # cached because that would take too much time for small changes - the only downside to
# this is that if an external-to-link file changes the final target wouldn't be relinked # this is that if an external-to-link file changes the final target wouldn't be relinked
if x.flags.contains(CfileFlag.Cached): continue if CfileFlag.Cached in x.flags: continue
# we pass each object file as if it is the project file - a .dll will be created for each such # we pass each object file as if it is the project file - a .dll will be created for each such
# object file in the nimcache directory, and only in the case of the main project file will # object file in the nimcache directory, and only in the case of the main project file will
# there be probably an executable (if the project is such) which will be copied out of the nimcache # there be probably an executable (if the project is such) which will be copied out of the nimcache
@ -965,7 +952,7 @@ proc callCCompiler*(conf: ConfigRef) =
prettyCmds = map(prettyCmds, proc (curr: string): string = return curr.replace("CC", "Link")) prettyCmds = map(prettyCmds, proc (curr: string): string = return curr.replace("CC", "Link"))
execCmdsInParallel(conf, cmds, prettyCb) execCmdsInParallel(conf, cmds, prettyCb)
# only if not cached - copy the resulting main file from the nimcache folder to its originally intended destination # only if not cached - copy the resulting main file from the nimcache folder to its originally intended destination
if not conf.toCompile[mainFileIdx].flags.contains(CfileFlag.Cached): if CfileFlag.Cached notin conf.toCompile[mainFileIdx].flags:
let mainObjFile = getObjFilePath(conf, conf.toCompile[mainFileIdx]) let mainObjFile = getObjFilePath(conf, conf.toCompile[mainFileIdx])
var src = conf.hcrLinkTargetName(mainObjFile, true) var src = conf.hcrLinkTargetName(mainObjFile, true)
var dst = conf.prepareToWriteOutput var dst = conf.prepareToWriteOutput
@ -1011,8 +998,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
f.write escapeJson(x) f.write escapeJson(x)
proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) = proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) =
var i = 0 for i, it in clist:
for it in clist:
if CfileFlag.Cached in it.flags: continue if CfileFlag.Cached in it.flags: continue
let compileCmd = getCompileCFileCmd(conf, it) let compileCmd = getCompileCFileCmd(conf, it)
if i > 0: lit ",\L" if i > 0: lit ",\L"
@ -1021,7 +1007,6 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
lit ", " lit ", "
str compileCmd str compileCmd
lit "]" lit "]"
inc i
proc linkfiles(conf: ConfigRef; f: File; buf, objfiles: var string; clist: CfileList; proc linkfiles(conf: ConfigRef; f: File; buf, objfiles: var string; clist: CfileList;
llist: seq[string]) = llist: seq[string]) =
@ -1125,16 +1110,18 @@ proc runJsonBuildInstructions*(conf: ConfigRef; projectfile: AbsoluteFile) =
let data = json.parseFile(jsonFile.string) let data = json.parseFile(jsonFile.string)
let toCompile = data["compile"] let toCompile = data["compile"]
doAssert toCompile.kind == JArray doAssert toCompile.kind == JArray
var cmds: TStringSeq = @[] var cmds: TStringSeq
var prettyCmds: TStringSeq = @[] var prettyCmds: TStringSeq
let prettyCb = proc (idx: int) =
if prettyCmds[idx].len > 0: echo prettyCmds[idx]
for c in toCompile: for c in toCompile:
doAssert c.kind == JArray doAssert c.kind == JArray
doAssert c.len >= 2 doAssert c.len >= 2
cmds.add(c[1].getStr) cmds.add(c[1].getStr)
prettyCmds.add displayProgressCC(conf, c[0].getStr) prettyCmds.add displayProgressCC(conf, c[0].getStr, c[1].getStr)
let prettyCb = proc (idx: int) = callbackPrettyCmd(prettyCmds[idx])
execCmdsInParallel(conf, cmds, prettyCb) execCmdsInParallel(conf, cmds, prettyCb)
let linkCmd = data["linkcmd"] let linkCmd = data["linkcmd"]
@ -1150,10 +1137,8 @@ proc runJsonBuildInstructions*(conf: ConfigRef; projectfile: AbsoluteFile) =
except: except:
let e = getCurrentException() let e = getCurrentException()
var msg = "\ncaught exception:n" & e.msg & "\nstacktrace:\n" & quit "\ncaught exception:n" & e.msg & "\nstacktrace:\n" & e.getStackTrace() &
getCurrentException().getStackTrace() & "error evaluating JSON file: " & jsonFile.string
"error evaluating JSON file: " & jsonFile.string
quit msg
proc genMappingFiles(conf: ConfigRef; list: CfileList): Rope = proc genMappingFiles(conf: ConfigRef; list: CfileList): Rope =
for it in list: for it in list: