diff options
author | kitsunyan | 2018-04-22 22:47:55 +0000 |
---|---|---|
committer | kitsunyan | 2018-04-22 22:47:55 +0000 |
commit | a1a5e345daaeae0fae1da58e3683041d48e2583a (patch) | |
tree | 67349123a37b8459a405954cc6ca0548662d8467 /src/package.nim | |
parent | 276d8b9b1dd15f3c6fdf6c44f2bab35713a98b74 (diff) |
Add support for version constraints for targets
Diffstat (limited to 'src/package.nim')
-rw-r--r-- | src/package.nim | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/package.nim b/src/package.nim index f0a4ee1..30ff2f8 100644 --- a/src/package.nim +++ b/src/package.nim @@ -177,9 +177,29 @@ proc toPackageReference*(dependency: ptr AlpmDependency): PackageReference = template toPackageReference*(pkg: ptr AlpmPackage): PackageReference = ($pkg.name, none(string), some((ConstraintOperation.eq, $pkg.version))) -template toPackageReference*(pkg: PackageInfo): PackageReference = +template toPackageReference*(pkg: RpcPackageInfo): PackageReference = (pkg.name, none(string), some((ConstraintOperation.eq, pkg.version))) +proc parsePackageReference*(name: string, withDescription: bool): PackageReference = + var matches: array[3, string] + + let descIndex = name.find(": ") + let (description, workName) = if withDescription and descIndex >= 0: + (some(name[descIndex + 2 .. ^1]), name[0 .. descIndex - 1]) + else: + (none(string), name) + + if workName.match(re"([^><=]*)\ *(=|>=|<=|>|<)\ *([^ ]*)", matches): + let constraints = toSeq(enumerate[ConstraintOperation]()) + let index = constraints.map(s => $s).find(matches[1]) + + if index >= 0: + (matches[0], description, some((constraints[index], matches[2]))) + else: + (matches[0], description, none(VersionConstraint)) + else: + (workName, description, none(VersionConstraint)) + proc parseSrcInfoKeys(srcInfo: string): tuple[baseSeq: ref seq[SrcInfoPair], table: OrderedTable[string, ref seq[SrcInfoPair]]] = var table = initOrderedTable[string, ref seq[SrcInfoPair]]() @@ -224,29 +244,9 @@ proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int else: res - proc splitConstraint(name: string): PackageReference = - var matches: array[3, string] - - let descIndex = name.find(": ") - let (description, workName) = if descIndex >= 0: - (some(name[descIndex + 2 .. ^1]), name[0 .. descIndex - 1]) - else: - (none(string), name) - - if workName.match(re"([^><=]*)\ *(=|>=|<=|>|<)\ *([^ ]*)", matches): - let constraints = toSeq(enumerate[ConstraintOperation]()) - let index = constraints.map(s => $s).find(matches[1]) - - if index >= 0: - (matches[0], description, some((constraints[index], matches[2]))) - else: - (matches[0], description, none(VersionConstraint)) - else: - (workName, description, none(VersionConstraint)) - proc collectArch(keyName: string): seq[PackageReference] = (collect(keyName) & collect(keyName & "_" & arch)) - .map(splitConstraint) + .map(n => parsePackageReference(n, true)) .filter(c => c.name.len > 0) proc filterReferences(references: seq[PackageReference], |