Skip to content

Commit

Permalink
nim_builder: do not use output* env variables
Browse files Browse the repository at this point in the history
Process the outputs variable, the output* vars are not reliable.
  • Loading branch information
ehmry committed Nov 24, 2021
1 parent fbd3a42 commit 86c48e8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions pkgs/development/nim-packages/nim_builder/nim_builder.nim
Original file line number Diff line number Diff line change
@@ -64,6 +64,19 @@ proc getNimbleValues(filePath, key: string): seq[string] =
if s.len > 0 and s[0] == '"':
s = s.unescape()

proc getOutputDir(name: string): string =
## Return the output directory for output `name`.
## If `name` is not a valid output then the first output
## is returned as a default.
let outputs = splitWhitespace getEnv("outputs")
doAssert(outputs.len > 0)
if outputs.contains name:
result = getEnv(name)
if result == "":
result = getEnv("out")
if result == "":
result = getEnv(outputs[0], "/dev/null")

proc configurePhase*() =
## Generate "config.nims" which will be read by the Nim
## compiler during later phases.
@@ -103,14 +116,14 @@ proc buildPhase*() =
nf = getNimbleFilePath()
bins = nf.getNimbleValues("bin")
srcDir = nf.getNimbleValue("srcDir", ".")
binDir = getenv("outputBin", getenv("out", "/dev/null")) / "bin"
binDir = getOutputDir("bin") / "bin"
if bins != @[]:
for bin in bins:
cmds.add("nim compile $# --outdir:$# $#" %
[getenv"nimFlags", binDir, normalizedPath(srcDir / bin)])
if getEnvBool"nimDoc":
echo "generating documentation"
let docDir = getenv("outputDoc", (getenv("out", "/dev/null") / "doc"))
let docDir = getOutputDir("doc") / "doc"
for path in walkFiles(srcDir / "*.nim"):
cmds.add("nim doc --outdir:$# $#" % [docDir, path])
if cmds.len > 0:
@@ -126,7 +139,7 @@ proc installPhase*() =
let
nf = getNimbleFilePath()
srcDir = nf.getNimbleValue("srcDir", ".")
devDir = getenv("outputDev", getenv("out", "/dev/null"))
devDir = getOutputDir "dev"
echo "Install ", srcDir, " to ", devDir
copyDir(normalizedPath(srcDir), normalizedPath(devDir / srcDir))
copyFile(nf, devDir / nf.extractFilename)

0 comments on commit 86c48e8

Please sign in to comment.