Usability fixes and output improvements for compile command.

This commit is contained in:
Dominik Picheta 2016-12-22 15:18:46 +01:00
commit 971dc300bb
2 changed files with 13 additions and 7 deletions

View file

@ -635,6 +635,13 @@ proc build(options: Options) =
buildFromDir(pkgInfo, paths, false) buildFromDir(pkgInfo, paths, false)
proc compile(options: Options) = proc compile(options: Options) =
let bin = options.action.file
if bin == "":
raise newException(NimbleError, "You need to specify a file to compile.")
if not fileExists(bin):
raise newException(NimbleError, "Specified file does not exist.")
var pkgInfo = getPkgInfo(getCurrentDir(), options) var pkgInfo = getPkgInfo(getCurrentDir(), options)
nimScriptHint(pkgInfo) nimScriptHint(pkgInfo)
let paths = processDeps(pkginfo, options) let paths = processDeps(pkginfo, options)
@ -644,20 +651,18 @@ proc compile(options: Options) =
for option in options.action.compileOptions: for option in options.action.compileOptions:
args.add(option & " ") args.add(option & " ")
let bin = options.action.file
let backend = let backend =
if options.action.backend.len > 0: if options.action.backend.len > 0:
options.action.backend options.action.backend
else: else:
pkgInfo.backend pkgInfo.backend
if bin == "": display("Compiling", "$1 (from package $2) using $3 backend" %
raise newException(NimbleError, "You need to specify a file to compile.") [bin, pkgInfo.name, backend], priority = HighPriority)
display("Compiling", "$1 ($2) using $3 backend" % [bin, pkgInfo.name, backend],
priority = HighPriority)
doCmd("\"" & getNimBin() & "\" $# --noBabelPath $# \"$#\"" % doCmd("\"" & getNimBin() & "\" $# --noBabelPath $# \"$#\"" %
[backend, args, bin]) [backend, args, bin])
display("Success:", "Compilation finished", Success, HighPriority)
proc search(options: Options) = proc search(options: Options) =
## Searches for matches in ``options.action.search``. ## Searches for matches in ``options.action.search``.

View file

@ -28,7 +28,8 @@ proc doCmd*(cmd: string) =
if exitCode != QuitSuccess: if exitCode != QuitSuccess:
raise newException(NimbleError, raise newException(NimbleError,
"Execution failed with exit code " & $exitCode) "Execution failed with exit code $1\nCommand: $2\nOutput: $3" %
[$exitCode, cmd, output])
proc doCmdEx*(cmd: string): tuple[output: TaintedString, exitCode: int] = proc doCmdEx*(cmd: string): tuple[output: TaintedString, exitCode: int] =
let bin = extractBin(cmd) let bin = extractBin(cmd)