Skip to content

Commit

Permalink
closes #139
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Aug 21, 2020
1 parent d466e0f commit 11070f7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
46 changes: 28 additions & 18 deletions nimph/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ when false:
var
priorProjectPath = config.projectPath
let
nextProjectPath = AbsoluteDir getCurrentDir()
nextProjectPath = getCurrentDir().toAbsoluteDir
filename = nextProjectPath.string / NimCfg

block complete:
Expand Down Expand Up @@ -116,25 +116,35 @@ var
proc findPrefixDir(): AbsoluteDir =
## determine the prefix directory for the current compiler
if compilerPrefixDir.isEmpty:
debug "find prefix"
let
compiler = runSomething("nim",
let compilerPath = findExe"nim"
if compilerPath == "":
raise newException(OSError, "cannot find a nim compiler in the path")

# start with the assumption that the compiler's parent directory works
compilerPrefixDir = parentDir(compilerPath.toAbsoluteFile)

if findExe("choosenim") == "":
# if choosenim is not found, we are done
result = compilerPrefixDir
else:
# if choosenim is in the path, we run the compiler to dump its config
let
compiler = runSomething(compilerPath,
@["--hints:off",
"--dump.format:json", "dump", "dummy"], {poDaemon})
if not compiler.ok:
warn "couldn't run the compiler to determine its location"
raise newException(OSError, "cannot find a nim compiler")
try:
let
js = parseJson(compiler.output)
compilerPrefixDir = AbsoluteDir js["prefixdir"].getStr
except JsonParsingError as e:
warn "`nim dump` json parse error: " & e.msg
raise
except KeyError:
warn "couldn't parse the prefix directory from `nim dump` output"
compilerPrefixDir = AbsoluteDir parentDir(findExe"nim")
debug "found prefix"
if not compiler.ok:
warn "couldn't run the compiler to determine its location"
warn "a choosenim-installed compiler might not work due to shims!"
try:
let
js = parseJson(compiler.output)
compilerPrefixDir = js["prefixdir"].getStr.toAbsoluteDir
except JsonParsingError as e:
warn "`nim dump` json parse error: " & e.msg
raise
except KeyError:
warn "couldn't parse the prefix directory from `nim dump` output"
warn "a choosenim-installed compiler might not work due to shims!"
result = compilerPrefixDir

proc loadAllCfgs*(directory: AbsoluteDir): ConfigRef =
Expand Down
20 changes: 8 additions & 12 deletions nimph/runner.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,21 @@ proc runSomething*(exe: string; args: seq[string]; options: set[ProcessOption];
opts.incl poInteractive
opts.incl poParentStreams
# the user wants interactivity
when defined(debug):
debug command, arguments.join(" ")
let
process = startProcess(command, args = arguments, options = opts)
result = RunOutput(ok: process.waitForExit == 0)
timer command & arguments.join(" "):
let
process = startProcess(command, args = arguments, options = opts)
result = RunOutput(ok: process.waitForExit == 0)
else:
# the user wants to capture output
command &= " " & quoteShellCommand(arguments)
when defined(debug):
debug command
let
(output, code) = execCmdEx(command, opts)
result = RunOutput(output: output, ok: code == 0)
timer command:
let
(output, code) = execCmdEx(command, opts)
result = RunOutput(output: output, ok: code == 0)

# for utility, also return the arguments we used
result.arguments = arguments

# a failure is worth noticing
if not result.ok:
notice exe & " " & arguments.join(" ")
when defined(debug):
debug "done running"

0 comments on commit 11070f7

Please sign in to comment.