Substitute $nimbleDir in --path flags (#12750)

This commit is contained in:
genotrance 2019-11-28 06:58:38 -06:00 • committed by Andreas Rumpf
commit 010067f3cc
6 changed files with 30 additions and 3 deletions

View file

@ -367,8 +367,9 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
case switch.normalize case switch.normalize
of "path", "p": of "path", "p":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
addPath(conf, if pass == passPP: processCfgPath(conf, arg, info) for path in nimbleSubs(conf, arg):
else: processPath(conf, arg, info), info) addPath(conf, if pass == passPP: processCfgPath(conf, path, info)
else: processPath(conf, path, info), info)
of "nimblepath", "babelpath": of "nimblepath", "babelpath":
# keep the old name for compat # keep the old name for compat
if pass in {passCmd2, passPP} and optNoNimblePath notin conf.globalOptions: if pass in {passCmd2, passPP} and optNoNimblePath notin conf.globalOptions:

View file

@ -129,6 +129,10 @@ proc addPathRec(conf: ConfigRef; dir: string, info: TLineInfo) =
proc nimblePath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) = proc nimblePath*(conf: ConfigRef; path: AbsoluteDir, info: TLineInfo) =
addPathRec(conf, path.string, info) addPathRec(conf, path.string, info)
addNimblePath(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: when isMainModule:
proc v(s: string): Version = s.newVersion proc v(s: string): Version = s.newVersion

View file

@ -234,6 +234,7 @@ type
## symbols are always guaranteed to be style ## symbols are always guaranteed to be style
## insensitive. Otherwise hell would break lose. ## insensitive. Otherwise hell would break lose.
packageCache*: StringTableRef packageCache*: StringTableRef
nimblePaths*: seq[AbsoluteDir]
searchPaths*: seq[AbsoluteDir] searchPaths*: seq[AbsoluteDir]
lazyPaths*: seq[AbsoluteDir] lazyPaths*: seq[AbsoluteDir]
outFile*: RelativeFile outFile*: RelativeFile
@ -587,6 +588,15 @@ proc pathSubs*(conf: ConfigRef; p, config: string): string =
if "~/" in result: if "~/" in result:
result = result.replace("~/", home & '/') 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, proc toGeneratedFile*(conf: ConfigRef; path: AbsoluteFile,
ext: string): AbsoluteFile = ext: string): AbsoluteFile =
## converts "/home/a/mymodule.nim", "rod" to "/home/a/nimcache/mymodule.rod" ## converts "/home/a/mymodule.nim", "rod" to "/home/a/nimcache/mymodule.rod"

View file

@ -44,12 +44,12 @@ path="$lib/core"
path="$lib/pure" path="$lib/pure"
@if nimbabel: @if nimbabel:
nimblepath="$home/.nimble/pkgs/"
@if not windows: @if not windows:
nimblepath="/opt/nimble/pkgs/" nimblepath="/opt/nimble/pkgs/"
@else: @else:
# TODO: # TODO:
@end @end
nimblepath="$home/.nimble/pkgs/"
@end @end
@if danger or quick: @if danger or quick:

View file

@ -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"

View file

@ -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")