Fix a problem with extra build commands. (#14528)
When --compileOnly is on, extraCmds are not added to JsonBuildInstructions. ``` $ echo 'echo 123'>test.nim $ nim c --debuginfo --nimcache:cache test $ ls cache test test.dSYM test.nim $ tail -n3 cache/test.json "extraCmds": ["dsymutil /Users/khronos31/src/tmp/test"], "stdinInput": false } ``` ``` $ echo 'echo 123'>test.nim $ nim c --debuginfo --nimcache:cache --compileOnly test $ nim jsonscript --nimcache:cache test $ ls cache test test.nim $ tail -n3 cache/test.json "extraCmds": [], "stdinInput": false } ```
This commit is contained in:
parent
0489e76da7
commit
5900d8442c
1 changed files with 11 additions and 11 deletions
|
|
@ -767,19 +767,16 @@ template tryExceptOSErrorMessage(conf: ConfigRef; errorPrefix: string = "", body
|
||||||
(ose.msg & " " & $ose.errorCode))
|
(ose.msg & " " & $ose.errorCode))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
proc getExtraCmds(conf: ConfigRef; output: AbsoluteFile): seq[string] =
|
||||||
|
when defined(macosx):
|
||||||
|
if optCDebug in conf.globalOptions and optGenStaticLib notin conf.globalOptions:
|
||||||
|
# if needed, add an option to skip or override location
|
||||||
|
result.add "dsymutil " & $(output).quoteShell
|
||||||
|
|
||||||
proc execLinkCmd(conf: ConfigRef; linkCmd: string) =
|
proc execLinkCmd(conf: ConfigRef; linkCmd: string) =
|
||||||
tryExceptOSErrorMessage(conf, "invocation of external linker program failed."):
|
tryExceptOSErrorMessage(conf, "invocation of external linker program failed."):
|
||||||
execExternalProgram(conf, linkCmd, hintLinking)
|
execExternalProgram(conf, linkCmd, hintLinking)
|
||||||
|
|
||||||
proc maybeRunDsymutil(conf: ConfigRef; exe: AbsoluteFile) =
|
|
||||||
when defined(osx):
|
|
||||||
if optCDebug in conf.globalOptions and optGenStaticLib notin conf.globalOptions:
|
|
||||||
# if needed, add an option to skip or override location
|
|
||||||
let cmd = "dsymutil " & $(exe).quoteShell
|
|
||||||
conf.extraCmds.add cmd
|
|
||||||
tryExceptOSErrorMessage(conf, "invocation of dsymutil failed."):
|
|
||||||
execExternalProgram(conf, cmd, hintExecuting)
|
|
||||||
|
|
||||||
proc execCmdsInParallel(conf: ConfigRef; cmds: seq[string]; prettyCb: proc (idx: int)) =
|
proc execCmdsInParallel(conf: ConfigRef; cmds: seq[string]; prettyCb: proc (idx: int)) =
|
||||||
let runCb = proc (idx: int, p: Process) =
|
let runCb = proc (idx: int, p: Process) =
|
||||||
let exitCode = p.peekExitCode
|
let exitCode = p.peekExitCode
|
||||||
|
|
@ -850,6 +847,7 @@ proc displayProgressCC(conf: ConfigRef, path, compileCmd: string): string =
|
||||||
proc callCCompiler*(conf: ConfigRef) =
|
proc callCCompiler*(conf: ConfigRef) =
|
||||||
var
|
var
|
||||||
linkCmd: string
|
linkCmd: string
|
||||||
|
extraCmds: seq[string]
|
||||||
if conf.globalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
|
if conf.globalOptions * {optCompileOnly, optGenScript} == {optCompileOnly}:
|
||||||
return # speed up that call if only compiling and no script shall be
|
return # speed up that call if only compiling and no script shall be
|
||||||
# generated
|
# generated
|
||||||
|
|
@ -920,6 +918,7 @@ proc callCCompiler*(conf: ConfigRef) =
|
||||||
let mainOutput = if optGenScript notin conf.globalOptions: conf.prepareToWriteOutput
|
let mainOutput = if optGenScript notin conf.globalOptions: conf.prepareToWriteOutput
|
||||||
else: AbsoluteFile(conf.projectName)
|
else: AbsoluteFile(conf.projectName)
|
||||||
linkCmd = getLinkCmd(conf, mainOutput, objfiles)
|
linkCmd = getLinkCmd(conf, mainOutput, objfiles)
|
||||||
|
extraCmds = getExtraCmds(conf, mainOutput)
|
||||||
if optCompileOnly notin conf.globalOptions:
|
if optCompileOnly notin conf.globalOptions:
|
||||||
const MaxCmdLen = when defined(windows): 8_000 else: 32_000
|
const MaxCmdLen = when defined(windows): 8_000 else: 32_000
|
||||||
if linkCmd.len > MaxCmdLen:
|
if linkCmd.len > MaxCmdLen:
|
||||||
|
|
@ -929,7 +928,8 @@ proc callCCompiler*(conf: ConfigRef) =
|
||||||
linkViaResponseFile(conf, linkCmd)
|
linkViaResponseFile(conf, linkCmd)
|
||||||
else:
|
else:
|
||||||
execLinkCmd(conf, linkCmd)
|
execLinkCmd(conf, linkCmd)
|
||||||
maybeRunDsymutil(conf, mainOutput)
|
for cmd in extraCmds:
|
||||||
|
execExternalProgram(conf, cmd, hintExecuting)
|
||||||
else:
|
else:
|
||||||
linkCmd = ""
|
linkCmd = ""
|
||||||
if optGenScript in conf.globalOptions:
|
if optGenScript in conf.globalOptions:
|
||||||
|
|
@ -1017,7 +1017,7 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) =
|
||||||
str getLinkCmd(conf, conf.absOutFile, objfiles)
|
str getLinkCmd(conf, conf.absOutFile, objfiles)
|
||||||
|
|
||||||
lit ",\L\"extraCmds\": "
|
lit ",\L\"extraCmds\": "
|
||||||
lit $(%* conf.extraCmds)
|
lit $(%* getExtraCmds(conf, conf.absOutFile))
|
||||||
|
|
||||||
lit ",\L\"stdinInput\": "
|
lit ",\L\"stdinInput\": "
|
||||||
lit $(%* conf.projectIsStdin)
|
lit $(%* conf.projectIsStdin)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue