From cbd63e61dec2360a17a640987298ca702d69d4c3 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Fri, 31 May 2019 12:49:15 -0500 Subject: [PATCH] Fix outfile issue when binary exists --- src/nimblepkg/nimscriptapi.nim | 17 ++++++++++++----- src/nimblepkg/nimscriptwrapper.nim | 9 +++++---- 2 files changed, 17 insertions(+), 9 deletions(-) mode change 100755 => 100644 src/nimblepkg/nimscriptapi.nim mode change 100755 => 100644 src/nimblepkg/nimscriptwrapper.nim diff --git a/src/nimblepkg/nimscriptapi.nim b/src/nimblepkg/nimscriptapi.nim old mode 100755 new mode 100644 index eba18cd..0ace797 --- a/src/nimblepkg/nimscriptapi.nim +++ b/src/nimblepkg/nimscriptapi.nim @@ -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. diff --git a/src/nimblepkg/nimscriptwrapper.nim b/src/nimblepkg/nimscriptwrapper.nim old mode 100755 new mode 100644 index 0956b79..ff28e8e --- a/src/nimblepkg/nimscriptwrapper.nim +++ b/src/nimblepkg/nimscriptwrapper.nim @@ -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()