mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-09 21:28:13 +00:00
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:
@@ -623,7 +623,7 @@ proc getCompileCFileCmd*(conf: ConfigRef; cfile: Cfile,
|
||||
|
||||
var objfile =
|
||||
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
|
||||
else:
|
||||
completeCfilePath(conf, toObjFile(conf, cf)).string
|
||||
@@ -705,26 +705,6 @@ proc addExternalFileToCompile*(conf: ConfigRef; filename: AbsoluteFile) =
|
||||
flags: {CfileFlag.External})
|
||||
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,
|
||||
objfiles: string, isDllBuild: bool): string =
|
||||
if optGenStaticLib in conf.globalOptions:
|
||||
@@ -862,15 +842,8 @@ proc execCmdsInParallel(conf: ConfigRef; cmds: seq[string]; prettyCb: proc (idx:
|
||||
cmds[i])
|
||||
else:
|
||||
tryExceptOSErrorMessage(conf, "invocation of external compiler program failed."):
|
||||
if optListCmd in conf.globalOptions or conf.verbosity > 1:
|
||||
res = execProcesses(cmds, {poEchoCmd, poStdErrToStdOut, poUsePath, poParentStreams},
|
||||
conf.numberOfProcessors, afterRunEvent=runCb)
|
||||
elif conf.verbosity == 1:
|
||||
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
|
||||
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
|
||||
conf.numberOfProcessors, prettyCb, afterRunEvent=runCb)
|
||||
else:
|
||||
res = execProcesses(cmds, {poStdErrToStdOut, poUsePath, poParentStreams},
|
||||
conf.numberOfProcessors, afterRunEvent=runCb)
|
||||
if res != 0:
|
||||
if conf.numberOfProcessors <= 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
|
||||
result = conf.getNimcacheDir / RelativeFile(targetName)
|
||||
|
||||
template callbackPrettyCmd(cmd) =
|
||||
when declared(echo):
|
||||
let cmd2 = cmd
|
||||
if cmd2.len > 0: echo cmd2
|
||||
proc displayProgressCC(conf: ConfigRef, path, compileCmd: string): string =
|
||||
if conf.hasHint(hintCC):
|
||||
if optListCmd in conf.globalOptions or conf.verbosity > 1:
|
||||
result = MsgKindToStr[hintCC] % (demanglePackageName(path.splitFile.name) & ": " & compileCmd)
|
||||
else:
|
||||
result = MsgKindToStr[hintCC] % demanglePackageName(path.splitFile.name)
|
||||
|
||||
proc callCCompiler*(conf: ConfigRef) =
|
||||
var
|
||||
@@ -925,10 +900,22 @@ proc callCCompiler*(conf: ConfigRef) =
|
||||
# generated
|
||||
#var c = cCompiler
|
||||
var script: Rope = nil
|
||||
var cmds: TStringSeq = @[]
|
||||
var prettyCmds: TStringSeq = @[]
|
||||
let prettyCb = proc (idx: int) = callbackPrettyCmd(prettyCmds[idx])
|
||||
compileCFiles(conf, conf.toCompile, script, cmds, prettyCmds)
|
||||
var cmds: TStringSeq
|
||||
var prettyCmds: TStringSeq
|
||||
let prettyCb = proc (idx: int) =
|
||||
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:
|
||||
execCmdsInParallel(conf, cmds, prettyCb)
|
||||
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
|
||||
# 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
|
||||
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
|
||||
# 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
|
||||
@@ -965,7 +952,7 @@ proc callCCompiler*(conf: ConfigRef) =
|
||||
prettyCmds = map(prettyCmds, proc (curr: string): string = return curr.replace("CC", "Link"))
|
||||
execCmdsInParallel(conf, cmds, prettyCb)
|
||||
# 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])
|
||||
var src = conf.hcrLinkTargetName(mainObjFile, true)
|
||||
var dst = conf.prepareToWriteOutput
|
||||
@@ -1011,8 +998,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
|
||||
f.write escapeJson(x)
|
||||
|
||||
proc cfiles(conf: ConfigRef; f: File; buf: var string; clist: CfileList, isExternal: bool) =
|
||||
var i = 0
|
||||
for it in clist:
|
||||
for i, it in clist:
|
||||
if CfileFlag.Cached in it.flags: continue
|
||||
let compileCmd = getCompileCFileCmd(conf, it)
|
||||
if i > 0: lit ",\L"
|
||||
@@ -1021,7 +1007,6 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
|
||||
lit ", "
|
||||
str compileCmd
|
||||
lit "]"
|
||||
inc i
|
||||
|
||||
proc linkfiles(conf: ConfigRef; f: File; buf, objfiles: var string; clist: CfileList;
|
||||
llist: seq[string]) =
|
||||
@@ -1125,16 +1110,18 @@ proc runJsonBuildInstructions*(conf: ConfigRef; projectfile: AbsoluteFile) =
|
||||
let data = json.parseFile(jsonFile.string)
|
||||
let toCompile = data["compile"]
|
||||
doAssert toCompile.kind == JArray
|
||||
var cmds: TStringSeq = @[]
|
||||
var prettyCmds: TStringSeq = @[]
|
||||
var cmds: TStringSeq
|
||||
var prettyCmds: TStringSeq
|
||||
let prettyCb = proc (idx: int) =
|
||||
if prettyCmds[idx].len > 0: echo prettyCmds[idx]
|
||||
|
||||
for c in toCompile:
|
||||
doAssert c.kind == JArray
|
||||
doAssert c.len >= 2
|
||||
|
||||
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)
|
||||
|
||||
let linkCmd = data["linkcmd"]
|
||||
@@ -1150,10 +1137,8 @@ proc runJsonBuildInstructions*(conf: ConfigRef; projectfile: AbsoluteFile) =
|
||||
|
||||
except:
|
||||
let e = getCurrentException()
|
||||
var msg = "\ncaught exception:n" & e.msg & "\nstacktrace:\n" &
|
||||
getCurrentException().getStackTrace() &
|
||||
"error evaluating JSON file: " & jsonFile.string
|
||||
quit msg
|
||||
quit "\ncaught exception:n" & e.msg & "\nstacktrace:\n" & e.getStackTrace() &
|
||||
"error evaluating JSON file: " & jsonFile.string
|
||||
|
||||
proc genMappingFiles(conf: ConfigRef; list: CfileList): Rope =
|
||||
for it in list:
|
||||
|
||||
Reference in New Issue
Block a user