aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkitsunyan2018-04-07 20:55:21 +0000
committerkitsunyan2018-04-07 20:55:21 +0000
commit769413c9f01676658acd33fedd90c038335af835 (patch)
tree9ac42383440bc94f733390d7dd7c3e6cc82d59a3 /src
parentde68bfe8a9947f26140da91a6ce26f49e5165738 (diff)
Allow to specify pre-build command
Diffstat (limited to 'src')
-rw-r--r--src/config.nim6
-rw-r--r--src/feature/syncinstall.nim26
2 files changed, 27 insertions, 5 deletions
diff --git a/src/config.nim b/src/config.nim
index 629cdfa..25ab011 100644
--- a/src/config.nim
+++ b/src/config.nim
@@ -33,6 +33,7 @@ type
checkIgnored*: bool
printAurNotFound*: bool
viewNoDefault*: bool
+ preBuildCommand*: Option[string]
proc readConfigFile*(configFile: string):
(OrderedTable[string, ref Table[string, string]], bool) =
@@ -118,10 +119,11 @@ proc obtainConfig*(config: PacmanConfig): Config =
let checkIgnored = options.hasKey("CheckIgnored")
let printAurNotFound = options.hasKey("PrintAurNotFound")
let viewNoDefault = options.hasKey("ViewNoDefault")
+ let preBuildCommand = options.opt("PreBuildCommand")
Config(root: root, db: db, tmpRoot: tmpRoot, color: color,
dbs: config.dbs, arch: config.arch, debug: config.debug, progressBar: config.progressBar,
verbosePkgList: config.verbosePkgList, pgpKeyserver: config.pgpKeyserver,
ignorePkgs: config.ignorePkgs, ignoreGroups: config.ignoreGroups,
- aurComments: aurComments, checkIgnored: checkIgnored,
- printAurNotFound: printAurNotFound, viewNoDefault: viewNoDefault)
+ aurComments: aurComments, checkIgnored: checkIgnored, printAurNotFound: printAurNotFound,
+ viewNoDefault: viewNoDefault, preBuildCommand: preBuildCommand)
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index c7f9fbc..5c511df 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -375,6 +375,8 @@ proc buildLoop(config: Config, pkgInfos: seq[PackageInfo], noconfirm: bool,
proc buildFromSources(config: Config, commonArgs: seq[Argument],
pkgInfos: seq[PackageInfo], noconfirm: bool): (Option[BuildResult], int) =
let base = pkgInfos[0].base
+ let repoPath = repoPath(config.tmpRoot, base)
+ let gitPath = pkgInfos[0].gitPath
let (cloneCode, cloneErrorMessage) = cloneRepo(config, pkgInfos)
if cloneCode != 0:
@@ -384,8 +386,7 @@ proc buildFromSources(config: Config, commonArgs: seq[Argument],
else:
proc loop(noextract: bool, showEditLoop: bool): (Option[BuildResult], int) =
let res = if showEditLoop:
- editLoop(config, base, repoPath(config.tmpRoot, base), pkgInfos[0].gitPath,
- false, noconfirm)
+ editLoop(config, base, repoPath, gitPath, false, noconfirm)
else:
'n'
@@ -416,7 +417,26 @@ proc buildFromSources(config: Config, commonArgs: seq[Argument],
else:
(buildResult, code)
- loop(false, false)
+ let preBuildCode = if config.preBuildCommand.isSome: (block:
+ printColon(config.color, tr"Running pre-build command...")
+
+ let code = forkWait(() => (block:
+ discard chdir(buildPath(repoPath, gitPath))
+ execResult(bashCmd, "-c", config.preBuildCommand.unsafeGet)))
+
+ if code != 0 and printColonUserChoice(config.color,
+ tr"Command failed, continue?", ['y', 'n'], 'n', 'n',
+ noconfirm, 'n') == 'y':
+ 0
+ else:
+ code)
+ else:
+ 0
+
+ if preBuildCode != 0:
+ (none(BuildResult), preBuildCode)
+ else:
+ loop(false, false)
proc installGroupFromSources(config: Config, commonArgs: seq[Argument],
basePackages: seq[seq[PackageInfo]], explicits: HashSet[string], noconfirm: bool): int =