diff options
author | Yuriy Glukhov <yglukhov@users.noreply.github.com> | 2017-09-06 16:02:25 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-09-06 15:02:25 +0200 |
commit | d8944b93cbea3f70d2bcfaa996d5bd5e7322f5b9 (patch) | |
tree | 57b43b5c0859777aebcafdffd3828e5b3ccb75a7 /compiler/nimblecmd.nim | |
parent | cf28222d2c2f8ca9963611cccfcdb00283ceb33d (diff) | |
download | Nim-d8944b93cbea3f70d2bcfaa996d5bd5e7322f5b9.tar.gz |
Fixed handling of versions with dashes in nimble pkgs (#6335)
Diffstat (limited to 'compiler/nimblecmd.nim')
-rw-r--r-- | compiler/nimblecmd.nim | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim index 8042644b0..ab63f9e12 100644 --- a/compiler/nimblecmd.nim +++ b/compiler/nimblecmd.nim @@ -15,12 +15,6 @@ proc addPath*(path: string, info: TLineInfo) = if not options.searchPaths.contains(path): options.searchPaths.insert(path, 0) -proc versionSplitPos(s: string): int = - result = s.len-2 - #while result > 1 and s[result] in {'0'..'9', '.'}: dec result - while result > 1 and s[result] != '-': dec result - if s[result] != '-': result = s.len - type Version = distinct string @@ -63,10 +57,27 @@ proc `<`(ver: Version, ver2: Version): bool = else: return false +proc getPathVersion*(p: string): tuple[name, version: string] = + ## Splits path ``p`` in the format ``/home/user/.nimble/pkgs/package-0.1`` + ## into ``(/home/user/.nimble/pkgs/package, 0.1)`` + result.name = "" + result.version = "" + + const specialSeparator = "-#" + var sepIdx = p.find(specialSeparator) + if sepIdx == -1: + sepIdx = p.rfind('-') + + if sepIdx == -1: + result.name = p + return + + result.name = p[0 .. sepIdx - 1] + result.version = p.substr(sepIdx + 1) + proc addPackage(packages: StringTableRef, p: string) = - let x = versionSplitPos(p) - let name = p.substr(0, x-1) - let version = newVersion(if x < p.len: p.substr(x+1) else: "") + let (name, ver) = getPathVersion(p) + let version = newVersion(ver) if packages.getOrDefault(name).newVersion < version or (not packages.hasKey(name)): packages[name] = $version |