From 616db85c615d9cf00a1c3b85e59cf6401fed915b Mon Sep 17 00:00:00 2001 From: Xiao-Yong Date: Sat, 28 Oct 2017 02:38:31 -0500 Subject: [PATCH] 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 --- compiler/commands.nim | 4 +++- tests/testament/categories.nim | 3 ++- tools/nimresolve.nim | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/compiler/commands.nim b/compiler/commands.nim index bae1fda386..71de28e090 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 d620a45879..675ff946f1 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 9af24df5a6..a7a7a33bd6 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