Implements NimblePkgVersion define. Fixes #625.

This commit is contained in:
Dominik Picheta 2019-09-22 00:53:52 +01:00
commit 4a2aaa07dc
5 changed files with 33 additions and 4 deletions

View file

@ -225,6 +225,7 @@ proc buildFromDir(
" `bin` key in your .nimble file?") " `bin` key in your .nimble file?")
var args = args var args = args
let realDir = pkgInfo.getRealDir() let realDir = pkgInfo.getRealDir()
let nimblePkgVersion = "-d:NimblePkgVersion=" & pkgInfo.version
for path in paths: args.add("--path:\"" & path & "\" ") for path in paths: args.add("--path:\"" & path & "\" ")
for bin in pkgInfo.bin: for bin in pkgInfo.bin:
# Check if this is the only binary that we want to build. # Check if this is the only binary that we want to build.
@ -242,8 +243,8 @@ proc buildFromDir(
createDir(outputDir) createDir(outputDir)
try: try:
doCmd("\"" & getNimBin() & "\" $# --noBabelPath $# $# \"$#\"" % doCmd("\"" & getNimBin() & "\" $# --noNimblePath $# $# $# \"$#\"" %
[pkgInfo.backend, join(args, " "), outputOpt, [pkgInfo.backend, nimblePkgVersion, join(args, " "), outputOpt,
realDir / bin.changeFileExt("nim")]) realDir / bin.changeFileExt("nim")])
except NimbleError: except NimbleError:
let currentExc = (ref NimbleError)(getCurrentException()) let currentExc = (ref NimbleError)(getCurrentException())
@ -530,6 +531,7 @@ proc execBackend(options: Options) =
nimScriptHint(pkgInfo) nimScriptHint(pkgInfo)
let deps = processDeps(pkginfo, options) let deps = processDeps(pkginfo, options)
let nimblePkgVersion = "-d:NimblePkgVersion=" & pkgInfo.version
var args = "" var args = ""
for dep in deps: args.add("--path:\"" & dep.getRealDir() & "\" ") for dep in deps: args.add("--path:\"" & dep.getRealDir() & "\" ")
for option in options.getCompilationFlags(): for option in options.getCompilationFlags():
@ -547,8 +549,8 @@ proc execBackend(options: Options) =
else: else:
display("Generating", ("documentation for $1 (from package $2) using $3 " & display("Generating", ("documentation for $1 (from package $2) using $3 " &
"backend") % [bin, pkgInfo.name, backend], priority = HighPriority) "backend") % [bin, pkgInfo.name, backend], priority = HighPriority)
doCmd("\"" & getNimBin() & "\" $# --noNimblePath $# \"$#\"" % doCmd("\"" & getNimBin() & "\" $# --noNimblePath $# $# \"$#\"" %
[backend, args, bin], showOutput = true) [backend, nimblePkgVersion, args, bin], showOutput = true)
display("Success:", "Execution finished", Success, HighPriority) display("Success:", "Execution finished", Success, HighPriority)
proc search(options: Options) = proc search(options: Options) =

View file

@ -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 not shown.

View file

@ -0,0 +1,3 @@
when isMainModule:
const NimblePkgVersion {.strdefine.} = "Unknown"
echo(NimblePkgVersion)

View file

@ -907,6 +907,16 @@ suite "nimble run":
check output.contains("tests/run/run --debug check") check output.contains("tests/run/run --debug check")
check output.contains("""Testing `nimble 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": test "compilation without warnings":
const buildDir = "./buildDir/" const buildDir = "./buildDir/"
const filesToBuild = [ const filesToBuild = [