summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorXiao-Yong <jinxiaoyong@gmail.com>2017-10-28 02:38:31 -0500
committerAndreas Rumpf <rumpf_a@web.de>2017-10-28 09:38:31 +0200
commit616db85c615d9cf00a1c3b85e59cf6401fed915b (patch)
treed1eba13b7a7006641aa168926a9a808265253109
parent93fd0b0cb5911c8d313988f39a20bcdbc851f6cb (diff)
downloadNim-616db85c615d9cf00a1c3b85e59cf6401fed915b.tar.gz
Let the environment variable NIMBLE_DIR overrides nimblepath in cfg file (#6542)
* Let the environment variable NIMBLE_DIR overrides nimblepath in cfg file

If the length of NIMBLE_DIR is larger than zero, the nimblepath
will be set to $NIMBLE_DIR/pkgs
-rw-r--r--compiler/commands.nim4
-rw-r--r--tests/testament/categories.nim3
-rw-r--r--tools/nimresolve.nim4
3 files changed, 8 insertions, 3 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index bae1fda38..71de28e09 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -343,7 +343,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
     # keep the old name for compat
     if pass in {passCmd2, passPP} and not options.gNoNimblePath:
       expectArg(switch, arg, pass, info)
-      let path = processPath(arg, info, notRelativeToProj=true)
+      var path = processPath(arg, info, notRelativeToProj=true)
+      let nimbleDir = getEnv("NIMBLE_DIR")
+      if nimbleDir.len > 0 and pass == passPP: path = nimbleDir / "pkgs"
       nimblePath(path, info)
   of "nonimblepath", "nobabelpath":
     expectNoArg(switch, arg, pass, info)
diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim
index d620a4587..675ff946f 100644
--- a/tests/testament/categories.nim
+++ b/tests/testament/categories.nim
@@ -324,9 +324,10 @@ type PackageFilter = enum
   pfExtraOnly
   pfAll
 
+var nimbleDir = getEnv("NIMBLE_DIR").string
+if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
 let
   nimbleExe = findExe("nimble")
-  nimbleDir = getHomeDir() / ".nimble"
   packageDir = nimbleDir / "pkgs"
   packageIndex = nimbleDir / "packages.json"
 
diff --git a/tools/nimresolve.nim b/tools/nimresolve.nim
index 9af24df5a..a7a7a33bd 100644
--- a/tools/nimresolve.nim
+++ b/tools/nimresolve.nim
@@ -127,7 +127,9 @@ proc resolve(t: Task) =
 
     when considerNimbleDirs:
       if not t.noNimblePath:
-        if findInNimbleDir(t, getHomeDir() / ".nimble" / "pkgs"): return
+        var nimbleDir = getEnv("NIMBLE_DIR")
+        if nimbleDir.len == 0: nimbleDir = getHomeDir() / ".nimble"
+        if findInNimbleDir(t, nimbleDir / "pkgs"): return
         when not defined(windows):
           if findInNimbleDir(t, "/opt/nimble/pkgs"): return