nimbus.nim: use custom jsonscript executor
Work around https://github.com/nim-lang/Nim/issues/21741
This commit is contained in:
parent
9d03584047
commit
8371e7918c
|
@ -3,8 +3,6 @@ Upstream-Name: nimbus
|
|||
Upstream-Contact: Anna <cyber@sysrq.in>
|
||||
Source: https://nimbus.sysrq.in
|
||||
|
||||
# Sample paragraph, commented out:
|
||||
#
|
||||
# Files: src/*
|
||||
# Copyright: $YEAR $NAME <$CONTACT>
|
||||
# License: ...
|
||||
Files: ChangeLog
|
||||
Copyright: Nimbus contributors
|
||||
License: CC0-1.0
|
||||
|
|
|
@ -22,48 +22,64 @@ const
|
|||
|
||||
type
|
||||
Options = object
|
||||
genScript: bool
|
||||
target: string
|
||||
targetName: string
|
||||
inFile: string
|
||||
outFile: string
|
||||
paths: seq[string]
|
||||
|
||||
proc build(options: Options) =
|
||||
proc genScript(options: Options) =
|
||||
var paths = ""
|
||||
if options.paths.len != 0:
|
||||
paths = "-p:" & options.paths.join(" -p:")
|
||||
|
||||
let targetName = options.target.extractFilename
|
||||
let nimCache = nimCacheBaseDir / targetName
|
||||
let nimCache = nimCacheBaseDir / options.targetName
|
||||
exec fmt"{nimBin} {nimFlags} c --genScript:on --nimcache:{nimCache.quoteShell}" &
|
||||
fmt" -o:{options.outFile.quoteShell} {paths} {options.inFile.quoteShell}"
|
||||
|
||||
let txt2deps = findExe("txt2deps")
|
||||
if txt2deps.len != 0:
|
||||
let nimDepsFile = nimCache / targetName.addFileExt("deps")
|
||||
let nimDepsFile = nimCache / options.targetName.addFileExt("deps")
|
||||
let gccDepsFile = options.target.addFileExt("d")
|
||||
exec fmt"{txt2deps} -T:{options.target.quoteShell}" &
|
||||
fmt" -i:{nimDepsFile.quoteShell} -o:{gccDepsFile.quoteShell}"
|
||||
|
||||
proc execScript(options: Options) =
|
||||
let nimCache = nimCacheBaseDir / options.targetName
|
||||
withDir nimCache:
|
||||
exec fmt"{nimBin} {nimFlags} jsonscript --nimcache:{nimCache.quoteShell}" &
|
||||
fmt" -o:{options.outFile.quoteShell} {options.inFile.quoteShell}"
|
||||
|
||||
proc parseCmdLine(): Options =
|
||||
result.genScript = true
|
||||
for kind, key, val in getOpt():
|
||||
case kind
|
||||
of cmdArgument:
|
||||
result.inFile = key
|
||||
of cmdShortOption:
|
||||
of cmdLongOption, cmdShortOption:
|
||||
case key.normalize()
|
||||
of "t":
|
||||
# full path!
|
||||
result.target = val
|
||||
result.targetName = val.extractFilename
|
||||
result.outFile = val.addFileExt(ExeExt)
|
||||
of "p":
|
||||
result.paths.add(val)
|
||||
of "genscript":
|
||||
result.genScript = true
|
||||
of "jsonscript":
|
||||
result.genScript = false
|
||||
else:
|
||||
discard
|
||||
of cmdEnd, cmdLongOption:
|
||||
of cmdEnd:
|
||||
discard
|
||||
|
||||
let opts = parseCmdLine()
|
||||
build(opts)
|
||||
if opts.genScript:
|
||||
genScript(opts)
|
||||
else:
|
||||
execScript(opts)
|
||||
""" % [options.getNimBin().tripleQuoted,
|
||||
options.getNimFlags().tripleQuoted,
|
||||
options.getNimCacheBaseDir().tripleQuoted])
|
||||
|
|
|
@ -34,18 +34,20 @@ proc processDependencies(requires: seq[string], options: Options): seq[string] =
|
|||
else:
|
||||
result.add(dep.getPath(options).quoteShell)
|
||||
|
||||
proc application(ninja: File, input, target: string;
|
||||
proc application(ninja: File, input, targetName: string;
|
||||
paths: seq[string], options: Options) =
|
||||
debug(fmt"[build.ninja] Generating target for application '{target}'")
|
||||
debug(fmt"[build.ninja] Generating target for application '{targetName}'")
|
||||
|
||||
var vars = newStringTable()
|
||||
vars["target"] = "$builddir" / target.escape(body = true)
|
||||
vars["targetname"] = targetName
|
||||
vars["target"] = "$builddir" / targetName.escape(body = true)
|
||||
vars["sourcefile"] = input.escape(body = true)
|
||||
vars["nimcache"] = options.getNimCacheBaseDir() / target
|
||||
vars["nimcache"] = escape(options.getNimCacheBaseDir() / targetName,
|
||||
body = true)
|
||||
if paths.len != 0:
|
||||
vars["paths"] = escape("-p:" & paths.join(" -p:"), body = true)
|
||||
|
||||
let jsonScript = "$nimcache" / target.addFileExt("json").escape
|
||||
let jsonScript = "$nimcache" / targetName.addFileExt("json").escape
|
||||
ninja.build([jsonScript],
|
||||
rule = "genscript",
|
||||
inputs = [input.escape, "$builder"],
|
||||
|
@ -53,9 +55,9 @@ proc application(ninja: File, input, target: string;
|
|||
)
|
||||
ninja.newline()
|
||||
|
||||
ninja.build([target.addFileExt(ExeExt).escape],
|
||||
ninja.build([vars["target"].addFileExt(ExeExt)],
|
||||
rule = "jsonscript",
|
||||
inputs = [input.escape],
|
||||
inputs = [input.escape, "$builder"],
|
||||
implicit = [jsonScript],
|
||||
variables = vars
|
||||
)
|
||||
|
@ -144,6 +146,7 @@ proc setup(options: Options) =
|
|||
ninja.newline()
|
||||
|
||||
debug("[build.ninja] Writing variables")
|
||||
ninja.variable("builddir", options.getBuildDir().escape(body = true))
|
||||
ninja.variable("nim", options.getNimBin().escape(body = true))
|
||||
ninja.variable("nimbus", getAppFilename().escape(body = true))
|
||||
ninja.variable("cmdline", options.getCmdLine().escape(body = true))
|
||||
|
@ -168,8 +171,9 @@ proc setup(options: Options) =
|
|||
if pkgInfo.bin.len != 0:
|
||||
debug("[build.ninja] Generating 'genscript' rule")
|
||||
ninja.rule("genscript",
|
||||
command = "$nim --hints:off e $builder -T:$target $paths $sourcefile",
|
||||
description = "Generating build script for Nim application $out",
|
||||
command = "$nim --hints:off e $builder" &
|
||||
" --genscript -T:$target $paths $sourcefile",
|
||||
description = "Generating build script for Nim application $targetname",
|
||||
depfile = "$target".addFileExt("d"),
|
||||
deps = "gcc",
|
||||
pool = "console")
|
||||
|
@ -177,8 +181,9 @@ proc setup(options: Options) =
|
|||
|
||||
debug("[build.ninja] Generating 'jsonscript' rule")
|
||||
ninja.rule("jsonscript",
|
||||
command = "$nim jsonscript --nimcache:$nimcache -o:$out $sourcefile",
|
||||
description = "Compiling Nim application $out",
|
||||
command = "$nim --hints:off e $builder" &
|
||||
" --jsonscript -T:$target $sourcefile",
|
||||
description = "Compiling Nim application $targetname",
|
||||
depfile = "$target".addFileExt("d"),
|
||||
deps = "gcc",
|
||||
pool = "console")
|
||||
|
@ -216,13 +221,16 @@ proc setup(options: Options) =
|
|||
|
||||
for bin in pkgInfo.bin:
|
||||
let input = pkgInfo.getSourceDir(options) / bin.addFileExt("nim")
|
||||
let target = bin.lastPathPart
|
||||
ninja.application(input, target, depPaths, options)
|
||||
let targetName = bin.lastPathPart
|
||||
ninja.application(input, targetName, depPaths, options)
|
||||
|
||||
debug("[build.ninja] Generating 'all' target")
|
||||
ninja.build(["all"],
|
||||
rule = "phony",
|
||||
inputs = pkgInfo.bin.mapIt(it.lastPathPart.addFileExt(ExeExt).escape))
|
||||
inputs = pkgInfo.bin.mapIt(
|
||||
"$builddir" / it.lastPathPart.addFileExt(ExeExt).escape
|
||||
)
|
||||
)
|
||||
ninja.default(["all"])
|
||||
ninja.newline()
|
||||
|
||||
|
|
Loading…
Reference in New Issue