aboutsummaryrefslogtreecommitdiff
path: root/src/feature/syncinstall.nim
diff options
context:
space:
mode:
authorshirleyquirk2020-08-04 23:54:04 +0000
committerGitHub2020-08-04 23:54:04 +0000
commit22799b2e439d6b74ca648060faa1e3f1ee13f946 (patch)
tree512a18c53d4e7e6878ea134a2a307e3caec2278d /src/feature/syncinstall.nim
parentb2321b0ded6f4a9803daf9dbcbd88d56321a9305 (diff)
parent731f8d7692bfe08f5fd5890a98797f9b1b8d065d (diff)
Merge pull request #1 from shirleyquirk/collect
Collect
Diffstat (limited to 'src/feature/syncinstall.nim')
-rw-r--r--src/feature/syncinstall.nim208
1 files changed, 170 insertions, 38 deletions
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index bb97178..abb25b5 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -66,7 +66,14 @@ proc isVcs(name: string): bool =
proc orderInstallation(ordered: seq[seq[seq[PackageInfo]]], grouped: seq[seq[PackageInfo]],
satisfied: Table[PackageReference, SatisfyResult]): seq[seq[seq[PackageInfo]]] =
- let orderedNamesSet = lc[c.rpc.name | (a <- ordered, b <- a, c <- b), string].toHashSet
+ when NimVersion >= "1.2":
+ let orderedNamesSet = collect(initHashSet):
+ for a in ordered:
+ for b in a:
+ for c in b:
+ {c.rpc.name}
+ else:
+ let orderedNamesSet = lc[c.rpc.name | (a <- ordered, b <- a, c <- b), string].toHashSet
proc hasBuildDependency(pkgInfos: seq[PackageInfo]): bool =
for pkgInfo in pkgInfos:
@@ -241,8 +248,17 @@ 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 | (y <- aurSuccess, r <- y.result, i <- r.buildPkgInfo,
- x <- i.allDepends), PackageReference].deduplicate
+ when NimVersion >= "1.2":
+ let newUnsatisfied = deduplicate:
+ collect(newSeq):
+ for y in aurSuccess:
+ for r in y.result:
+ for i in r.buildPkgInfo:
+ for x in i.allDepends:
+ x
+ else:
+ 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
@@ -261,7 +277,14 @@ proc findDependencies(config: Config, handle: ptr AlpmHandle,
(Table[PackageReference, SatisfyResult], seq[PackageReference], seq[string]) =
let satisfied = pkgInfos.map(p => ((p.rpc.name, none(string), none(VersionConstraint)),
(false, p.rpc.name, some(p)))).toTable
- let unsatisfied = lc[x | (i <- pkgInfos, x <- i.allDepends), PackageReference].deduplicate
+ when NimVersion >= "1.2":
+ let unsatisfied = deduplicate:
+ collect(newSeq):
+ for i in pkgInfos:
+ for x in i.allDepends:
+ x
+ else:
+ let unsatisfied = lc[x | (i <- pkgInfos, x <- i.allDepends), PackageReference].deduplicate
findDependencies(config, handle, dbs, satisfied, unsatisfied, @[],
additionalPkgInfos, @[], nodepsCount, assumeInstalled, printMode, noaur)
@@ -473,7 +496,13 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], skipDeps: bool,
else:
resultByNames
- let failedNames = lc[x.name | (x <- resultByIndices, x.pkgInfo.isNone), string]
+ when NimVersion >= "1.2":
+ let failedNames = collect(newSeq):
+ for x in resultByIndices:
+ if x.pkgInfo.isNone:
+ x.name
+ else:
+ let failedNames = lc[x.name | (x <- resultByIndices, x.pkgInfo.isNone), string]
if failedNames.len > 0:
for name in failedNames:
@@ -563,11 +592,24 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
let arch = if pkgInfo.archs.len > 0: config.common.arch else: "any"
config.tmpRootInitial & "/" & pkgInfo.rpc.name & "-" & pkgInfo.rpc.version & "-" & arch & ext
- let allFiles = lc[(r.name, formatArchiveFile(r.pkgInfo, br.ext)) |
- (br <- buildResults, r <- br.replacePkgInfos), tuple[name: Option[string], file: string]]
+ when NimVersion >= "1.2":
+ let allFiles = collect(newSeq):
+ for br in buildResults:
+ for r in br.replacePkgInfos:
+ (name:r.name, file:formatArchiveFile(r.pkgInfo, br.ext))
+ else:
+ let allFiles = lc[(r.name, formatArchiveFile(r.pkgInfo, br.ext)) |
+ (br <- buildResults, r <- br.replacePkgInfos), tuple[name: Option[string], file: string]]
let filesTable = allFiles.filter(f => f.name.isSome).map(f => (f.name.unsafeGet, f.file)).toTable
- let install = lc[(i.rpc.name, x) | (g <- basePackages, i <- g, x <- filesTable.opt(i.rpc.name)),
- tuple[name: string, file: string]]
+ when NimVersion >= "1.2":
+ let install = collect(newSeq):
+ for g in basePackages:
+ for i in g:
+ for x in filesTable.opt(i.rpc.name):
+ (name:i.rpc.name,file:x)
+ else:
+ let install = lc[(i.rpc.name, x) | (g <- basePackages, i <- g, x <- filesTable.opt(i.rpc.name)),
+ tuple[name: string, file: string]]
proc handleTmpRoot(clear: bool) =
let installFiles = install.map(p => p.file)
@@ -628,11 +670,22 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
let pacmanDatabaseParams = pacmanCmd & pacmanParams(config.color,
commonArgs.keepOnlyOptions(commonOptions) & ("D", none(string), ArgumentType.short))
- let installParams = sudoPrefix & (pkgLibDir & "/install") &
- cacheDir & $cacheUser & $cacheGroup &
- $pacmanUpgradeParams.len & pacmanUpgradeParams &
- $pacmanDatabaseParams.len & pacmanDatabaseParams &
- lc[x | (i <- installWithReason, x <- [i.name, i.file, i.mode]), string]
+ when NimVersion >= "1.2":
+ let installParams = sudoPrefix & (pkgLibDir & "/install") &
+ cacheDir & $cacheUser & $cacheGroup &
+ $pacmanUpgradeParams.len & pacmanUpgradeParams &
+ $pacmanDatabaseParams.len & pacmanDatabaseParams &
+ (block:collect(newSeq):
+ for i in installWithReason:
+ for x in [i.name,i.file,i.mode]:
+ x
+ )
+ else:
+ let installParams = sudoPrefix & (pkgLibDir & "/install") &
+ cacheDir & $cacheUser & $cacheGroup &
+ $pacmanUpgradeParams.len & pacmanUpgradeParams &
+ $pacmanDatabaseParams.len & pacmanDatabaseParams &
+ lc[x | (i <- installWithReason, x <- [i.name, i.file, i.mode]), string]
let code = forkWait(() => execResult(installParams))
if code != 0:
@@ -662,8 +715,15 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
run(gitCmd, "-C", bareRepoPath, "tag", tag)
handleTmpRoot(true)
- let installedAs = lc[(r.name.unsafeGet, r.pkgInfo.rpc.name) | (br <- buildResults,
- r <- br.replacePkgInfos, r.name.isSome), (string, string)]
+ when NimVersion >= "1.2":
+ let installedAs = collect(newSeq):
+ for br in buildResults:
+ for r in br.replacePkgInfos:
+ if r.name.isSome:
+ (r.name.unsafeGet, r.pkgInfo.rpc.name)
+ else:
+ let installedAs = lc[(r.name.unsafeGet, r.pkgInfo.rpc.name) | (br <- buildResults,
+ r <- br.replacePkgInfos, r.name.isSome), (string, string)]
(installedAs, 0)
proc deduplicatePkgInfos(pkgInfos: seq[PackageInfo],
@@ -695,12 +755,24 @@ proc resolveDependencies(config: Config, pkgInfos: seq[PackageInfo],
newSeq[seq[seq[PackageInfo]]](), newSeq[string]())
else:
let buildAndAurNamesSet = pkgInfos.map(i => i.rpc.name).toHashSet
- let fullPkgInfos = (pkgInfos & lc[i | (s <- satisfied.values,
- i <- s.buildPkgInfo, not (i.rpc.name in buildAndAurNamesSet)), PackageInfo])
- .deduplicatePkgInfos(config, false)
+ when NimVersion >= "1.2":
+ let fullPkgInfos = (pkgInfos & (block:collect(newSeq):
+ for s in satisfied.values:
+ for i in s.buildPkgInfo:
+ if not (i.rpc.name in buildAndAurNamesSet):
+ i
+ )).deduplicatePkgInfos(config,false)
+ let additionalPacmanTargets = collect(newSeq):
+ for x in satisfied.values:
+ if not x.installed and x.buildPkgInfo.isNone:
+ x.name
+ else:
+ let fullPkgInfos = (pkgInfos & lc[i | (s <- satisfied.values,
+ i <- s.buildPkgInfo, not (i.rpc.name in buildAndAurNamesSet)), PackageInfo])
+ .deduplicatePkgInfos(config, false)
- let additionalPacmanTargets = lc[x.name | (x <- satisfied.values,
- not x.installed and x.buildPkgInfo.isNone), string]
+ let additionalPacmanTargets = lc[x.name | (x <- satisfied.values,
+ not x.installed and x.buildPkgInfo.isNone), string]
let orderedPkgInfos = orderInstallation(fullPkgInfos, satisfied)
(true, satisfied, additionalPacmanTargets, orderedPkgInfos, paths)
@@ -709,16 +781,29 @@ proc confirmViewAndImportKeys(config: Config, basePackages: seq[seq[seq[PackageI
installed: seq[Installed], noconfirm: bool): int =
if basePackages.len > 0: (block:
let installedVersions = installed.map(i => (i.name, i.version)).toTable
-
- printPackages(config.color, config.common.verbosePkgLists,
- lc[(i.rpc.name, i.rpc.repo, installedVersions.opt(i.rpc.name), i.rpc.version) |
- (g <- basePackages, b <- g, i <- b), PackageInstallFormat]
- .sorted((a, b) => cmp(a.name, b.name)))
+ when NimVersion >= "1.2":
+ printPackages(config.color, config.common.verbosePkgLists,(block:collect(newSeq):
+ for g in basePackages:
+ for b in g:
+ for i in b:
+ (i.rpc.name,i.rpc.repo,installedVersions.opt(i.rpc.name),i.rpc.version).PackageInstallFormat
+ ).sorted((a,b) => cmp(a.name, b.name)))
+ else:
+ printPackages(config.color, config.common.verbosePkgLists,
+ lc[(i.rpc.name, i.rpc.repo, installedVersions.opt(i.rpc.name), i.rpc.version) |
+ (g <- basePackages, b <- g, i <- b), PackageInstallFormat]
+ .sorted((a, b) => cmp(a.name, b.name)))
let input = printColonUserChoice(config.color,
tr"Proceed with building?", ['y', 'n'], 'y', 'n', noconfirm, 'y')
if input == 'y':
- let flatBasePackages = lc[x | (a <- basePackages, x <- a), seq[PackageInfo]]
+ when NimVersion >= "1.2":
+ let flatBasePackages = collect(newSeq):
+ for a in basePackages:
+ for x in a:
+ x
+ else:
+ let flatBasePackages = lc[x | (a <- basePackages, x <- a), seq[PackageInfo]]
proc checkNext(index: int, skipEdit: bool, skipKeys: bool): int =
if index < flatBasePackages.len:
@@ -749,7 +834,14 @@ proc confirmViewAndImportKeys(config: Config, basePackages: seq[seq[seq[PackageI
else:
let resultPkgInfos = reloadPkgInfos(config,
repoPath & "/" & pkgInfos[0].rpc.gitSubdir.get("."), pkgInfos)
- let pgpKeys = lc[x | (p <- resultPkgInfos, x <- p.pgpKeys), string].deduplicate
+ when NimVersion >= "1.2":
+ let pgpKeys = deduplicate:
+ collect(newSeq):
+ for p in resultPkgInfos:
+ for x in p.pgpKeys:
+ x
+ else:
+ let pgpKeys = lc[x | (p <- resultPkgInfos, x <- p.pgpKeys), string].deduplicate
proc keysLoop(index: int, skipKeys: bool): char =
if index >= pgpKeys.len:
@@ -890,8 +982,14 @@ proc filterIgnoresAndConflicts(config: Config, pkgInfos: seq[PackageInfo],
targetNamesSet: HashSet[string], installed: Table[string, Installed],
printMode: bool, noconfirm: bool): (seq[PackageInfo], seq[PackageInfo]) =
let acceptedPkgInfos = pkgInfos.filter(pkgInfo => (block:
- let instGroups = lc[x | (i <- installed.opt(pkgInfo.rpc.name),
- x <- i.groups), string]
+ when NimVersion >= "1.2":
+ let instGroups = collect(newSeq):
+ for i in installed.opt(pkgInfo.rpc.name):
+ for x in i.groups:
+ x
+ else:
+ let instGroups = lc[x | (i <- installed.opt(pkgInfo.rpc.name),
+ x <- i.groups), string]
if config.ignored(pkgInfo.rpc.name, (instGroups & pkgInfo.groups).deduplicate):
if pkgInfo.rpc.name in targetNamesSet:
@@ -908,10 +1006,26 @@ proc filterIgnoresAndConflicts(config: Config, pkgInfos: seq[PackageInfo],
true))
let nonConflicingPkgInfos = acceptedPkgInfos.foldl(block:
- let conflictsWith = lc[p | (p <- a, p.rpc.name != b.rpc.name and
- (lc[0 | (c <- b.conflicts, c.isProvidedBy(p.rpc.toPackageReference, true)), int].len > 0 or
- lc[0 | (c <- p.conflicts, c.isProvidedBy(b.rpc.toPackageReference, true)), int].len > 0)),
- PackageInfo]
+ when NimVersion >= "1.2":
+ let conflictsWith = collect(newSeq):
+ for p in a:
+ if p.rpc.name != b.rpc.name and
+ (block:collect(newSeq):
+ for c in b.conflicts:
+ if c.isProvidedBy(p.rpc.toPackageReference, true):
+ 0
+ ).len>0 or
+ (block:collect(newSeq):
+ for c in p.conflicts:
+ if c.isProvidedBy(p.rpc.toPackageReference, true):
+ 0
+ ).len>0:
+ p
+ else:
+ let conflictsWith = lc[p | (p <- a, p.rpc.name != b.rpc.name and
+ (lc[0 | (c <- b.conflicts, c.isProvidedBy(p.rpc.toPackageReference, true)), int].len > 0 or
+ lc[0 | (c <- p.conflicts, c.isProvidedBy(b.rpc.toPackageReference, true)), int].len > 0)),
+ PackageInfo]
if not printMode and conflictsWith.len > 0:
for conflict in conflictsWith:
printWarning(config.color,
@@ -1043,7 +1157,12 @@ proc obtainInstalledWithAur(config: Config): (seq[Installed], seq[string]) =
($package.name, $package.version, package.groupsSeq,
package.reason == AlpmReason.explicit, foreign)
- let installed = lc[createInstalled(p) | (p <- handle.local.packages), Installed]
+ when NimVersion >= "1.2":
+ let installed = collect(newSeq):
+ for p in handle.local.packages:
+ createInstalled(p)
+ else:
+ let installed = lc[createInstalled(p) | (p <- handle.local.packages), Installed]
let checkAurUpgradeNames = installed
.filter(i => i.foreign and (config.checkIgnored or not config.ignored(i.name, i.groups)))
.map(i => i.name)
@@ -1076,7 +1195,13 @@ proc resolveBuildTargets(config: Config, syncTargets: seq[SyncPackageTarget],
let installedTable = installed.map(i => (i.name, i)).toTable
let rpcAurTargets = fullTargets.filter(f => f.isAurTargetFull(config.aurRepo))
- let targetRpcInfos = lc[x | (t <- rpcAurTargets, x <- t.rpcInfo), RpcPackageInfo]
+ when NimVersion >= "1.2":
+ let targetRpcInfos = collect(newSeq):
+ for t in rpcAurTargets:
+ for x in t.rpcInfo:
+ x
+ else:
+ let targetRpcInfos = lc[x | (t <- rpcAurTargets, x <- t.rpcInfo), RpcPackageInfo]
let targetRpcInfoNames = targetRpcInfos.map(i => i.name).toHashSet
let rpcInfos = targetRpcInfos & upgradeRpcInfos.filter(i => not (i.name in targetRpcInfoNames))
@@ -1224,8 +1349,15 @@ proc handleInstall(args: seq[Argument], config: Config, syncTargets: seq[SyncPac
return true
return false
- lc[x.key | (x <- satisfied.namedPairs, not x.value.installed and
- x.value.buildPkgInfo.isNone and not x.key.checkSatisfied), PackageReference]
+ when NimVersion >= "1.2":
+ collect(newSeq):
+ for x in satisfied.namedPairs:
+ if not x.value.installed and x.value.buildPkgInfo.isNone and
+ not x.key.checkSatisfied:
+ x.key
+ else:
+ lc[x.key | (x <- satisfied.namedPairs, not x.value.installed and
+ x.value.buildPkgInfo.isNone and not x.key.checkSatisfied), PackageReference]
else:
@[]