Fix outfile issue when binary exists
This commit is contained in:
parent
0e873c2702
commit
cbd63e61de
2 changed files with 17 additions and 9 deletions
17
src/nimblepkg/nimscriptapi.nim
Executable file → Normal file
17
src/nimblepkg/nimscriptapi.nim
Executable file → Normal file
|
|
@ -35,6 +35,7 @@ var
|
|||
success = false
|
||||
retVal = true
|
||||
projectFile = ""
|
||||
outFile = ""
|
||||
|
||||
proc requires*(deps: varargs[string]) =
|
||||
## 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)
|
||||
|
||||
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():
|
||||
let
|
||||
param = paramStr(i)
|
||||
if param.fileExists():
|
||||
projectFile = param
|
||||
elif param[0] != '-':
|
||||
commandLineParams.add paramStr(i).normalize
|
||||
if param[0] != '-':
|
||||
if projectFile.len == 0:
|
||||
projectFile = param
|
||||
elif outFile.len == 0:
|
||||
outFile = param
|
||||
else:
|
||||
commandLineParams.add param.normalize
|
||||
|
||||
proc getCommand*(): string =
|
||||
return command
|
||||
|
|
@ -136,7 +142,8 @@ proc onExit*() =
|
|||
|
||||
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
|
||||
# `when not defined(nimble)`. This will allow us to override it in the future.
|
||||
|
|
|
|||
9
src/nimblepkg/nimscriptwrapper.nim
Executable file → Normal file
9
src/nimblepkg/nimscriptwrapper.nim
Executable file → Normal file
|
|
@ -4,7 +4,7 @@
|
|||
## Implements the new configuration system for Nimble. Uses Nim as a
|
||||
## scripting language.
|
||||
|
||||
import common, version, options, packageinfo, cli
|
||||
import common, version, options, packageinfo, cli, tools
|
||||
import hashes, json, os, streams, strutils, strtabs,
|
||||
tables, times, osproc, sets, pegs
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options,
|
|||
let
|
||||
shash = $projectDir.hash().abs()
|
||||
nimsFileCopied = projectDir / nimsFile.splitFile().name & "_" & shash & ".nims"
|
||||
outFile = getNimbleTempDir() & ".out"
|
||||
|
||||
let
|
||||
isScriptResultCopied =
|
||||
|
|
@ -42,12 +43,12 @@ proc execNimscript(nimsFile, projectDir, actionName: string, options: Options,
|
|||
|
||||
let
|
||||
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:
|
||||
result.exitCode = execCmd(cmd)
|
||||
let
|
||||
outFile = nimsFileCopied & ".out"
|
||||
if outFile.fileExists():
|
||||
result.output = outFile.readFile()
|
||||
discard outFile.tryRemoveFile()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue