aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/feature/syncinstall.nim107
-rw-r--r--src/utils.nim14
2 files changed, 80 insertions, 41 deletions
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index 230c95a..b945562 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -289,58 +289,83 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], noconfirm: bool,
let gitPath = pkgInfos[0].gitPath
let buildPath = buildPath(repoPath, gitPath)
- let buildCode = forkWait(proc: int =
- if chdir(buildPath) == 0:
- discard setenv("PKGDEST", config.tmpRoot, 1)
- discard setenv("CARCH", config.arch, 1)
-
- if not noextract:
- removeDirQuiet(buildPath & "src")
-
- let optional: seq[tuple[arg: string, cond: bool]] = @[
- ("-e", noextract),
- ("-m", not config.color)
- ]
-
- execResult(@[makepkgCmd, "-f"] &
- optional.filter(o => o.cond).map(o => o.arg))
+ let confFileEnv = getenv("MAKEPKG_CONF")
+ let confFile = if confFileEnv == nil or confFileEnv.len == 0:
+ sysConfDir & "/makepkg.conf"
else:
- quit(1))
+ $confFileEnv
- if buildCode != 0:
- printError(config.color, tr"failed to build '$#'" % [base])
- (none(BuildResult), buildCode)
- else:
- let confFileEnv = getenv("MAKEPKG_CONF")
- let confFile = if confFileEnv == nil or confFileEnv.len == 0:
- sysConfDir & "/makepkg.conf"
- else:
- $confFileEnv
+ let workConfFile = config.tmpRoot & "/makepkg.conf"
+ let workConfFileCopySuccess = try:
+ copyFile(confFile, workConfFile)
+ var file: File
+ if file.open(workConfFile, fmAppend):
+ try:
+ file.writeLine("")
+ file.writeLine('#'.repeat(73))
+ file.writeLine("# PAKKU OVERRIDES")
+ file.writeLine('#'.repeat(73))
+ file.writeLine("CARCH=" & config.arch.bashEscape)
+ file.writeLine("PKGDEST=" & config.tmpRoot.bashEscape)
+ finally:
+ file.close()
+ true
+ except:
+ discard unlink(workConfFile)
+ false
+
+ if not workConfFileCopySuccess:
+ printError(config.color, tr"failed to copy config file '$#'" % [confFile])
+ (none(BuildResult), 1)
+ else:
let envExt = getenv("PKGEXT")
let confExt = if envExt == nil or envExt.len == 0:
runProgram(bashCmd, "-c",
"source \"$@\" && echo \"$PKGEXT\"",
- "bash", confFile).optFirst.get("")
+ "bash", workConfFile).optFirst.get("")
else:
$envExt
- 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])
- (none(BuildResult), 1)
+ let buildCode = forkWait(proc: int =
+ if chdir(buildPath) == 0:
+ discard setenv("MAKEPKG_CONF", "", 1)
+
+ if not noextract:
+ removeDirQuiet(buildPath & "src")
+
+ let optional: seq[tuple[arg: string, cond: bool]] = @[
+ ("-e", noextract),
+ ("-m", not config.color)
+ ]
+
+ execResult(@[makepkgCmd, "--config", workConfFile, "-f"] &
+ optional.filter(o => o.cond).map(o => o.arg))
+ else:
+ quit(1))
+
+ discard unlink(workConfFile)
+
+ if buildCode != 0:
+ printError(config.color, tr"failed to build '$#'" % [base])
+ (none(BuildResult), buildCode)
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 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])
+ (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)
proc buildFromSources(config: Config, commonArgs: seq[Argument],
pkgInfos: seq[PackageInfo], noconfirm: bool): (Option[BuildResult], int) =
diff --git a/src/utils.nim b/src/utils.nim
index 1d7c6bd..8316110 100644
--- a/src/utils.nim
+++ b/src/utils.nim
@@ -179,6 +179,20 @@ proc removeDirQuiet*(s: string) =
except:
discard
+const bashSpecialCharacters = " \t\"'`()[]{}#&|;!\\*~<>?"
+
+proc bashEscape*(s: string): string =
+ result = ""
+ for c in s:
+ if c in bashSpecialCharacters:
+ result &= "\\" & c
+ elif c == "\n"[0]:
+ result &= "$'\\n'"
+ elif c.cuint < 0x20.cuint or c.cuint > 0x80.cuint:
+ result &= "$'\\0x" & c.toHex & "'"
+ else:
+ result &= c
+
proc dgettext(domain: cstring, s: cstring): cstring
{.cdecl, importc: "dgettext".}