diff options
Diffstat (limited to 'src/package.nim')
-rw-r--r-- | src/package.nim | 102 |
1 files changed, 77 insertions, 25 deletions
diff --git a/src/package.nim b/src/package.nim index 612f98f..181b5bf 100644 --- a/src/package.nim +++ b/src/package.nim @@ -91,8 +91,18 @@ const static: # test only single match available - let osSet = lc[x | (r <- packageRepos, x <- r.os), string].toHashSet - let repoSet = lc[x | (r <- packageRepos, x <- r.repo), string].toHashSet + when NimVersion >= "1.2": + let osSet = collect(initHashSet): + for r in packageRepos: + for x in r.os: + {x} + let repoSet = collect(initHashSet): + for r in packageRepos: + for x in r.repo: + {x} + else: + let osSet = lc[x | (r <- packageRepos, x <- r.os), string].toHashSet + let repoSet = lc[x | (r <- packageRepos, x <- r.repo), string].toHashSet for os in osSet: for repo in repoSet: let osValue = os @@ -102,10 +112,20 @@ static: "only single matching repo available: " & os & ":" & repo) # test unique url <> bareName links - let bareNameToUrl = lc[(x, r.git.url) | - (r <- packageRepos, x <- r.git.bareName), (string, string)].toTable - let urlToBareName = lc[(r.git.url, x) | - (r <- packageRepos, x <- r.git.bareName), (string, string)].toTable + when NimVersion >= "1.2": + let bareNameToUrl = collect(initTable): + for r in packageRepos: + for x in r.git.bareName: + {x:r.git.url} + let urlToBareName = collect(initTable): + for r in packageRepos: + for x in r.git.bareName: + {r.git.url:x} + else: + let bareNameToUrl = lc[(x, r.git.url) | + (r <- packageRepos, x <- r.git.bareName), (string, string)].toTable + let urlToBareName = lc[(r.git.url, x) | + (r <- packageRepos, x <- r.git.bareName), (string, string)].toTable template testBareNamesAndUrls(m1: untyped, m2: untyped) = for x1, x2 in m1: @@ -262,9 +282,15 @@ 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, gitSubdir: Option[string]): Option[PackageInfo] = proc collectFromPairs(pairs: seq[SrcInfoPair], keyName: string): seq[string] = - lc[x.value | (x <- pairs, x.key == keyName), string] - - proc collect(baseOnly: bool, keyName: string): seq[string] = + when NimVersion >= "1.2": + collect(newSeq): + for x in pairs: + if x.key == keyName: + x.value + else: + lc[x.value | (x <- pairs, x.key == keyName), string] + #changed the name as shadows collect macro from sugar + proc collectName(baseOnly: bool, keyName: string): seq[string] = let res = if baseOnly: @[] else: collectFromPairs(nameSeq[], keyName) if res.len == 0: collectFromPairs(baseSeq[], keyName).filter(x => x.len > 0) @@ -272,28 +298,42 @@ proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int res.filter(x => x.len > 0) proc collectArch(baseOnly: bool, keyName: string): seq[PackageReference] = - (collect(baseOnly, keyName) & collect(baseOnly, keyName & "_" & arch)) + (collectName(baseOnly, keyName) & collectName(baseOnly, keyName & "_" & arch)) .map(n => parsePackageReference(n, true)) .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, true)).len == 0) + + when NimVersion >= "1.2": + let base = optLast: + collect(newSeq): + for x in baseSeq[]: + if x.key == "pkgbase": + x.value + else: + let base = lc[x.value | (x <- baseSeq[], x.key == "pkgbase"), string].optLast + + let version = collectName(true, "pkgver").optLast + let release = collectName(true, "pkgrel").optLast + let epoch = collectName(true, "epoch").optLast + when NimVersion >= "1.2": + let versionFull = (block:collect(newSeq): + for v in version: + for r in release: + (v & "-" & r) + ).optLast.map(v => epoch.map(e => e & ":" & v).get(v)) + else: + let versionFull = lc[(v & "-" & r) | (v <- version, r <- release), string].optLast + .map(v => epoch.map(e => e & ":" & v).get(v)) - let base = lc[x.value | (x <- baseSeq[], x.key == "pkgbase"), string].optLast - - let version = collect(true, "pkgver").optLast - let release = collect(true, "pkgrel").optLast - let epoch = collect(true, "epoch").optLast - let versionFull = lc[(v & "-" & r) | (v <- version, r <- release), string].optLast - .map(v => epoch.map(e => e & ":" & v).get(v)) - - let description = collect(false, "pkgdesc").optLast - let archs = collect(false, "arch").filter(a => a != "any") - let url = collect(false, "url").optLast - let licenses = collect(false, "license") - let groups = collect(false, "groups") - let pgpKeys = collect(true, "validpgpkeys") + let description = collectName(false, "pkgdesc").optLast + let archs = collectName(false, "arch").filter(a => a != "any") + let url = collectName(false, "url").optLast + let licenses = collectName(false, "license") + let groups = collectName(false, "groups") + let pgpKeys = collectName(true, "validpgpkeys") let baseDepends = collectArch(true, "depends") let depends = collectArch(false, "depends") @@ -308,7 +348,19 @@ proc parseSrcInfoName(repo: string, name: string, baseIndex: int, baseCount: int let info = rpcInfos.filter(i => i.name == name).optLast - lc[((repo, b, name, v, description, info.map(i => i.maintainer).flatten, + when NimVersion >= "1.2": + optLast: + collect(newSeq): + for b in base: + for v in versionFull: + ((repo, b, name, v, description, info.map(i => i.maintainer).flatten, + info.map(i => i.firstSubmitted).flatten, info.map(i => i.lastModified).flatten, + info.map(i => i.outOfDate).flatten, info.map(i => i.votes).get(0), + info.map(i => i.popularity).get(0), gitUrl, gitSubdir), baseIndex, baseCount, + archs, url, licenses, groups, pgpKeys, depends, makeDepends, checkDepends, + optional, provides, conflicts, replaces) + else: + lc[((repo, b, name, v, description, info.map(i => i.maintainer).flatten, info.map(i => i.firstSubmitted).flatten, info.map(i => i.lastModified).flatten, info.map(i => i.outOfDate).flatten, info.map(i => i.votes).get(0), info.map(i => i.popularity).get(0), gitUrl, gitSubdir), baseIndex, baseCount, |