diff options
author | kitsunyan | 2018-05-01 19:30:15 +0000 |
---|---|---|
committer | kitsunyan | 2018-05-01 19:30:15 +0000 |
commit | dc6cbc555c9c7a091e7ba4ff7ccb71ad41a3a3b1 (patch) | |
tree | 50d7c28f73250dd8de02e7aa09f1d1c88376df1f /src/package.nim | |
parent | 81c557e0c4f3676a189f45dbba22392451cfc3f3 (diff) |
Use bare repositories to build repo packages from the same source
Diffstat (limited to 'src/package.nim')
-rw-r--r-- | src/package.nim | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/package.nim b/src/package.nim index 3884a34..c9ea5b2 100644 --- a/src/package.nim +++ b/src/package.nim @@ -53,7 +53,8 @@ type GitRepo* = tuple[ url: string, - branch: string, + bareName: Option[string], + branch: Option[string], path: string ] @@ -69,12 +70,12 @@ const packageRepos: seq[PackageRepo] = @[ (["arch"].toSet, ["core", "extra", "testing"].toSet, - ("https://git.archlinux.org/svntogit/packages.git", - "packages/${BASE}", "repos/${REPO}-${ARCH}")), + ("https://git.archlinux.org/svntogit/packages.git", none(string), + some("packages/${BASE}"), "repos/${REPO}-${ARCH}")), (["arch"].toSet, ["community", "community-testing", "multilib", "multilib-testing"].toSet, - ("https://git.archlinux.org/svntogit/community.git", - "packages/${BASE}", "repos/${REPO}-${ARCH}")) + ("https://git.archlinux.org/svntogit/community.git", none(string), + some("packages/${BASE}"), "repos/${REPO}-${ARCH}")) ] static: @@ -89,6 +90,23 @@ static: raise newException(SystemError, "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 + + template testBareNamesAndUrls(m1: untyped, m2: untyped) = + for x1, x2 in m1: + try: + if m2[x2] != x1: + raise newException(SystemError, "") + except: + raise newException(SystemError, "Invalid url <> bareName links") + + testBareNamesAndUrls(bareNameToUrl, urlToBareName) + testBareNamesAndUrls(urlToBareName, bareNameToUrl) + proc readOsId: Option[string] = var file: File if file.open("/usr/lib/os-release"): @@ -108,7 +126,7 @@ proc readOsId: Option[string] = let osId = readOsId() proc lookupGitRepo*(repo: string, base: string, arch: string): Option[GitRepo] = - template replaceAll(gitPart: string): string = + proc replaceAll(gitPart: string): string = gitPart .replace("${REPO}", repo) .replace("${BASE}", base) @@ -116,7 +134,8 @@ proc lookupGitRepo*(repo: string, base: string, arch: string): Option[GitRepo] = packageRepos .filter(pr => osId.isSome and osid.unsafeGet in pr.os and repo in pr.repo) - .map(pr => (pr.git.url.replaceAll, pr.git.branch.replaceAll, pr.git.path.replaceAll)) + .map(pr => (pr.git.url.replaceAll, pr.git.bareName, + pr.git.branch.map(replaceAll), pr.git.path.replaceAll)) .optFirst template repoPath*(tmpRoot: string, base: string): string = |