[pacman-dev] [PATCH 1/2] makepkg: move config loading into libmakepkg
Signed-off-by: Eli Schwartz
Signed-off-by: Eli Schwartz
On Tue, Apr 16, 2019 at 12:22:38PM -0400, Eli Schwartz wrote:
Signed-off-by: Eli Schwartz
--- scripts/libmakepkg/util/config.sh.in | 20 ++++++++++++++++++++ scripts/makepkg.sh.in | 6 +----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/libmakepkg/util/config.sh.in b/scripts/libmakepkg/util/config.sh.in index fdfeef89..2a6a0ae3 100644 --- a/scripts/libmakepkg/util/config.sh.in +++ b/scripts/libmakepkg/util/config.sh.in @@ -53,3 +53,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:-@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@Q}"
Shouldn't this be "${!var@Q}"?
+ done + ) + + source_makepkg_config "$MAKEPKG_CONF" + + eval "$restore_envvars" +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 08ec2a15..7a65d0f2 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1098,15 +1098,11 @@ 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)
# default config is makepkg.conf MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
-source_makepkg_config "$MAKEPKG_CONF" - -eval "$restore_envvars" +load_makepkg_config "$MAKEPKG_CONF"
# override settings from extra variables on commandline, if any if (( ${#extra_environment[*]} )); then -- 2.21.0
On 4/16/19 12:59 PM, Dave Reisner wrote:
On Tue, Apr 16, 2019 at 12:22:38PM -0400, Eli Schwartz wrote:
Signed-off-by: Eli Schwartz
--- scripts/libmakepkg/util/config.sh.in | 20 ++++++++++++++++++++ scripts/makepkg.sh.in | 6 +----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/scripts/libmakepkg/util/config.sh.in b/scripts/libmakepkg/util/config.sh.in index fdfeef89..2a6a0ae3 100644 --- a/scripts/libmakepkg/util/config.sh.in +++ b/scripts/libmakepkg/util/config.sh.in @@ -53,3 +53,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:-@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@Q}"
Shouldn't this be "${!var@Q}"?
Oops, will fix.
+ done + ) + + source_makepkg_config "$MAKEPKG_CONF" + + eval "$restore_envvars" +} diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 08ec2a15..7a65d0f2 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1098,15 +1098,11 @@ 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)
# default config is makepkg.conf MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
-source_makepkg_config "$MAKEPKG_CONF" - -eval "$restore_envvars" +load_makepkg_config "$MAKEPKG_CONF"
# override settings from extra variables on commandline, if any if (( ${#extra_environment[*]} )); then -- 2.21.0
-- Eli Schwartz Bug Wrangler and Trusted User
Signed-off-by: Eli Schwartz
Signed-off-by: Eli Schwartz
On 17/4/19 3:17 am, Eli Schwartz wrote:
Signed-off-by: Eli Schwartz
---
Comments from v1 indicate this will be useful for (e.g.) devtools to read a makepkg.conf. But devtools uses a custom makepkg.conf plus info from a users ~/.makepkg.conf. This patch will allow reading the custom makepkg.conf, but as it is not the system makepkg.conf it would then not parse the ~/. one. So does this patch achieve its purpose?
v2: fix a missing dependency, rebase on top of https://patchwork.archlinux.org/patch/1074/ because util.sh had a missing dependency
<snip>
merge_arch_attrs() { local attr supported_attrs=( provides conflicts depends replaces optdepends @@ -1113,25 +1104,7 @@ restore_envvars=$(declare -p PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR PKGEXT # default config is makepkg.conf MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
This is not needed any more. The logic is handled in the source_makepkg_conf() function. The MAKEPKG_CONF variable is not used elsewhere.
-# Source the config file; fail if it is not found -if [[ -r $MAKEPKG_CONF ]]; then - source_safe "$MAKEPKG_CONF" -else - error "$(gettext "%s not found.")" "$MAKEPKG_CONF" - plain "$(gettext "Aborting...")" - exit $E_CONFIG_ERROR -fi - -# Source user-specific makepkg.conf overrides, but only if no override config -# file was specified -XDG_PACMAN_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/pacman" -if [[ "$MAKEPKG_CONF" = "$confdir/makepkg.conf" ]]; then - if [[ -r "$XDG_PACMAN_DIR/makepkg.conf" ]]; then - source_safe "$XDG_PACMAN_DIR/makepkg.conf" - elif [[ -r "$HOME/.makepkg.conf" ]]; then - source_safe "$HOME/.makepkg.conf" - fi -fi +source_makepkg_config "$MAKEPKG_CONF"
eval "$restore_envvars"
On 17/4/19 3:17 am, Eli Schwartz wrote:
Signed-off-by: Eli Schwartz
--- Comments from v1 indicate this will be useful for (e.g.) devtools to read a makepkg.conf. But devtools uses a custom makepkg.conf plus info from a users ~/.makepkg.conf. This patch will allow reading the custom makepkg.conf, but as it is not the system makepkg.conf it would then not parse the ~/. one. So does this patch achieve its purpose? , In devtools, there is one "pristine" makepkg.conf used for configuring
On 5/8/19 1:08 AM, Allan McRae wrote: the chroot, but we also want to extract certain variables from "whatever plain old makepkg would see". MAKEFLAGS and PACKAGER as well as the *DEST settings. As per makepkg, these could be set in /etc/makepkg.conf or in ~/. -- so the objective would be to use this function and load the default /etc/makepkg.conf + user-specific ones, and then eventually echo "MAKEFLAGS='$MAKEFLAGS'" >> $chrootdir/etc/makepkg.conf It would also be useful in another script, to obtain the $PKGDEST -- the script will run makechrootpkg on a remote build server, then scp the files back to the local machine, and it would be nice to scp it into the same directory makepkg would have used if run locally. I expect there are other programs out there which also desire to do high-level things around makepkg, while still using makepkg's configuration directories. -- Eli Schwartz Bug Wrangler and Trusted User
Signed-off-by: Eli Schwartz
Signed-off-by: Eli Schwartz
When scripting/automating around makepkg, it is sometimes desirable to
know how makepkg will be configured to operate. One example is the
archlinux devtools, which must forward select makepkg.conf variables
into a build chroot (for example PACKAGER) or use those variables itself
(for example {SRC,PKG,LOG}DEST).
The configuration file can be in up to 3 places, and should be capable
of being overridden via environment variables. It is sufficiently
complex to represent distinct functionality, and sufficiently useful to
merit easy accessibility in other scripts, therefore, let us move it
into a publicly exposed utility library.
Signed-off-by: Eli Schwartz
Signed-off-by: Eli Schwartz
When scripting/automating around makepkg, it is sometimes desirable to
know how makepkg will be configured to operate. One example is the
archlinux devtools, which must forward select makepkg.conf variables
into a build chroot (for example PACKAGER) or use those variables itself
(for example {SRC,PKG,LOG}DEST).
The configuration file can be in up to 3 places, and should be capable
of being overridden via environment variables. It is sufficiently
complex to represent distinct functionality, and sufficiently useful to
merit easy accessibility in other scripts, therefore, let us move it
into a publicly exposed utility library.
Signed-off-by: Eli Schwartz
Signed-off-by: Eli Schwartz
On 23/5/19 12:44 am, Eli Schwartz wrote:
When scripting/automating around makepkg, it is sometimes desirable to know how makepkg will be configured to operate. One example is the archlinux devtools, which must forward select makepkg.conf variables into a build chroot (for example PACKAGER) or use those variables itself (for example {SRC,PKG,LOG}DEST).
The configuration file can be in up to 3 places, and should be capable of being overridden via environment variables. It is sufficiently complex to represent distinct functionality, and sufficiently useful to merit easy accessibility in other scripts, therefore, let us move it into a publicly exposed utility library.
Signed-off-by: Eli Schwartz
---
Good. A
participants (3)
-
Allan McRae
-
Dave Reisner
-
Eli Schwartz