Skip to content

Commit

Permalink
Substitute $nimbleDir in --path flags (#12750)
Browse files Browse the repository at this point in the history
  • Loading branch information
genotrance authored and Araq committed Nov 28, 2019
1 parent abe07eb commit 010067f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions compiler/nimblecmd.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion config/nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tests/nimble/tnimblepathdollar.nim
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions tests/nimble/tnimblepathdollar.nims
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 010067f

Please sign in to comment.