[pacman-dev] [PATCH v5 2/2] makepkg: also move restore_envvars handling into libmakepkg
Eli Schwartz
eschwartz at archlinux.org
Wed May 22 14:44:27 UTC 2019
Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
---
v5: prioritize $1 over $MAKEPKG_CONF in the public API.
scripts/libmakepkg/util/config.sh.in | 20 ++++++++++++++++++++
scripts/makepkg.sh.in | 7 +------
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/scripts/libmakepkg/util/config.sh.in b/scripts/libmakepkg/util/config.sh.in
index 9201bc01..4c7d39b7 100644
--- a/scripts/libmakepkg/util/config.sh.in
+++ b/scripts/libmakepkg/util/config.sh.in
@@ -54,3 +54,23 @@ source_makepkg_config() {
fi
fi
}
+
+# load makepkg.conf by sourcing the configuration files, and preserving
+# existing environment settings
+load_makepkg_config() {
+ # $1: override system config file
+
+ local MAKEPKG_CONF=${1:-${MAKEPKG_CONF:- at sysconfdir@/makepkg.conf}}
+
+ # preserve environment variables to override makepkg.conf
+ local restore_envvars=$(
+ for var in PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR PKGEXT SRCEXT GPGKEY PACKAGER CARCH; do
+ # declare -p does not work inside a function due to being marked as local
+ [[ -v $var ]] && printf '%s=%s\n' "$var" "${!var at Q}"
+ done
+ )
+
+ source_makepkg_config "$MAKEPKG_CONF"
+
+ eval "$restore_envvars"
+}
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 59a738a0..dcd6b4b3 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1098,12 +1098,7 @@ done
trap 'trap_exit INT "$(gettext "Aborted by user! Exiting...")"' INT
trap 'trap_exit USR1 "$(gettext "An unknown error has occurred. Exiting...")"' ERR
-# preserve environment variables to override makepkg.conf
-restore_envvars=$(declare -p PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR PKGEXT SRCEXT GPGKEY PACKAGER CARCH 2>/dev/null || true)
-
-source_makepkg_config
-
-eval "$restore_envvars"
+load_makepkg_config
# override settings from extra variables on commandline, if any
if (( ${#extra_environment[*]} )); then
--
2.21.0
More information about the pacman-dev
mailing list