aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-04-28 10:30:24 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-04-28 10:30:24 -0500
commitc57666d5dbafaf88c4a8b53149ce9b07f9391242 (patch)
treeaeec7ca06261432576e23dedc7678cff2e02dfea
parent33d77f82e878c86c0edf3bd21d359e5f40492ad2 (diff)
downloadnimterop-c57666d5dbafaf88c4a8b53149ce9b07f9391242.tar.gz
nimterop-c57666d5dbafaf88c4a8b53149ce9b07f9391242.zip
Enable conf detection in toast standalone
-rw-r--r--nimterop/getters.nim8
-rw-r--r--nimterop/nimconf.nim32
2 files changed, 29 insertions, 11 deletions
diff --git a/nimterop/getters.nim b/nimterop/getters.nim
index 121c8d5..d829cf0 100644
--- a/nimterop/getters.nim
+++ b/nimterop/getters.nim
@@ -726,7 +726,13 @@ proc loadPlugin*(gState: State, sourcePath: string) =
pdll = sourcePath.dll
if not fileExists(pdll) or
sourcePath.getLastModificationTime() > pdll.getLastModificationTime():
- discard execAction(&"{gState.nim.sanitizePath} c --app:lib --gc:markAndSweep {sourcePath.sanitizePath}")
+ let
+ # Get Nim configuration flags if not already specified in a .cfg file
+ flags =
+ if fileExists(sourcePath & ".cfg"): ""
+ else: getNimConfigFlags(getCurrentDir())
+ cmd = &"{gState.nim.sanitizePath} c --app:lib --gc:markAndSweep {flags} {sourcePath.sanitizePath}"
+ discard execAction(cmd)
doAssert fileExists(pdll), "No plugin binary generated for " & sourcePath
let lib = loadLib(pdll)
diff --git a/nimterop/nimconf.nim b/nimterop/nimconf.nim
index fdf2648..664675e 100644
--- a/nimterop/nimconf.nim
+++ b/nimterop/nimconf.nim
@@ -171,29 +171,41 @@ proc getNimConfig*(projectDir = ""): Config =
result.nimcacheDir = getNimcacheDir(projectDir)
-proc writeNimConfig*(cfg: Config, cfgFile: string) =
- # Write Nim configuration to file
- var
- cfgOut = &"--nimcache:\"{cfg.nimcacheDir}\"\n"
+proc getNimConfigFlags(cfg: Config): string =
+ # Convert configuration into Nim flags for cfg file or command line
+ result = &"--nimcache:\"{cfg.nimcacheDir}\"\n"
if (cfg.NimMajor, cfg.NimMinor, cfg.NimPatch) >= (1, 2, 0):
# --clearNimbleCache if Nim v1.2.0+
- cfgOut &= "--clearNimblePath\n"
+ result &= "--clearNimblePath\n"
# Add `nimblePaths` if detected - v1.2.0+
for path in cfg.nimblePaths:
- cfgOut &= &"--nimblePath:\"{path}\"\n"
+ result &= &"--nimblePath:\"{path}\"\n"
# Add `paths` in all cases if any detected
for path in cfg.paths:
- cfgOut &= &"--path:\"{path}\"\n"
+ result &= &"--path:\"{path}\"\n"
when defined(windows):
- cfgOut = cfgOut.replace("\\", "/")
+ result = result.replace("\\", "/")
- writeFile(cfgFile, cfgOut)
+proc getNimConfigFlags*(projectDir = ""): string =
+ ## Get Nim command line configuration flags for `projectDir`
+ ##
+ ## If `projectDir` is not specified, it is detected if compile time or
+ ## current directory is used.
+ let
+ cfg = getNimConfig(projectDir)
+ cfgOut = getNimConfigFlags(cfg)
+ return cfgOut.replace("\n", " ")
proc writeNimConfig*(cfgFile: string, projectDir = "") =
+ ## Write Nim configuration for `projectDir` to specified `cfgFile`
+ ##
+ ## If `projectDir` is not specified, it is detected if compile time or
+ ## current directory is used.
let
cfg = getNimConfig(projectDir)
- writeNimConfig(cfg, cfgFile)
+ cfgOut = getNimConfigFlags(cfg)
+ writeFile(cfgFile, cfgOut) \ No newline at end of file