diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common.nim | 10 | ||||
-rw-r--r-- | src/feature/syncinstall.nim | 53 | ||||
-rw-r--r-- | src/package.nim | 22 | ||||
-rw-r--r-- | src/utils.nim | 10 |
4 files changed, 58 insertions, 37 deletions
diff --git a/src/common.nim b/src/common.nim index 2da7dc0..0dc73f3 100644 --- a/src/common.nim +++ b/src/common.nim @@ -245,6 +245,10 @@ proc bisectVersion(repoPath: string, debug: bool, firstCommit: Option[string], else: none(string) +proc obtainSrcInfo*(path: string): string = + execProcess(bashCmd, ["-c", """cd "$2" && "$1" --printsrcinfo""", + "bash", makePkgCmd, path], options = {}) + proc obtainBuildPkgInfos*(config: Config, pacmanTargets: seq[FullPackageTarget[RpcPackageInfo]]): (seq[PackageInfo], seq[string]) = type @@ -296,10 +300,8 @@ proc obtainBuildPkgInfos*(config: Config, else: discard forkWait(() => execResult(gitCmd, "-C", repoPath, "checkout", "-q", commit.unsafeGet)) - let output = execProcess(bashCmd, ["-c", - """cd "$2/$3" && "$1" --printsrcinfo""", - "bash", makePkgCmd, repoPath, git.path], options = {}) - parseSrcInfo(repo, output, config.arch, + let srcInfo = obtainSrcInfo(repoPath & "/" & git.path) + parseSrcInfo(repo, srcInfo, config.arch, git.url, some(git.branch), commit, some(git.path)) .filter(i => i.version == version) else: diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim index b945562..99da522 100644 --- a/src/feature/syncinstall.nim +++ b/src/feature/syncinstall.nim @@ -19,10 +19,8 @@ type ] BuildResult = tuple[ - version: string, - arch: string, ext: string, - names: seq[string] + pkgInfos: Table[string, PackageInfo] ] proc groupsSeq(pkg: ptr AlpmPackage): seq[string] = @@ -350,22 +348,34 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], noconfirm: bool, printError(config.color, tr"failed to build '$#'" % [base]) (none(BuildResult), buildCode) else: - let extracted = runProgram(bashCmd, "-c", - """source "$@" && echo "$epoch" && echo "$pkgver" && """ & - """echo "$pkgrel" && echo "${arch[@]}" && echo "${pkgname[@]}"""", - "bash", buildPath & "/PKGBUILD") - if extracted.len != 5: - printError(config.color, tr"failed to extract package info '$#'" % [base]) + let srcInfo = obtainSrcInfo(buildPath) + let resultPkgInfos = parseSrcInfo(pkgInfos[0].repo, srcInfo, config.arch, + pkgInfos[0].gitUrl, pkgInfos[0].gitBranch, pkgInfos[0].gitCommit, some(buildPath)) + + type ResultInfo = tuple[name: string, baseIndex: int, pkgInfo: Option[PackageInfo]] + + let resultPkgInfosTable = resultPkgInfos.map(i => (i.name, i)).toTable + let resultByNames: seq[ResultInfo] = pkgInfos + .map(i => (i.name, i.baseIndex, resultPkgInfosTable.opt(i.name))) + + let resultByIndices: seq[ResultInfo] = if pkgInfos[0].baseCount == resultPkgInfos.len: + resultByNames.map(res => (block: + if res.pkgInfo.isNone: + (res.name, res.baseIndex, some(resultPkgInfos[res.baseIndex])) + else: + res)) + else: + resultByNames + + let failedNames = lc[x.name | (x <- resultByIndices, x.pkgInfo.isNone), string] + + if failedNames.len > 0: + for name in failedNames: + printError(config.color, tr"$#: failed to extract package info" % [name]) (none(BuildResult), 1) else: - let epoch = extracted[0] - let versionShort = extracted[1] & "-" & extracted[2] - let version = if epoch.len > 0: epoch & ":" & versionShort else: versionShort - let archs = extracted[3].split(" ").toSet - let arch = if config.arch in archs: config.arch else: "any" - let names = extracted[4].split(" ") - - (some((version, arch, $confExt, names)), 0) + let table = resultByIndices.map(i => (i.name, i.pkgInfo.get)).toTable + (some(($confExt, table)), 0) proc buildFromSources(config: Config, commonArgs: seq[Argument], pkgInfos: seq[PackageInfo], noconfirm: bool): (Option[BuildResult], int) = @@ -429,11 +439,12 @@ proc installGroupFromSources(config: Config, commonArgs: seq[Argument], let (buildResults, buildCode) = buildNext(0, @[]) - proc formatArchiveFile(br: BuildResult, name: string): string = - config.tmpRoot & "/" & name & "-" & br.version & "-" & br.arch & br.ext + proc formatArchiveFile(pkgInfo: PackageInfo, ext: string): string = + let arch = if config.arch in pkgInfo.archs: config.arch else: "any" + config.tmpRoot & "/" & pkgInfo.name & "-" & pkgInfo.version & "-" & arch & ext - let files = lc[(name, formatArchiveFile(br, name)) | - (br <- buildResults, name <- br.names), (string, string)].toTable + let files = lc[(p.key, formatArchiveFile(p.value, br.ext)) | + (br <- buildResults, p <- br.pkgInfos.namedPairs), (string, string)].toTable let install = lc[x | (g <- basePackages, i <- g, x <- files.opt(i.name)), string] proc handleTmpRoot(clear: bool) = diff --git a/src/package.nim b/src/package.nim index b158b3d..483c058 100644 --- a/src/package.nim +++ b/src/package.nim @@ -35,6 +35,8 @@ type popularity*: float PackageInfo* = object of RpcPackageInfo + baseIndex*: int + baseCount*: int archs*: seq[string] url*: Option[string] licenses*: seq[string] @@ -161,8 +163,8 @@ proc isProvidedBy*(package: PackageReference, by: PackageReference): bool = false proc parseSrcInfoKeys(srcInfo: string): - tuple[baseSeq: ref seq[SrcInfoPair], table: Table[string, ref seq[SrcInfoPair]]] = - var table = initTable[string, ref seq[SrcInfoPair]]() + tuple[baseSeq: ref seq[SrcInfoPair], table: OrderedTable[string, ref seq[SrcInfoPair]]] = + var table = initOrderedTable[string, ref seq[SrcInfoPair]]() var matches: array[2, string] var baseSeq: ref seq[SrcInfoPair] var values: ref seq[SrcInfoPair] @@ -190,9 +192,9 @@ 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], arch: string, - gitUrl: string, gitBranch: Option[string], gitCommit: Option[string], +proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int, + rpcInfos: seq[RpcPackageInfo], 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[] proc collect(keyName: string): seq[string] = @@ -251,7 +253,8 @@ proc parseSrcInfoName(repo: string, name: string, rpcInfos: seq[RpcPackageInfo], let info = rpcInfos.filter(i => i.name == name).optLast - lc[PackageInfo(repo: repo, base: b, name: name, version: v, description: description, + lc[PackageInfo(baseIndex: baseIndex, baseCount: baseCount, + repo: repo, base: b, name: name, version: v, description: description, archs: archs, url: url, licenses: licenses, groups: groups, depends: depends, makeDepends: makeDepends, checkDepends: checkDepends, optional: optional, provides: provides, conflicts: conflicts, replaces: replaces, @@ -267,9 +270,10 @@ 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, arch, gitUrl, gitBranch, gitCommit, gitPath)), PackageInfo] + + toSeq(parsed.table.namedPairs).foldl(a & toSeq(parseSrcInfoName(repo, b.key, + a.len, parsed.table.len, rpcInfos, parsed.baseSeq, b.value, arch, + gitUrl, gitBranch, gitCommit, gitPath).items), newSeq[PackageInfo]()) proc `$`*(reference: PackageReference): string = reference.constraint diff --git a/src/utils.nim b/src/utils.nim index 8316110..288cf44 100644 --- a/src/utils.nim +++ b/src/utils.nim @@ -67,9 +67,13 @@ iterator enumerate*[T: enum]: T = for i in elow .. ehigh: yield T(i) -iterator namedPairs*[K, V](table: Table[K, V]): tuple[key: K, value: V] = - for key, value in table.pairs: - yield (key, value) +template namedPairsTyped(T: typedesc) = + iterator namedPairs*[K, V](table: T[K, V]): tuple[key: K, value: V] = + for key, value in table.pairs: + yield (key, value) + +namedPairsTyped(Table) +namedPairsTyped(OrderedTable) iterator reversed*[T](s: openArray[T]): T = for i in countdown(s.len - 1, 0): |