Fixed #329
This commit is contained in:
parent
0a280aa6dd
commit
83731a9b32
4 changed files with 33 additions and 11 deletions
|
|
@ -1063,7 +1063,8 @@ proc doAction(options: Options) =
|
||||||
parseCommand(execResult.command, newOptions)
|
parseCommand(execResult.command, newOptions)
|
||||||
for arg in execResult.arguments:
|
for arg in execResult.arguments:
|
||||||
parseArgument(arg, newOptions)
|
parseArgument(arg, newOptions)
|
||||||
for flag, val in execResult.flags:
|
for flag, vals in execResult.flags:
|
||||||
|
for val in vals:
|
||||||
parseFlag(flag, val, newOptions)
|
parseFlag(flag, val, newOptions)
|
||||||
doAction(newOptions)
|
doAction(newOptions)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,17 +16,18 @@ from compiler/astalgo import strTableGet
|
||||||
import compiler/options as compiler_options
|
import compiler/options as compiler_options
|
||||||
|
|
||||||
import common, version, options, packageinfo, cli
|
import common, version, options, packageinfo, cli
|
||||||
import os, strutils, strtabs, times, osproc, sets
|
import os, strutils, strtabs, tables, times, osproc, sets
|
||||||
|
|
||||||
when not declared(resetAllModulesHard):
|
when not declared(resetAllModulesHard):
|
||||||
import compiler/modulegraphs
|
import compiler/modulegraphs
|
||||||
|
|
||||||
type
|
type
|
||||||
|
Flags = TableRef[string, seq[string]]
|
||||||
ExecutionResult*[T] = object
|
ExecutionResult*[T] = object
|
||||||
success*: bool
|
success*: bool
|
||||||
command*: string
|
command*: string
|
||||||
arguments*: seq[string]
|
arguments*: seq[string]
|
||||||
flags*: StringTableRef
|
flags*: Flags
|
||||||
retVal*: T
|
retVal*: T
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -74,8 +75,7 @@ proc extractRequires(ident: PSym, result: var seq[PkgTuple]) =
|
||||||
when declared(newIdentCache):
|
when declared(newIdentCache):
|
||||||
var identCache = newIdentCache()
|
var identCache = newIdentCache()
|
||||||
|
|
||||||
proc setupVM(module: PSym; scriptName: string,
|
proc setupVM(module: PSym; scriptName: string, flags: Flags): PEvalContext =
|
||||||
flags: StringTableRef): PEvalContext =
|
|
||||||
## This procedure is exported in the compiler sources, but its implementation
|
## This procedure is exported in the compiler sources, but its implementation
|
||||||
## is too Nim-specific to be used by Nimble.
|
## is too Nim-specific to be used by Nimble.
|
||||||
## Specifically, the implementation of ``switch`` is problematic. Sooo
|
## Specifically, the implementation of ``switch`` is problematic. Sooo
|
||||||
|
|
@ -180,15 +180,20 @@ proc setupVM(module: PSym; scriptName: string,
|
||||||
setResult(a, compiler_options.command)
|
setResult(a, compiler_options.command)
|
||||||
cbconf switch:
|
cbconf switch:
|
||||||
if not flags.isNil:
|
if not flags.isNil:
|
||||||
flags[a.getString 0] = a.getString 1
|
let
|
||||||
|
key = a.getString 0
|
||||||
|
value = a.getString 1
|
||||||
|
if flags.hasKey(key):
|
||||||
|
flags[key].add(value)
|
||||||
|
else:
|
||||||
|
flags[key] = @[value]
|
||||||
|
|
||||||
proc getNimPrefixDir(): string = splitPath(findExe("nim")).head.parentDir
|
proc getNimPrefixDir(): string = splitPath(findExe("nim")).head.parentDir
|
||||||
|
|
||||||
when declared(ModuleGraph):
|
when declared(ModuleGraph):
|
||||||
var graph: ModuleGraph
|
var graph: ModuleGraph
|
||||||
|
|
||||||
proc execScript(scriptName: string, flags: StringTableRef,
|
proc execScript(scriptName: string, flags: Flags, options: Options): PSym =
|
||||||
options: Options): PSym =
|
|
||||||
## Executes the specified script. Returns the script's module symbol.
|
## Executes the specified script. Returns the script's module symbol.
|
||||||
##
|
##
|
||||||
## No clean up is performed and must be done manually!
|
## No clean up is performed and must be done manually!
|
||||||
|
|
@ -364,7 +369,7 @@ proc execTask*(scriptName, taskName: string,
|
||||||
##
|
##
|
||||||
## `scriptName` should be a filename pointing to the nimscript file.
|
## `scriptName` should be a filename pointing to the nimscript file.
|
||||||
result.success = true
|
result.success = true
|
||||||
result.flags = newStringTable()
|
result.flags = newTable[string, seq[string]]()
|
||||||
compiler_options.command = internalCmd
|
compiler_options.command = internalCmd
|
||||||
display("Executing", "task $# in $#" % [taskName, scriptName],
|
display("Executing", "task $# in $#" % [taskName, scriptName],
|
||||||
priority = HighPriority)
|
priority = HighPriority)
|
||||||
|
|
@ -392,7 +397,7 @@ proc execHook*(scriptName, actionName: string, before: bool,
|
||||||
##
|
##
|
||||||
## `scriptName` should be a filename pointing to the nimscript file.
|
## `scriptName` should be a filename pointing to the nimscript file.
|
||||||
result.success = true
|
result.success = true
|
||||||
result.flags = newStringTable()
|
result.flags = newTable[string, seq[string]]()
|
||||||
compiler_options.command = internalCmd
|
compiler_options.command = internalCmd
|
||||||
let hookName =
|
let hookName =
|
||||||
if before: actionName.toLowerAscii & "Before"
|
if before: actionName.toLowerAscii & "Before"
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,11 @@ task cr, "Testing `nimble c -r nimscript.nim` via setCommand":
|
||||||
--r
|
--r
|
||||||
setCommand "c", "nimscript.nim"
|
setCommand "c", "nimscript.nim"
|
||||||
|
|
||||||
|
task repeated, "Testing `nimble c nimscript.nim` with repeated flags":
|
||||||
|
--define: foo
|
||||||
|
--define: bar
|
||||||
|
setCommand "c", "nimscript.nim"
|
||||||
|
|
||||||
task api, "Testing nimscriptapi module functionality":
|
task api, "Testing nimscriptapi module functionality":
|
||||||
echo(getPkgDir())
|
echo(getPkgDir())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,17 @@ test "can use nimscript's setCommand with flags":
|
||||||
check exitCode == QuitSuccess
|
check exitCode == QuitSuccess
|
||||||
check "Hello World".normalize in lines[^2].normalize
|
check "Hello World".normalize in lines[^2].normalize
|
||||||
|
|
||||||
|
test "can use nimscript with repeated flags (issue #329)":
|
||||||
|
cd "nimscript":
|
||||||
|
let (output, exitCode) = execNimble("--debug", "repeated")
|
||||||
|
let lines = output.strip.splitLines()
|
||||||
|
check exitCode == QuitSuccess
|
||||||
|
var found = false
|
||||||
|
for line in lines:
|
||||||
|
if line.contains("--define:foo"):
|
||||||
|
found = true
|
||||||
|
check found == true
|
||||||
|
|
||||||
test "can list nimscript tasks":
|
test "can list nimscript tasks":
|
||||||
cd "nimscript":
|
cd "nimscript":
|
||||||
let (output, exitCode) = execNimble("tasks")
|
let (output, exitCode) = execNimble("tasks")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue