From 997a93161f8f0816d9566f339d33ddc051ef5de8 Mon Sep 17 00:00:00 2001 From: Andy Davidoff Date: Thu, 28 Nov 2019 12:46:13 -0500 Subject: [PATCH] 0.0.14: support $nimbleDir on nim-1.0 --- nimph.nimble | 2 +- src/nimph/config.nim | 52 ++++++++++++++++++++++++++++++------------- src/nimph/project.nim | 3 +-- src/nimph/spec.nim | 1 + 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/nimph.nimble b/nimph.nimble index 9a1fc85..503d1b6 100644 --- a/nimph.nimble +++ b/nimph.nimble @@ -1,4 +1,4 @@ -version = "0.0.13" +version = "0.0.14" author = "disruptek" description = "nim package handler from the future" license = "MIT" diff --git a/src/nimph/config.nim b/src/nimph/config.nim index 77c9893..00af156 100644 --- a/src/nimph/config.nim +++ b/src/nimph/config.nim @@ -281,8 +281,7 @@ iterator packagePaths*(config: ConfigRef; exists = true): string = continue yield path -proc suggestNimbleDir*(config: ConfigRef; repo: string; - local = ""; global = ""): string = +proc suggestNimbleDir*(config: ConfigRef; local = ""; global = ""): string = ## come up with a useful nimbleDir based upon what we find in the ## current configuration, the location of the project, and the provided ## suggestions for local or global package directories @@ -295,13 +294,13 @@ proc suggestNimbleDir*(config: ConfigRef; repo: string; if local != "": assert local.endsWith(DirSep) {.warning: "look for a nimble packages file here?".} - for search in config.likelySearch(repo, libsToo = false): + for search in config.likelySearch(libsToo = false): if search.startsWith(local): result = local break either # otherwise, try to pick a global .nimble directory based upon lazy paths - for search in config.likelyLazy(repo): + for search in config.likelyLazy: {.warning: "maybe we should look for some nimble debris?".} if search.endsWith(PkgDir & DirSep): result = search.parentDir # ie. the parent of pkgs @@ -311,18 +310,41 @@ proc suggestNimbleDir*(config: ConfigRef; repo: string; # otherwise, try to make one up using the suggestion if global == "": - raise newException(IOError, "unable to guess global {dotNimble} directory") + raise newException(IOError, "can't guess global {dotNimble} directory") assert global.endsWith(DirSep) result = global break either +iterator pathSubsFor(config: ConfigRef; sub: string; conf: string): string = + ## a convenience to work around the compiler's broken pathSubs + if sub.toLowerAscii in ["nimbledir", "nimblepath"]: + when NimMajor <= 1 and NimMinor < 1: + # we have to pick the first lazy path because that's what Nimble does + block found: + for search in config.likelyLazy: + if search.endsWith(PkgDir & DirSep): + yield search.parentDir / "" + else: + yield search + break found + raise newException(ValueError, "unable to compute $" & sub) + else: + for path in config.nimbleSubs(&"${sub}"): + yield path / "" + else: + yield config.pathSubs(&"${sub}", conf) / "" + iterator pathSubstitutions(config: ConfigRef; path: string; conf: string; write: bool): string = ## compute the possible path substitions, including the original path const readSubs = @["nimcache", "config", "nimbledir", "nimblepath", "projectdir", "projectpath", "lib", "nim", "home"] - writeSubs = @["nimcache", "config", "projectdir", "lib", "nim", "home"] + writeSubs = + when writeNimbleDirPaths: + readSubs + else: + @["nimcache", "config", "projectdir", "lib", "nim", "home"] var matchedPath = false when defined(debug): @@ -334,15 +356,15 @@ iterator pathSubstitutions(config: ConfigRef; path: string; substitutions = if write: writeSubs else: readSubs for sub in substitutions.items: - let attempt = config.pathSubs(&"${sub}", conf) / "" - # ignore any empty substitutions - if attempt == "/": - continue - # note if any substitution matches the path - if path == attempt: - matchedPath = true - if path.startsWith(attempt): - yield path.replace(attempt, &"${sub}" / "") + for attempt in config.pathSubsFor(sub, conf): + # ignore any empty substitutions + if attempt == "/": + continue + # note if any substitution matches the path + if path == attempt: + matchedPath = true + if path.startsWith(attempt): + yield path.replace(attempt, &"${sub}" / "") # if a substitution matches the path, don't yield it at the end if not matchedPath: yield path diff --git a/src/nimph/project.nim b/src/nimph/project.nim index acc1e7e..5f1ce8d 100644 --- a/src/nimph/project.nim +++ b/src/nimph/project.nim @@ -111,8 +111,7 @@ proc nimbleDir*(project: Project): string = # otherwise, if we have configuration data, we should use it to determine # what the user might be using as a package directory -- local or elsewise elif project.cfg != nil: - result = project.cfg.suggestNimbleDir(project.repo, - local = project.localDeps, + result = project.cfg.suggestNimbleDir(local = project.localDeps, global = globaldeps) # otherwise, we'll just presume some configuration-free defaults diff --git a/src/nimph/spec.nim b/src/nimph/spec.nim index dc7dbe9..b41685f 100644 --- a/src/nimph/spec.nim +++ b/src/nimph/spec.nim @@ -25,6 +25,7 @@ const emptyRelease* {.strdefine.} = "#head" defaultRemote* {.strdefine.} = "origin" excludeMissingPaths* {.booldefine.} = false + writeNimbleDirPaths* {.booldefine.} = false hubTime* = initTimeFormat "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'" shortDate* = initTimeFormat "yyyy-MM-dd"