summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorgenotrance <dev@genotrance.com>2019-11-28 06:58:38 -0600
committerAndreas Rumpf <rumpf_a@web.de>2019-11-28 13:58:38 +0100
commit010067f3cc43f24991731d644d1abc70a07d5f38 (patch)
tree4ad96386bb6a87191282fba542a41cfd84f869da
parentabe07eb75d31189e8afea90c3c8608574f1a0751 (diff)
downloadNim-010067f3cc43f24991731d644d1abc70a07d5f38.tar.gz
Substitute $nimbleDir in --path flags (#12750)
-rw-r--r--compiler/commands.nim5
-rw-r--r--compiler/nimblecmd.nim4
-rw-r--r--compiler/options.nim10
-rw-r--r--config/nim.cfg2
-rw-r--r--tests/nimble/tnimblepathdollar.nim7
-rw-r--r--tests/nimble/tnimblepathdollar.nims5
6 files changed, 30 insertions, 3 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index 88f6bef57..5e306288a 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -367,8 +367,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
   case switch.normalize
   of "path", "p":
     expectArg(conf, switch, arg, pass, info)
-    addPath(conf, if pass == passPP: processCfgPath(conf, arg, info)
-                  else: processPath(conf, arg, info), info)
+    for path in nimbleSubs(conf, arg):
+      addPath(conf, if pass == passPP: processCfgPath(conf, path, info)
+                    else: processPath(conf, path, info), info)
   of "nimblepath", "babelpath":
     # keep the old name for compat
     if pass in {passCmd2, passPP} and optNoNimblePath notin conf.globalOptions:
diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim
index fa938556b..9916f2461 100644
--- a/compiler/nimblecmd.nim
+++ b/compiler/nimblecmd.nim
@@ -129,6 +129,10 @@ proc addPathRec(conf: ConfigRef; dir: string, info: TLineInfo) =
 proc nimblePath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) =
   addPathRec(conf, path.string, info)
   addNimblePath(conf, path.string, info)
+  let i = conf.nimblePaths.find(path)
+  if i != -1:
+    conf.nimblePaths.delete(i)
+  conf.nimblePaths.insert(path, 0)
 
 when isMainModule:
   proc v(s: string): Version = s.newVersion
diff --git a/compiler/options.nim b/compiler/options.nim
index 8cfd2f2fb..f096f22e0 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -234,6 +234,7 @@ type
                              ## symbols are always guaranteed to be style
                              ## insensitive. Otherwise hell would break lose.
     packageCache*: StringTableRef
+    nimblePaths*: seq[AbsoluteDir]
     searchPaths*: seq[AbsoluteDir]
     lazyPaths*: seq[AbsoluteDir]
     outFile*: RelativeFile
@@ -587,6 +588,15 @@ proc pathSubs*(conf: ConfigRef; p, config: string): string =
   if "~/" in result:
     result = result.replace("~/", home & '/')
 
+iterator nimbleSubs*(conf: ConfigRef; p: string): string =
+  let pl = p.toLowerAscii
+  if "$nimblepath" in pl or "$nimbledir" in pl:
+    for i in countdown(conf.nimblePaths.len-1, 0):
+      let nimblePath = removeTrailingDirSep(conf.nimblePaths[i].string)
+      yield p % ["nimblepath", nimblePath, "nimbledir", nimblePath]
+  else:
+    yield p
+
 proc toGeneratedFile*(conf: ConfigRef; path: AbsoluteFile,
                       ext: string): AbsoluteFile =
   ## converts "/home/a/mymodule.nim", "rod" to "/home/a/nimcache/mymodule.rod"
diff --git a/config/nim.cfg b/config/nim.cfg
index 78b565d52..65a1d00d2 100644
--- a/config/nim.cfg
+++ b/config/nim.cfg
@@ -44,12 +44,12 @@ path="$lib/core"
 path="$lib/pure"
 
 @if nimbabel:
-  nimblepath="$home/.nimble/pkgs/"
   @if not windows:
     nimblepath="/opt/nimble/pkgs/"
   @else:
     # TODO:
   @end
+  nimblepath="$home/.nimble/pkgs/"
 @end
 
 @if danger or quick:
diff --git a/tests/nimble/tnimblepathdollar.nim b/tests/nimble/tnimblepathdollar.nim
new file mode 100644
index 000000000..994d975bb
--- /dev/null
+++ b/tests/nimble/tnimblepathdollar.nim
@@ -0,0 +1,7 @@
+import pkgA/module as A
+import pkgB/module as B
+import pkgC/module as C
+
+doAssert pkgATest() == 1, "Simple pkgA-0.1.0 wasn't added to path correctly."
+doAssert pkgBTest() == 0xDEADBEEF, "pkgB-#head wasn't picked over pkgB-0.1.0"
+doAssert pkgCTest() == 0xDEADBEEF, "pkgC-#head wasn't picked over pkgC-#aa11"
diff --git a/tests/nimble/tnimblepathdollar.nims b/tests/nimble/tnimblepathdollar.nims
new file mode 100644
index 000000000..ff45366a8
--- /dev/null
+++ b/tests/nimble/tnimblepathdollar.nims
@@ -0,0 +1,5 @@
+switch("nimblePath", "$projectdir/nimbleDir/simplePkgs")
+switch("path", "$nimblepath/pkgA-0.1.0")
+switch("path", "$nimblepath/pkgB-#head")
+switch("path", "$nimblepath/pkgC-#head")
+switch("noNimblePath")