Fix quoted switch, multi-line description, more caching (#642)
* Fix quoted switch, multi-line description, more caching * Incorporate feedback
This commit is contained in:
parent
6542c1ef16
commit
ca779afb20
3 changed files with 15 additions and 15 deletions
|
|
@ -75,7 +75,7 @@ template `--`*(key: untyped) =
|
|||
|
||||
template printIfLen(varName) =
|
||||
if varName.len != 0:
|
||||
iniOut &= astToStr(varName) & ": \"" & varName & "\"\n"
|
||||
iniOut &= astToStr(varName) & ": \"\"\"" & varName & "\"\"\"\n"
|
||||
|
||||
template printSeqIfLen(varName) =
|
||||
if varName.len != 0:
|
||||
|
|
@ -128,7 +128,9 @@ proc onExit*() =
|
|||
for key, val in flags.pairs:
|
||||
output &= "\"" & key & "\": ["
|
||||
for v in val:
|
||||
output &= "\"" & v & "\", "
|
||||
let v = if v.len > 0 and v[0] == '"': strutils.unescape(v)
|
||||
else: v
|
||||
output &= v.escape & ", "
|
||||
output = output[0 .. ^3] & "], "
|
||||
output = output[0 .. ^3] & "}, "
|
||||
|
||||
|
|
|
|||
|
|
@ -57,22 +57,19 @@ proc getNimsFile(scriptName: string, options: Options): string =
|
|||
cacheDir = getTempDir() / "nimblecache"
|
||||
shash = $scriptName.parentDir().hash().abs()
|
||||
prjCacheDir = cacheDir / scriptName.splitFile().name & "_" & shash
|
||||
nimscriptApiFile = cacheDir / "nimscriptapi.nim"
|
||||
|
||||
result = prjCacheDir / scriptName.extractFilename().changeFileExt ".nims"
|
||||
|
||||
proc setupNimscript(scriptName: string, options: Options) =
|
||||
let
|
||||
cacheDir = getTempDir() / "nimblecache"
|
||||
nimscriptApiFile = cacheDir / "nimscriptapi.nim"
|
||||
nimsFile = getNimsFile(scriptName, options)
|
||||
iniFile = result.changeFileExt(".ini")
|
||||
|
||||
let
|
||||
isNimscriptApiCached =
|
||||
nimscriptApiFile.fileExists() and nimscriptApiFile.getLastModificationTime() >
|
||||
getAppFilename().getLastModificationTime()
|
||||
|
||||
isScriptResultCached =
|
||||
nimsFile.fileExists() and nimsFile.getLastModificationTime() >
|
||||
isNimscriptApiCached and result.fileExists() and result.getLastModificationTime() >
|
||||
scriptName.getLastModificationTime()
|
||||
|
||||
if not isNimscriptApiCached:
|
||||
|
|
@ -80,14 +77,15 @@ proc setupNimscript(scriptName: string, options: Options) =
|
|||
writeFile(nimscriptApiFile, nimscriptApi)
|
||||
|
||||
if not isScriptResultCached:
|
||||
createDir(nimsFile.parentDir())
|
||||
writeFile(nimsFile, """
|
||||
createDir(result.parentDir())
|
||||
writeFile(result, """
|
||||
import system except getCommand, setCommand, switch, `--`,
|
||||
packageName, version, author, description, license, srcDir, binDir, backend,
|
||||
skipDirs, skipFiles, skipExt, installDirs, installFiles, installExt, bin, foreignDeps,
|
||||
requires, task, packageName
|
||||
""" &
|
||||
"import nimscriptapi, strutils\n" & scriptName.readFile() & "\nonExit()\n")
|
||||
discard tryRemoveFile(iniFile)
|
||||
|
||||
proc getIniFile*(scriptName: string, options: Options): string =
|
||||
let
|
||||
|
|
@ -101,7 +99,6 @@ proc getIniFile*(scriptName: string, options: Options): string =
|
|||
scriptName.getLastModificationTime()
|
||||
|
||||
if not isIniResultCached:
|
||||
setupNimscript(scriptName, options)
|
||||
let
|
||||
(output, exitCode) =
|
||||
execNimscript(nimsFile, scriptName.parentDir(), "printPkgInfo", options, live=false)
|
||||
|
|
@ -116,9 +113,6 @@ proc execScript(scriptName, actionName: string, options: Options):
|
|||
let
|
||||
nimsFile = getNimsFile(scriptName, options)
|
||||
|
||||
if not nimsFile.fileExists():
|
||||
setupNimScript(scriptName, options)
|
||||
|
||||
let
|
||||
(output, exitCode) = execNimscript(nimsFile, scriptName.parentDir(), actionName, options)
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
version = "0.1.0"
|
||||
author = "Dominik Picheta"
|
||||
description = "Test package"
|
||||
description = """Test package
|
||||
with multi-line description
|
||||
"""
|
||||
license = "BSD"
|
||||
|
||||
bin = @["nimscript"]
|
||||
|
|
@ -24,6 +26,8 @@ task cr, "Testing `nimble c -r nimscript.nim` via setCommand":
|
|||
task repeated, "Testing `nimble c nimscript.nim` with repeated flags":
|
||||
--define: foo
|
||||
--define: bar
|
||||
--define: "quoted"
|
||||
--define: "quoted\\\"with\\\"quotes"
|
||||
setCommand "c", "nimscript.nim"
|
||||
|
||||
task api, "Testing nimscriptapi module functionality":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue