Skip to content
Permalink
Browse files

Provide custom config for makepkg instead of exporting variables

  • Loading branch information...
kitsunyan committed Mar 15, 2018
1 parent c09885f commit 864cc0373fd6095295f68cc44d1657bd17269732
Showing with 80 additions and 41 deletions.
  1. +66 −41 src/feature/syncinstall.nim
  2. +14 −0 src/utils.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) =
@@ -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".}

0 comments on commit 864cc03

Please sign in to comment.
You can’t perform that action at this time.