This commit is contained in:
Araq 2017-12-21 12:28:05 +01:00
commit 0181253eea

View file

@ -28,6 +28,10 @@ proc newVersion*(ver: string): Version =
proc isSpecial(ver: Version): bool = proc isSpecial(ver: Version): bool =
return ($ver).len > 0 and ($ver)[0] == '#' return ($ver).len > 0 and ($ver)[0] == '#'
proc isValidVersion(v: string): bool =
if v.len > 0:
if v[0] in {'#'} + Digits: return true
proc `<`*(ver: Version, ver2: Version): bool = proc `<`*(ver: Version, ver2: Version): bool =
## This is synced from Nimble's version module. ## This is synced from Nimble's version module.
@ -72,15 +76,23 @@ proc getPathVersion*(p: string): tuple[name, version: string] =
result.name = p result.name = p
return return
for i in sepIdx..<p.len:
if p[i] in {DirSep, AltSep}:
result.name = p
return
result.name = p[0 .. sepIdx - 1] result.name = p[0 .. sepIdx - 1]
result.version = p.substr(sepIdx + 1) result.version = p.substr(sepIdx + 1)
proc addPackage(packages: StringTableRef, p: string) = proc addPackage(packages: StringTableRef, p: string; info: TLineInfo) =
let (name, ver) = getPathVersion(p) let (name, ver) = getPathVersion(p)
let version = newVersion(ver) if isValidVersion(ver):
if packages.getOrDefault(name).newVersion < version or let version = newVersion(ver)
(not packages.hasKey(name)): if packages.getOrDefault(name).newVersion < version or
packages[name] = $version (not packages.hasKey(name)):
packages[name] = $version
else:
localError(info, "invalid package name: " & p)
iterator chosen(packages: StringTableRef): string = iterator chosen(packages: StringTableRef): string =
for key, val in pairs(packages): for key, val in pairs(packages):
@ -109,7 +121,7 @@ proc addPathRec(dir: string, info: TLineInfo) =
if dir[pos] in {DirSep, AltSep}: inc(pos) if dir[pos] in {DirSep, AltSep}: inc(pos)
for k,p in os.walkDir(dir): for k,p in os.walkDir(dir):
if k == pcDir and p[pos] != '.': if k == pcDir and p[pos] != '.':
addPackage(packages, p) addPackage(packages, p, info)
for p in packages.chosen: for p in packages.chosen:
addNimblePath(p, info) addNimblePath(p, info)