aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/pakku.conf.5.txt4
-rw-r--r--pakku.conf2
-rw-r--r--src/config.nim6
-rw-r--r--src/feature/syncinstall.nim26
4 files changed, 33 insertions, 5 deletions
diff --git a/doc/pakku.conf.5.txt b/doc/pakku.conf.5.txt
index 5ea2460..5eda994 100644
--- a/doc/pakku.conf.5.txt
+++ b/doc/pakku.conf.5.txt
@@ -36,6 +36,10 @@ Options
content of PKGBUILD and other files. Pressing enter key will give the
positive answer unless this option is specified.
+*PreBuildCommand =* command::
+ This command will be executed in package directory before building,
+ allowing you to modify PKGBUILD or perform other necessary actions.
+
See Also
--------
linkman:pacman.conf[5], linkman:pakku[8]
diff --git a/pakku.conf b/pakku.conf
index 0b7e200..8014338 100644
--- a/pakku.conf
+++ b/pakku.conf
@@ -7,3 +7,5 @@ AurComments
CheckIgnored
PrintAurNotFound
#ViewNoDefault
+
+#PreBuildCommand =
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 =