Fix #665 - avoid stdout in printPkgInfo

This commit is contained in:
Ganesh Viswanathan 2019-06-11 10:54:00 -05:00 committed by Dominik Picheta
commit 513780a382
2 changed files with 16 additions and 21 deletions

View file

@ -81,20 +81,19 @@ template `--`*(key: untyped) =
template printIfLen(varName) = template printIfLen(varName) =
if varName.len != 0: if varName.len != 0:
iniOut &= astToStr(varName) & ": \"\"\"" & varName & "\"\"\"\n" result &= astToStr(varName) & ": \"\"\"" & varName & "\"\"\"\n"
template printSeqIfLen(varName) = template printSeqIfLen(varName) =
if varName.len != 0: if varName.len != 0:
iniOut &= astToStr(varName) & ": \"" & varName.join(", ") & "\"\n" result &= astToStr(varName) & ": \"" & varName.join(", ") & "\"\n"
proc printPkgInfo() = proc printPkgInfo(): string =
if backend.len == 0: if backend.len == 0:
backend = "c" backend = "c"
var result = "[Package]\n"
iniOut = "[Package]\n"
if packageName.len != 0: if packageName.len != 0:
iniOut &= "name: \"" & packageName & "\"\n" result &= "name: \"" & packageName & "\"\n"
printIfLen version printIfLen version
printIfLen author printIfLen author
printIfLen description printIfLen description
@ -114,14 +113,13 @@ proc printPkgInfo() =
printSeqIfLen afterHooks printSeqIfLen afterHooks
if requiresData.len != 0: if requiresData.len != 0:
iniOut &= "\n[Deps]\n" result &= "\n[Deps]\n"
iniOut &= &"requires: \"{requiresData.join(\", \")}\"\n" result &= &"requires: \"{requiresData.join(\", \")}\"\n"
echo iniOut
proc onExit*() = proc onExit*() =
if "printPkgInfo".normalize in commandLineParams: if "printPkgInfo".normalize in commandLineParams:
printPkgInfo() if outFile.len != 0:
writeFile(outFile, printPkgInfo())
else: else:
var var
output = "" output = ""

View file

@ -21,8 +21,8 @@ const
internalCmd = "e" internalCmd = "e"
nimscriptApi = staticRead("nimscriptapi.nim") nimscriptApi = staticRead("nimscriptapi.nim")
proc execNimscript(nimsFile, projectDir, actionName: string, options: Options, proc execNimscript(nimsFile, projectDir, actionName: string, options: Options):
live = true): tuple[output: string, exitCode: int] = tuple[output: string, exitCode: int] =
let let
nimsFileCopied = projectDir / nimsFile.splitFile().name & "_" & getProcessId() & ".nims" nimsFileCopied = projectDir / nimsFile.splitFile().name & "_" & getProcessId() & ".nims"
outFile = getNimbleTempDir() & ".out" outFile = getNimbleTempDir() & ".out"
@ -46,13 +46,10 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options,
displayDebug("Executing " & cmd) displayDebug("Executing " & cmd)
if live: result.exitCode = execCmd(cmd)
result.exitCode = execCmd(cmd) if outFile.fileExists():
if outFile.fileExists(): result.output = outFile.readFile()
result.output = outFile.readFile() discard outFile.tryRemoveFile()
discard outFile.tryRemoveFile()
else:
result = execCmdEx(cmd, options = {poUsePath, poStdErrToStdOut})
proc getNimsFile(scriptName: string, options: Options): string = proc getNimsFile(scriptName: string, options: Options): string =
let let
@ -103,7 +100,7 @@ proc getIniFile*(scriptName: string, options: Options): string =
if not isIniResultCached: if not isIniResultCached:
let let
(output, exitCode) = (output, exitCode) =
execNimscript(nimsFile, scriptName.parentDir(), "printPkgInfo", options, live=false) execNimscript(nimsFile, scriptName.parentDir(), "printPkgInfo", options)
if exitCode == 0 and output.len != 0: if exitCode == 0 and output.len != 0:
result.writeFile(output) result.writeFile(output)