From 1e95fd4104ec3ffb69fe67b9c2fac23f991e163a Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Tue, 16 Apr 2019 10:45:12 -0500 Subject: [PATCH] getParams once, hash nimscriptapi, fix loop in setcommand --- src/nimblepkg/nimscriptapi.nim | 22 ++++++++++------------ src/nimblepkg/nimscriptwrapper.nim | 5 ++++- 2 files changed, 14 insertions(+), 13 deletions(-) mode change 100644 => 100755 src/nimblepkg/nimscriptapi.nim mode change 100644 => 100755 src/nimblepkg/nimscriptwrapper.nim diff --git a/src/nimblepkg/nimscriptapi.nim b/src/nimblepkg/nimscriptapi.nim old mode 100644 new mode 100755 index 57ee7a2d..fbd8cab7 --- a/src/nimblepkg/nimscriptapi.nim +++ b/src/nimblepkg/nimscriptapi.nim @@ -27,6 +27,7 @@ var beforeHooks: seq[string] = @[] afterHooks: seq[string] = @[] + commandLineParams: seq[string] = @[] startCommand = "e" endCommand = startCommand @@ -38,9 +39,9 @@ proc requires*(deps: varargs[string]) = ## package. for d in deps: requiresData.add(d) -proc getParams(): seq[string] = +proc getParams() = for i in 4 .. paramCount(): - result.add paramStr(i) + commandLineParams.add paramStr(i) proc getCommand(): string = return endCommand @@ -90,9 +91,7 @@ proc printPkgInfo() = echo iniOut proc onExit() = - let - params = getParams() - if "printPkgInfo" in params: + if "printPkgInfo" in commandLineParams: printPkgInfo() else: var @@ -116,10 +115,9 @@ template task*(name: untyped; description: string; body: untyped): untyped = ## setCommand "c" proc `name Task`*() = body - let params = getParams() - if params.len == 0 or "help" in params: + if commandLineParams.len == 0 or "help" in commandLineParams: echo(astToStr(name), " ", description) - elif astToStr(name) in params: + elif astToStr(name) in commandLineParams: `name Task`() template before*(action: untyped, body: untyped): untyped = @@ -130,8 +128,7 @@ template before*(action: untyped, body: untyped): untyped = beforeHooks.add astToStr(action) - let params = getParams() - if astToStr(action) & "Before" in params: + if astToStr(action) & "Before" in commandLineParams: retVal = `action Before`() template after*(action: untyped, body: untyped): untyped = @@ -142,11 +139,12 @@ template after*(action: untyped, body: untyped): untyped = afterHooks.add astToStr(action) - let params = getParams() - if astToStr(action) & "After" in params: + if astToStr(action) & "After" in commandLineParams: retVal = `action After`() proc getPkgDir(): string = ## Returns the package directory containing the .nimble file currently ## being evaluated. result = currentSourcePath.rsplit(seps={'/', '\\', ':'}, maxsplit=1)[0] + +getParams() diff --git a/src/nimblepkg/nimscriptwrapper.nim b/src/nimblepkg/nimscriptwrapper.nim old mode 100644 new mode 100755 index 9708cd6b..9aba301a --- a/src/nimblepkg/nimscriptwrapper.nim +++ b/src/nimblepkg/nimscriptwrapper.nim @@ -19,6 +19,7 @@ type const internalCmd = "e" nimscriptApi = staticRead("nimscriptapi.nim") + nimscriptHash = $nimscriptApi.hash().abs() proc execNimscript(nimsFile, actionName: string, options: Options): tuple[output: string, exitCode: int] = let @@ -29,7 +30,7 @@ proc execNimscript(nimsFile, actionName: string, options: Options): tuple[output proc setupNimscript*(scriptName: string, options: Options): tuple[nimsFile, iniFile: string] = let cacheDir = getTempDir() / "nimblecache" - shash = $scriptName.hash().abs() + shash = $(scriptName & nimscriptHash).hash().abs() prjCacheDir = cacheDir / scriptName.splitFile().name & "_" & shash nimsCacheFile = prjCacheDir / scriptName.extractFilename().changeFileExt ".nims" @@ -74,6 +75,8 @@ proc execScript*(scriptName, actionName: string, options: Options): ExecutionRes result.success = true if "command" in j: result.command = $j["command"] + else: + result.command = internalCmd if "project" in j: result.arguments.add $j["project"] if "retVal" in j: