Skip to content

Commit

Permalink
getParams once, hash nimscriptapi, fix loop in setcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance committed Apr 16, 2019
1 parent 51d03b3 commit 1e95fd4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/nimblepkg/nimscriptapi.nim
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var

beforeHooks: seq[string] = @[]
afterHooks: seq[string] = @[]
commandLineParams: seq[string] = @[]

startCommand = "e"
endCommand = startCommand
Expand All @@ -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
Expand Down Expand Up @@ -90,9 +91,7 @@ proc printPkgInfo() =
echo iniOut
proc onExit() =
let
params = getParams()
if "printPkgInfo" in params:
if "printPkgInfo" in commandLineParams:
printPkgInfo()
else:
var
Expand All @@ -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 =
Expand All @@ -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 =
Expand All @@ -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()
5 changes: 4 additions & 1 deletion src/nimblepkg/nimscriptwrapper.nim
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1e95fd4

Please sign in to comment.