added selfExe and selfExec for NimScript support

This commit is contained in:
Andreas Rumpf 2016-08-05 20:19:15 +02:00
commit 8882b062e1
2 changed files with 15 additions and 0 deletions

View file

@ -130,6 +130,8 @@ proc setupVM*(module: PSym; scriptName: string): PEvalContext =
elif not isAbsolute(val): elif not isAbsolute(val):
val = vthisDir / val val = vthisDir / val
gModuleOverrides[key] = val gModuleOverrides[key] = val
cbconf selfExe:
setResult(a, os.getAppFilename())
proc runNimScript*(scriptName: string; freshDefines=true) = proc runNimScript*(scriptName: string; freshDefines=true) =
passes.gIncludeFile = includeModule passes.gIncludeFile = includeModule

View file

@ -122,6 +122,10 @@ proc existsDir*(dir: string): bool =
## An alias for ``dirExists``. ## An alias for ``dirExists``.
dirExists(dir) dirExists(dir)
proc selfExe*(): string =
## Returns the currently running nim or nimble executable.
builtin
proc toExe*(filename: string): string = proc toExe*(filename: string): string =
## On Windows adds ".exe" to `filename`, else returns `filename` unmodified. ## On Windows adds ".exe" to `filename`, else returns `filename` unmodified.
(when defined(windows): filename & ".exe" else: filename) (when defined(windows): filename & ".exe" else: filename)
@ -208,6 +212,15 @@ proc exec*(command: string, input: string, cache = "") {.
log "exec: " & command: log "exec: " & command:
echo staticExec(command, input, cache) echo staticExec(command, input, cache)
proc selfExec*(command: string) =
## Executes an external command with the current nim/nimble executable.
## ``Command`` must not contain the "nim " part.
let c = selfExe() & " " & command
log "exec: " & c:
if rawExec(c) != 0:
raise newException(OSError, "FAILED: " & c)
checkOsError()
proc put*(key, value: string) = proc put*(key, value: string) =
## Sets a configuration 'key' like 'gcc.options.always' to its value. ## Sets a configuration 'key' like 'gcc.options.always' to its value.
builtin builtin