Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Heusel <christian@heusel.eu>2024-01-05 17:43:34 +0100
committerChristian Heusel <christian@heusel.eu>2024-01-21 23:28:28 +0100
commitdb8c157eeaac98d23247dac1236642c79a1d257f (patch)
treedfbc9f0c3f92cdccf67511c4acce38bf52a822ba
parent343a2b5d4c564593402158d2e4dd35dedaf5599f (diff)
chore(build): factor out functions to modify PKGBUILDs
Component: pkgctl build Signed-off-by: Christian Heusel <christian@heusel.eu>
-rw-r--r--src/lib/build/build.sh12
-rw-r--r--src/lib/util/pkgbuild.sh43
2 files changed, 47 insertions, 8 deletions
diff --git a/src/lib/build/build.sh b/src/lib/build/build.sh
index 5276653..712be22 100644
--- a/src/lib/build/build.sh
+++ b/src/lib/build/build.sh
@@ -18,6 +18,8 @@ source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/git.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/srcinfo.sh
# shellcheck source=src/lib/util/pacman.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pacman.sh
+# shellcheck source=src/lib/util/pkgbuild.sh
+source "${_DEVTOOLS_LIBRARY_DIR}"/lib/util/pkgbuild.sh
# shellcheck source=src/lib/valid-repos.sh
source "${_DEVTOOLS_LIBRARY_DIR}"/lib/valid-repos.sh
# shellcheck source=src/lib/valid-tags.sh
@@ -374,20 +376,14 @@ pkgctl_build() {
# update pkgver
if [[ -n ${PKGVER} ]]; then
- if [[ $(type -t pkgver) == function ]]; then
- # TODO: check if die or warn, if we provide _commit _gitcommit setter maybe?
- warning 'setting pkgver variable has no effect if the PKGBUILD has a pkgver() function'
- fi
msg "Bumping pkgver to ${PKGVER}"
- grep --extended-regexp --quiet --max-count=1 "^pkgver=${pkgver}$" PKGBUILD || die "Non-standard pkgver declaration"
- sed --regexp-extended "s|^(pkgver=)${pkgver}$|\1${PKGVER}|g" -i PKGBUILD
+ pkgbuild_set_pkgver "${PKGVER}"
fi
# update pkgrel
if [[ -n ${PKGREL} ]]; then
msg "Bumping pkgrel to ${PKGREL}"
- grep --extended-regexp --quiet --max-count=1 "^pkgrel=${pkgrel}$" PKGBUILD || die "Non-standard pkgrel declaration"
- sed --regexp-extended "s|^(pkgrel=)${pkgrel}$|\1${PKGREL}|g" -i PKGBUILD
+ pkgbuild_set_pkgrel "${PKGREL}"
fi
# edit PKGBUILD
diff --git a/src/lib/util/pkgbuild.sh b/src/lib/util/pkgbuild.sh
new file mode 100644
index 0000000..ebf8e5f
--- /dev/null
+++ b/src/lib/util/pkgbuild.sh
@@ -0,0 +1,43 @@
+#!/hint/bash
+#
+# SPDX-License-Identifier: GPL-3.0-or-later
+
+[[ -z ${DEVTOOLS_INCLUDE_UTIL_PKGBUILD_SH:-} ]] || return 0
+DEVTOOLS_INCLUDE_UTIL_PKGBUILD_SH=1
+
+_DEVTOOLS_LIBRARY_DIR=${_DEVTOOLS_LIBRARY_DIR:-@pkgdatadir@}
+
+source /usr/share/makepkg/util/message.sh
+
+set -e
+
+
+# set the pkgver variable in a PKGBUILD
+# assumes that the pkgbuild is sourced to detect the presence of a pkgver function
+pkgbuild_set_pkgver() {
+ local new_pkgver=$1
+ local pkgver=${pkgver}
+
+ if [[ $(type -t pkgver) == function ]]; then
+ # TODO: check if die or warn, if we provide _commit _gitcommit setter maybe?
+ warning 'setting pkgver variable has no effect if the PKGBUILD has a pkgver() function'
+ fi
+
+ if ! grep --extended-regexp --quiet --max-count=1 "^pkgver=${pkgver}$" PKGBUILD; then
+ die "Non-standard pkgver declaration"
+ fi
+ sed --regexp-extended "s|^(pkgver=)${pkgver}$|\1${new_pkgver}|g" --in-place PKGBUILD
+}
+
+# set the pkgrel variable in a PKGBUILD
+# assumes that the pkgbuild is sourced so pkgrel is present
+pkgbuild_set_pkgrel() {
+ local new_pkgrel=$1
+ local pkgrel=${pkgrel}
+
+ if ! grep --extended-regexp --quiet --max-count=1 "^pkgrel=${pkgrel}$" PKGBUILD; then
+ die "Non-standard pkgrel declaration"
+ fi
+ sed --regexp-extended "s|^(pkgrel=)${pkgrel}$|\1${new_pkgrel}|g" --in-place PKGBUILD
+}
+