diff options
author | kitsunyan | 2018-03-13 23:25:44 +0000 |
---|---|---|
committer | kitsunyan | 2018-03-13 23:25:44 +0000 |
commit | 9fceba899e954d77b0aee27d3f084bab4728a770 (patch) | |
tree | f77874220784316d050e4c1f4159b05bba17b85a /src | |
parent | 67d1413bbcbb07636a3267568572b99e0c92f219 (diff) |
Filter repeating dependencies
Diffstat (limited to 'src')
-rw-r--r-- | src/common.nim | 32 | ||||
-rw-r--r-- | src/package.nim | 43 |
2 files changed, 40 insertions, 35 deletions
diff --git a/src/common.nim b/src/common.nim index eab0750..2da7dc0 100644 --- a/src/common.nim +++ b/src/common.nim @@ -37,38 +37,6 @@ proc toPackageReference*(dependency: ptr AlpmDependency): PackageReference = let description = if dependency.desc != nil: some($dependency.desc) else: none(string) ($dependency.name, description, op.map(o => (o, $dependency.version))) -proc checkConstraints(lop: ConstraintOperation, rop: ConstraintOperation, cmp: int): bool = - let (x1, x2) = if cmp > 0: - (1, -1) - elif cmp < 0: - (-1, 1) - else: - (0, 0) - - proc c(op: ConstraintOperation, x1: int, x2: int): bool = - case op: - of ConstraintOperation.eq: x1 == x2 - of ConstraintOperation.ge: x1 >= x2 - of ConstraintOperation.le: x1 <= x2 - of ConstraintOperation.gt: x1 > x2 - of ConstraintOperation.lt: x1 < x2 - - template a(x: int): bool = lop.c(x, x1) and rop.c(x, x2) - - a(2) or a(1) or a(0) or a(-1) or a(-2) - -proc isProvidedBy*(package: PackageReference, by: PackageReference): bool = - if package.name == by.name: - if package.constraint.isNone or by.constraint.isNone: - true - else: - let lcon = package.constraint.unsafeGet - let rcon = package.constraint.unsafeGet - let cmp = vercmp(lcon.version, rcon.version) - checkConstraints(lcon.operation, rcon.operation, cmp) - else: - false - proc checkAndRefresh*(color: bool, args: seq[Argument]): tuple[code: int, args: seq[Argument]] = let refreshCount = args.count((some("y"), "refresh")) if refreshCount > 0: diff --git a/src/package.nim b/src/package.nim index 57b69ca..b158b3d 100644 --- a/src/package.nim +++ b/src/package.nim @@ -1,6 +1,7 @@ import future, options, os, re, sequtils, sets, strutils, tables, - utils + utils, + "wrapper/alpm" type ConstraintOperation* {.pure.} = enum @@ -127,6 +128,38 @@ template buildPath*(repoPath: string, gitPath: Option[string]): string = template allDepends*(pkgInfo: PackageInfo): seq[PackageReference] = pkgInfo.depends & pkgInfo.makeDepends & pkgInfo.checkDepends +proc checkConstraints(lop: ConstraintOperation, rop: ConstraintOperation, cmp: int): bool = + let (x1, x2) = if cmp > 0: + (1, -1) + elif cmp < 0: + (-1, 1) + else: + (0, 0) + + proc c(op: ConstraintOperation, x1: int, x2: int): bool = + case op: + of ConstraintOperation.eq: x1 == x2 + of ConstraintOperation.ge: x1 >= x2 + of ConstraintOperation.le: x1 <= x2 + of ConstraintOperation.gt: x1 > x2 + of ConstraintOperation.lt: x1 < x2 + + template a(x: int): bool = lop.c(x, x1) and rop.c(x, x2) + + a(2) or a(1) or a(0) or a(-1) or a(-2) + +proc isProvidedBy*(package: PackageReference, by: PackageReference): bool = + if package.name == by.name: + if package.constraint.isNone or by.constraint.isNone: + true + else: + let lcon = package.constraint.unsafeGet + let rcon = package.constraint.unsafeGet + let cmp = vercmp(lcon.version, rcon.version) + checkConstraints(lcon.operation, rcon.operation, cmp) + else: + false + proc parseSrcInfoKeys(srcInfo: string): tuple[baseSeq: ref seq[SrcInfoPair], table: Table[string, ref seq[SrcInfoPair]]] = var table = initTable[string, ref seq[SrcInfoPair]]() @@ -190,6 +223,10 @@ proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], .map(splitConstraint) .filter(c => c.name.len > 0) + proc filterReferences(references: seq[PackageReference], + filterWith: seq[PackageReference]): seq[PackageReference] = + references.filter(r => filterWith.filter(w => r.isProvidedBy(w)).len == 0) + let base = lc[x.value | (x <- baseSeq[], x.key == "pkgbase"), string].optLast let version = collect("pkgver").optLast @@ -205,8 +242,8 @@ proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], let groups = collect("groups") let depends = collectArch("depends") - let makeDepends = collectArch("makedepends") - let checkDepends = collectArch("checkdepends") + let makeDepends = collectArch("makedepends").filterReferences(depends) + let checkDepends = collectArch("checkdepends").filterReferences(depends & makeDepends) let optional = collectArch("optdepends") let provides = collectArch("provides") let conflicts = collectArch("conflicts") |