Skip to content

Commit

Permalink
Implements NimblePkgVersion define. Fixes #625.
Browse files Browse the repository at this point in the history
  • Loading branch information
dom96 committed Sep 22, 2019
1 parent 28ff2e0 commit 4a2aaa0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ proc buildFromDir(
" `bin` key in your .nimble file?")
var args = args
let realDir = pkgInfo.getRealDir()
let nimblePkgVersion = "-d:NimblePkgVersion=" & pkgInfo.version
for path in paths: args.add("--path:\"" & path & "\" ")
for bin in pkgInfo.bin:
# Check if this is the only binary that we want to build.
Expand All @@ -242,8 +243,8 @@ proc buildFromDir(
createDir(outputDir)

try:
doCmd("\"" & getNimBin() & "\" $# --noBabelPath $# $# \"$#\"" %
[pkgInfo.backend, join(args, " "), outputOpt,
doCmd("\"" & getNimBin() & "\" $# --noNimblePath $# $# $# \"$#\"" %
[pkgInfo.backend, nimblePkgVersion, join(args, " "), outputOpt,
realDir / bin.changeFileExt("nim")])
except NimbleError:
let currentExc = (ref NimbleError)(getCurrentException())
Expand Down Expand Up @@ -530,6 +531,7 @@ proc execBackend(options: Options) =
nimScriptHint(pkgInfo)
let deps = processDeps(pkginfo, options)

let nimblePkgVersion = "-d:NimblePkgVersion=" & pkgInfo.version
var args = ""
for dep in deps: args.add("--path:\"" & dep.getRealDir() & "\" ")
for option in options.getCompilationFlags():
Expand All @@ -547,8 +549,8 @@ proc execBackend(options: Options) =
else:
display("Generating", ("documentation for $1 (from package $2) using $3 " &
"backend") % [bin, pkgInfo.name, backend], priority = HighPriority)
doCmd("\"" & getNimBin() & "\" $# --noNimblePath $# \"$#\"" %
[backend, args, bin], showOutput = true)
doCmd("\"" & getNimBin() & "\" $# --noNimblePath $# $# \"$#\"" %
[backend, nimblePkgVersion, args, bin], showOutput = true)
display("Success:", "Execution finished", Success, HighPriority)

proc search(options: Options) =
Expand Down
14 changes: 14 additions & 0 deletions tests/nimbleVersionDefine/nimbleVersionDefine.nimble
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Package

version = "0.1.0"
author = "Dominik Picheta"
description = "A new awesome nimble package"
license = "MIT"
srcDir = "src"
bin = @["nimbleVersionDefine"]



# Dependencies

requires "nim >= 0.16.0"
Binary file added tests/nimbleVersionDefine/src/nimbleVersionDefine
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/nimbleVersionDefine/src/nimbleVersionDefine.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
when isMainModule:
const NimblePkgVersion {.strdefine.} = "Unknown"
echo(NimblePkgVersion)
10 changes: 10 additions & 0 deletions tests/tester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,16 @@ suite "nimble run":
check output.contains("tests/run/run --debug check")
check output.contains("""Testing `nimble run`: @["--debug", "check"]""")

test "NimbleVersion is defined":
cd "nimbleVersionDefine":
var (output, exitCode) = execNimble("c", "-r", "src/nimbleVersionDefine.nim")
check output.contains("0.1.0")
check exitCode == QuitSuccess

var (output2, exitCode2) = execNimble("run", "nimbleVersionDefine")
check output2.contains("0.1.0")
check exitCode2 == QuitSuccess

test "compilation without warnings":
const buildDir = "./buildDir/"
const filesToBuild = [
Expand Down

0 comments on commit 4a2aaa0

Please sign in to comment.