diff options
author | kitsunyan | 2018-03-13 23:23:58 +0000 |
---|---|---|
committer | kitsunyan | 2018-03-13 23:23:58 +0000 |
commit | 67d1413bbcbb07636a3267568572b99e0c92f219 (patch) | |
tree | d03ad0740f6a6d64d4a820ddaec82d3968181ba3 | |
parent | eedc8ca25aa95ffd152fe9fc3b4946e7ebe0d917 (diff) |
Perform arch filter during .SRCINFO parsing
-rw-r--r-- | src/aur.nim | 4 | ||||
-rw-r--r-- | src/common.nim | 3 | ||||
-rw-r--r-- | src/feature/syncinfo.nim | 14 | ||||
-rw-r--r-- | src/feature/syncinstall.nim | 41 | ||||
-rw-r--r-- | src/package.nim | 52 |
5 files changed, 48 insertions, 66 deletions
diff --git a/src/aur.nim b/src/aur.nim index acf9f96..42762f6 100644 --- a/src/aur.nim +++ b/src/aur.nim @@ -74,7 +74,7 @@ proc getRpcPackageInfo*(pkgs: seq[string]): (seq[RpcPackageInfo], Option[string] (@[], some(tr"failed to parse server response")) proc getAurPackageInfo*(pkgs: seq[string], rpcInfosOption: Option[seq[RpcPackageInfo]], - progressCallback: (int, int) -> void): (seq[PackageInfo], seq[string]) = + arch: string, progressCallback: (int, int) -> void): (seq[PackageInfo], seq[string]) = if pkgs.len == 0: (@[], @[]) else: @@ -105,7 +105,7 @@ proc getAurPackageInfo*(pkgs: seq[string], rpcInfosOption: Option[seq[RpcPackage if operror.isSome: (@[], operror) else: - let pkgInfos = parseSrcInfo("aur", srcInfo, + let pkgInfos = parseSrcInfo("aur", srcInfo, arch, aurUrl & base & ".git", none(string), none(string), none(string), rpcInfos) (pkgInfos, none(string)) diff --git a/src/common.nim b/src/common.nim index 8ef6dba..eab0750 100644 --- a/src/common.nim +++ b/src/common.nim @@ -331,7 +331,8 @@ proc obtainBuildPkgInfos*(config: Config, let output = execProcess(bashCmd, ["-c", """cd "$2/$3" && "$1" --printsrcinfo""", "bash", makePkgCmd, repoPath, git.path], options = {}) - parseSrcInfo(repo, output, git.url, some(git.branch), commit, some(git.path)) + parseSrcInfo(repo, output, config.arch, + git.url, some(git.branch), commit, some(git.path)) .filter(i => i.version == version) else: @[] diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim index 3c64282..5ff6b38 100644 --- a/src/feature/syncinfo.nim +++ b/src/feature/syncinfo.nim @@ -37,15 +37,11 @@ const ] proc formatDeps(title: string, config: Config, - refs: seq[ArchPackageReference]): PackageLineFormat = - proc formatDep(reference: ArchPackageReference): (string, bool) = - reference.reference.description - .map(d => ($reference.reference & ": " & d, true)) - .get(($reference.reference, false)) - + refs: seq[PackageReference]): PackageLineFormat = let values: seq[tuple[title: string, hasDesc: bool]] = refs - .filter(r => r.arch.isNone or r.arch == some(config.arch)) - .map(formatDep) + .map(r => r.description + .map(d => ($r & ": " & d, true)) + .get(($r, false))) if values.len > 0: (title, values.map(v => v.title), values.map(v => v.hasDesc).foldl(a or b)) @@ -110,7 +106,7 @@ proc handleSyncInfo*(args: seq[Argument], config: Config): int = findSyncTargets(handle, dbs, targets, false, false) let (pkgInfos, aerrors) = getAurPackageInfo(checkAur, none(seq[RpcPackageInfo]), - proc (a: int, b: int) = discard) + config.arch, proc (a: int, b: int) = discard) for e in aerrors: printError(config.color, e) let fullTargets = mapAurTargets[PackageInfo](syncTargets, pkgInfos) diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim index 3e5496d..230c95a 100644 --- a/src/feature/syncinstall.nim +++ b/src/feature/syncinstall.nim @@ -35,7 +35,7 @@ proc orderInstallation(ordered: seq[seq[seq[PackageInfo]]], grouped: seq[seq[Pac proc hasBuildDependency(pkgInfos: seq[PackageInfo]): bool = for pkgInfo in pkgInfos: for reference in pkgInfo.allDepends: - let satres = dependencies[reference.reference] + let satres = dependencies[reference] if satres.buildPkgInfo.isSome and not (satres.buildPkgInfo.unsafeGet in pkgInfos) and not (satres.buildPkgInfo.unsafeGet.name in orderedNamesSet): @@ -70,13 +70,12 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, dbs: seq[ptr AlpmD (Table[PackageReference, SatisfyResult], seq[PackageReference]) = proc checkDependencyCycle(pkgInfo: PackageInfo, reference: PackageReference): bool = for checkReference in pkgInfo.allDepends: - if checkReference.arch.isNone or checkReference.arch == some(config.arch): - if checkReference.reference == reference: - return false - let buildPkgInfo = satisfied.opt(checkReference.reference) - .map(r => r.buildPkgInfo).flatten - if buildPkgInfo.isSome and not checkDependencyCycle(buildPkgInfo.unsafeGet, reference): - return false + if checkReference == reference: + return false + let buildPkgInfo = satisfied.opt(checkReference) + .map(r => r.buildPkgInfo).flatten + if buildPkgInfo.isSome and not checkDependencyCycle(buildPkgInfo.unsafeGet, reference): + return false return true proc findInSatisfied(reference: PackageReference): Option[PackageInfo] = @@ -87,10 +86,9 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, dbs: seq[ptr AlpmD some((ConstraintOperation.eq, pkgInfo.version)))): return some(pkgInfo) for provides in pkgInfo.provides: - if provides.arch.isNone or provides.arch == some(config.arch): - if reference.isProvidedBy(provides.reference) and - checkDependencyCycle(pkgInfo, reference): - return some(pkgInfo) + if reference.isProvidedBy(provides) and + checkDependencyCycle(pkgInfo, reference): + return some(pkgInfo) return none(PackageInfo) proc findInDatabaseWithGroups(db: ptr AlpmDatabase, reference: PackageReference, @@ -157,7 +155,7 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, dbs: seq[ptr AlpmD try: withAur(): let (pkgInfos, aerrors) = getAurPackageInfo(aurCheck.map(r => r.name), - none(seq[RpcPackageInfo]), update) + none(seq[RpcPackageInfo]), config.arch, update) for e in aerrors: printError(config.color, e) let acceptedPkgInfos = pkgInfos.filter(i => not config.ignored(i.name, i.groups)) @@ -180,9 +178,8 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, dbs: seq[ptr AlpmD success.map(r => (r.reference, r.result.unsafeGet)) & aurSuccess.map(r => (r.reference, r.result.unsafeGet))).toTable - let newUnsatisfied = lc[x.reference | (y <- aurSuccess, - r <- y.result, i <- r.buildPkgInfo, x <- i.allDepends, - x.arch.isNone or x.arch == some(config.arch)), PackageReference].deduplicate + let newUnsatisfied = lc[x | (y <- aurSuccess, r <- y.result, i <- r.buildPkgInfo, + x <- i.allDepends), PackageReference].deduplicate let newTotalAurFail = (totalAurFail & aurFail).deduplicate let newTotalUnsatisfied = (newUnsatisfied & newTotalAurFail).deduplicate @@ -199,8 +196,7 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle, (Table[PackageReference, SatisfyResult], seq[PackageReference]) = let satisfied = pkgInfos.map(p => ((p.name, none(string), none(VersionConstraint)), (false, p.name, some(p)))).toTable - let unsatisfied = lc[x.reference | (i <- pkgInfos, x <- i.allDepends, - x.arch.isNone or x.arch == some(config.arch)), PackageReference].deduplicate + let unsatisfied = lc[x | (i <- pkgInfos, x <- i.allDepends), PackageReference].deduplicate findDependencies(config, handle, dbs, satisfied, unsatisfied, @[], printMode, noaur) proc filterNotFoundSyncTargets[T: RpcPackageInfo](syncTargets: seq[SyncPackageTarget], @@ -231,11 +227,10 @@ proc printUnsatisfied(config: Config, for _, satres in satisfied.pairs: for pkgInfo in satres.buildPkgInfo: for reference in pkgInfo.allDepends: - let pref = reference.reference - if pref in unsatisfied: + if reference in unsatisfied: printError(config.color, trp("unable to satisfy dependency '%s' required by %s\n") % - [$pref, pkgInfo.name]) + [$reference, pkgInfo.name]) proc editLoop(config: Config, base: string, repoPath: string, gitPath: Option[string], defaultYes: bool, noconfirm: bool): char = @@ -739,8 +734,8 @@ proc handleSyncInstall*(args: seq[Argument], config: Config): int = if fullRpcInfos.len > 0 and printFormat.isNone: echo(tr"downloading full package descriptions...") - let (aurPkgInfos, faerrors) = getAurPackageInfo(fullRpcInfos - .map(i => i.name), some(fullRpcInfos), proc (a: int, b: int) = discard) + let (aurPkgInfos, faerrors) = getAurPackageInfo(fullRpcInfos.map(i => i.name), + some(fullRpcInfos), config.arch, proc (a: int, b: int) = discard) if faerrors.len > 0: for e in faerrors: printError(config.color, e) diff --git a/src/package.nim b/src/package.nim index ce74303..57b69ca 100644 --- a/src/package.nim +++ b/src/package.nim @@ -21,11 +21,6 @@ type constraint: Option[VersionConstraint] ] - ArchPackageReference* = tuple[ - arch: Option[string], - reference: PackageReference - ] - RpcPackageInfo* = object of RootObj repo*: string base*: string @@ -43,13 +38,13 @@ type url*: Option[string] licenses*: seq[string] groups*: seq[string] - depends*: seq[ArchPackageReference] - makeDepends*: seq[ArchPackageReference] - checkDepends*: seq[ArchPackageReference] - optional*: seq[ArchPackageReference] - provides*: seq[ArchPackageReference] - conflicts*: seq[ArchPackageReference] - replaces*: seq[ArchPackageReference] + depends*: seq[PackageReference] + makeDepends*: seq[PackageReference] + checkDepends*: seq[PackageReference] + optional*: seq[PackageReference] + provides*: seq[PackageReference] + conflicts*: seq[PackageReference] + replaces*: seq[PackageReference] gitUrl*: string gitBranch*: Option[string] gitCommit*: Option[string] @@ -129,7 +124,7 @@ template repoPath*(tmpRoot: string, base: string): string = template buildPath*(repoPath: string, gitPath: Option[string]): string = gitPath.map(p => repoPath & "/" & p).get(repoPath) -template allDepends*(pkgInfo: PackageInfo): seq[ArchPackageReference] = +template allDepends*(pkgInfo: PackageInfo): seq[PackageReference] = pkgInfo.depends & pkgInfo.makeDepends & pkgInfo.checkDepends proc parseSrcInfoKeys(srcInfo: string): @@ -163,7 +158,7 @@ proc parseSrcInfoKeys(srcInfo: string): (baseSeq: baseSeq, table: table) proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], - baseSeq: ref seq[SrcInfoPair], nameSeq: ref seq[SrcInfoPair], + baseSeq: ref seq[SrcInfoPair], nameSeq: ref seq[SrcInfoPair], arch: string, gitUrl: string, gitBranch: Option[string], gitCommit: Option[string], gitPath: Option[string]): Option[PackageInfo] = let pairs = baseSeq[] & nameSeq[] @@ -190,15 +185,10 @@ proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], else: (workName, description, none(VersionConstraint)) - proc collectArch(keyName: string, arch: Option[string]): seq[ArchPackageReference] = - collect(arch.map(a => keyName & "_" & a).get(keyName)) + proc collectArch(keyName: string): seq[PackageReference] = + (collect(keyName) & collect(keyName & "_" & arch)) .map(splitConstraint) .filter(c => c.name.len > 0) - .map(c => (arch, (c.name, c.description, c.constraint))) - - proc collectArchs(keyName: string, archs: seq[string]): seq[ArchPackageReference] = - let archsFull = none(string) & archs.map(some) - lc[x | (a <- archsFull, x <- collectArch(keyName, a)), ArchPackageReference] let base = lc[x.value | (x <- baseSeq[], x.key == "pkgbase"), string].optLast @@ -214,19 +204,19 @@ proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], let licenses = collect("license") let groups = collect("groups") - let depends = collectArchs("depends", archs) - let makeDepends = collectArchs("makedepends", archs) - let checkDepends = collectArchs("checkdepends", archs) - let optional = collectArchs("optdepends", archs) - let provides = collectArchs("provides", archs) - let conflicts = collectArchs("conflicts", archs) - let replaces = collectArchs("replaces", archs) + let depends = collectArch("depends") + let makeDepends = collectArch("makedepends") + let checkDepends = collectArch("checkdepends") + let optional = collectArch("optdepends") + let provides = collectArch("provides") + let conflicts = collectArch("conflicts") + let replaces = collectArch("replaces") let info = rpcInfos.filter(i => i.name == name).optLast lc[PackageInfo(repo: repo, base: b, name: name, version: v, description: description, archs: archs, url: url, licenses: licenses, groups: groups, - depends: depends, makeDepends: makeDepends, checkdepends: checkDepends, + depends: depends, makeDepends: makeDepends, checkDepends: checkDepends, optional: optional, provides: provides, conflicts: conflicts, replaces: replaces, maintainer: info.map(i => i.maintainer).flatten, firstSubmitted: info.map( i => i.firstSubmitted).flatten, @@ -236,13 +226,13 @@ proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], gitUrl: gitUrl, gitBranch: gitBranch, gitCommit: gitCommit, gitPath: gitPath) | (b <- base, v <- versionFull), PackageInfo].optLast -proc parseSrcInfo*(repo: string, srcInfo: string, +proc parseSrcInfo*(repo: string, srcInfo: string, arch: string, gitUrl: string, gitBranch: Option[string], gitCommit: Option[string], gitPath: Option[string], rpcInfos: seq[RpcPackageInfo] = @[]): seq[PackageInfo] = let parsed = parseSrcInfoKeys(srcInfo) let packageSeq = toSeq(parsed.table.namedPairs) lc[x | (pair <- packageSeq, x <- parseSrcInfoName(repo, pair.key, rpcInfos, - parsed.baseSeq, pair.value, gitUrl, gitBranch, gitCommit, gitPath)), PackageInfo] + parsed.baseSeq, pair.value, arch, gitUrl, gitBranch, gitCommit, gitPath)), PackageInfo] proc `$`*(reference: PackageReference): string = reference.constraint |