Fix outfile issue when binary exists

This commit is contained in:
Ganesh Viswanathan 2019-05-31 12:49:15 -05:00 committed by Dominik Picheta
commit cbd63e61de
2 changed files with 17 additions and 9 deletions

17
src/nimblepkg/nimscriptapi.nim Executable file → Normal file
View file

@ -35,6 +35,7 @@ var
success = false success = false
retVal = true retVal = true
projectFile = "" projectFile = ""
outFile = ""
proc requires*(deps: varargs[string]) = proc requires*(deps: varargs[string]) =
## Call this to set the list of requirements of your Nimble ## Call this to set the list of requirements of your Nimble
@ -42,13 +43,18 @@ proc requires*(deps: varargs[string]) =
for d in deps: requiresData.add(d) for d in deps: requiresData.add(d)
proc getParams() = proc getParams() =
# Called by nimscriptwrapper.nim:execNimscript()
# nim e --flags /full/path/to/file.nims /full/path/to/file.out action
for i in 2 .. paramCount(): for i in 2 .. paramCount():
let let
param = paramStr(i) param = paramStr(i)
if param.fileExists(): if param[0] != '-':
projectFile = param if projectFile.len == 0:
elif param[0] != '-': projectFile = param
commandLineParams.add paramStr(i).normalize elif outFile.len == 0:
outFile = param
else:
commandLineParams.add param.normalize
proc getCommand*(): string = proc getCommand*(): string =
return command return command
@ -136,7 +142,8 @@ proc onExit*() =
output &= "\"retVal\": " & $retVal output &= "\"retVal\": " & $retVal
writeFile(projectFile & ".out", "{" & output & "}") if outFile.len != 0:
writeFile(outFile, "{" & output & "}")
# TODO: New release of Nim will move this `task` template under a # TODO: New release of Nim will move this `task` template under a
# `when not defined(nimble)`. This will allow us to override it in the future. # `when not defined(nimble)`. This will allow us to override it in the future.

9
src/nimblepkg/nimscriptwrapper.nim Executable file → Normal file
View file

@ -4,7 +4,7 @@
## Implements the new configuration system for Nimble. Uses Nim as a ## Implements the new configuration system for Nimble. Uses Nim as a
## scripting language. ## scripting language.
import common, version, options, packageinfo, cli import common, version, options, packageinfo, cli, tools
import hashes, json, os, streams, strutils, strtabs, import hashes, json, os, streams, strutils, strtabs,
tables, times, osproc, sets, pegs tables, times, osproc, sets, pegs
@ -26,6 +26,7 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options,
let let
shash = $projectDir.hash().abs() shash = $projectDir.hash().abs()
nimsFileCopied = projectDir / nimsFile.splitFile().name & "_" & shash & ".nims" nimsFileCopied = projectDir / nimsFile.splitFile().name & "_" & shash & ".nims"
outFile = getNimbleTempDir() & ".out"
let let
isScriptResultCopied = isScriptResultCopied =
@ -42,12 +43,12 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options,
let let
cmd = ("nim e --hints:off --verbosity:0 -p:" & (getTempDir() / "nimblecache").quoteShell & cmd = ("nim e --hints:off --verbosity:0 -p:" & (getTempDir() / "nimblecache").quoteShell &
" " & nimsFileCopied.quoteShell & " " & actionName).strip() " " & nimsFileCopied.quoteShell & " " & outFile.quoteShell & " " & actionName).strip()
displayDebug("Executing " & cmd)
if live: if live:
result.exitCode = execCmd(cmd) result.exitCode = execCmd(cmd)
let
outFile = nimsFileCopied & ".out"
if outFile.fileExists(): if outFile.fileExists():
result.output = outFile.readFile() result.output = outFile.readFile()
discard outFile.tryRemoveFile() discard outFile.tryRemoveFile()