mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-12 06:18:51 +00:00
Substitute $nimbleDir in --path flags (#12750)
This commit is contained in:
committed by
Andreas Rumpf
parent
abe07eb75d
commit
010067f3cc
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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:
|
||||
|
||||
7
tests/nimble/tnimblepathdollar.nim
Normal file
7
tests/nimble/tnimblepathdollar.nim
Normal 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"
|
||||
5
tests/nimble/tnimblepathdollar.nims
Normal file
5
tests/nimble/tnimblepathdollar.nims
Normal 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")
|
||||
Reference in New Issue
Block a user