diff options
-rwxr-xr-x | src/chroot-tools/libremakepkg | 12 | ||||
-rw-r--r-- | src/lib/conf.sh | 29 | ||||
-rw-r--r-- | src/lib/conf.sh.3.ronn | 34 | ||||
-rw-r--r-- | test/lib-conf-test.sh | 2 |
4 files changed, 36 insertions, 41 deletions
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg index f808070..fc6418c 100755 --- a/src/chroot-tools/libremakepkg +++ b/src/chroot-tools/libremakepkg @@ -219,12 +219,12 @@ main() { # Load makepkg configuration ########################################### # Note that all of these are globals - SRCDEST="$(get_conf_makepkg SRCDEST "$PWD")" - PKGDEST="$(get_conf_makepkg PKGDEST "$PWD")" - LOGDEST="$(get_conf_makepkg LOGDEST "$PWD")" + SRCDEST="$(get_var makepkg SRCDEST "$PWD")" + PKGDEST="$(get_var makepkg PKGDEST "$PWD")" + LOGDEST="$(get_var makepkg LOGDEST "$PWD")" mkdir -p "$SRCDEST" "$PKGDEST" "$LOGDEST" - MAKEFLAGS="$(get_conf_makepkg MAKEFLAGS '')" - PACKAGER="$(get_conf_makepkg PACKAGER '')" + MAKEFLAGS="$(get_var makepkg MAKEFLAGS '')" + PACKAGER="$(get_var makepkg PACKAGER '')" librechroot_flags=( -r "$PWD:/startdir_host" @@ -249,7 +249,7 @@ main() { # Set target CARCH # note that we waited until after locking/creating the chroot to do this - export CARCH="$(MAKEPKG_CONF=$copydir/etc/makepkg.conf get_conf_makepkg CARCH)" + export CARCH="$(MAKEPKG_CONF=$copydir/etc/makepkg.conf get_var makepkg CARCH)" # Pre-build msg 'Starting pre-build activities...' diff --git a/src/lib/conf.sh b/src/lib/conf.sh index c2904de..47a93c7 100644 --- a/src/lib/conf.sh +++ b/src/lib/conf.sh @@ -29,7 +29,7 @@ if [[ -z ${XDG_CACHE_HOME:-} ]]; then export XDG_CACHE_HOME="${LIBREHOME}/.cache" fi -# Generic functions ############################################################ +# Low-level generic functions ################################################## # Usage: list_files $slug # Lists the configuration files to be considered for $slug. @@ -77,6 +77,8 @@ list_envvars() { esac } +# High-level generic functions ################################################# + # Usage: load_files $slug # Loads the configuration files for $slug in the proper order. load_files() { @@ -130,24 +132,25 @@ check_vars() { fi } -# makepkg configuration ######################################################## - -# Usage: get_conf_makepkg <var_name> <default_value> +# Usage: get_var <slug> <var_name> <default_value> # Does not work with arrays -get_conf_makepkg() ( +get_var() ( set +euE - local setting=$1 - local default=$2 - load_files makepkg - printf '%s\n' "${!setting:-${default}}" + local slug=$1 + local setting=$2 + local default=$3 + load_files "$slug" + printf '%s' "${!setting:-${default}}" ) +# Usage: set_var <slug> <var_name> <value> # Does not work with arrays -set_conf_makepkg() { - local key=$1 - local val=$2 +set_var() { + local slug=$1 + local key=$2 + local val=$3 local file - for file in $(list_files makepkg|tac); do + for file in $(list_files "$slug"|tac); do if [[ -w $file ]]; then sed -i "/^\s*$key=/d" "$file" printf '%s=%q\n' "$key" "$val" >> "$file" diff --git a/src/lib/conf.sh.3.ronn b/src/lib/conf.sh.3.ronn index a2bc862..82f6eed 100644 --- a/src/lib/conf.sh.3.ronn +++ b/src/lib/conf.sh.3.ronn @@ -59,10 +59,20 @@ The routines you will likely actually use are: aren't, it prints a message to configure them in the configuration files for <SLUG>, and returns with a non-zero status. + * `get_var` <SLUG> <VAR> <DEFAULT>: + If <VAR> is set in the configuration for <SLUG>, print it's + value, considering environmental variables. If it is not set, + return <DEFAULT>. This does NOT work for array variables. + * `set_var` <SLUG> <VAR> <VALUE>: + Set the variable <VAR> equal to <VALUE> in the configuration file + for <SLUG> of highest precedence that already exists, and is + writable. If no files fit this description, the routine does + nothing and returns a non-zero exit status. This does NOT work + for array variables. -There are also two more routines that are used internally by -the above. You are unlikely to use them directly, but they might -be useful for debugging. +There are two more routines the above routines use internally that are +used internally by . You are unlikely to use them directly, but they +might be useful for debugging, or at least describing behavior. * `list_files` <SLUG>: Lists (newline-separated) the configuration files that must be @@ -75,24 +85,6 @@ be useful for debugging. <PACKAGER> environmental variable is set, the value in the configuration file is ignored. -### MAKEPKG.CONF ROUTINES - -These two routines exist to get and set individual variables in -`makepkg.conf`(). See the output of `list_files makepkg` for exactly -what set of files that refers to. - -These routines do NOT work with array settings. - - * `get_conf_makepkg` <VAR> <DEFAULT>: - If <VAR> is set, return it's value, considering environmental - variables. If it is not set, return <DEFAULT>. The printed - value is then trailed by a newline. - * `set_conf_makepkg` <VAR> <VALUE>: - Set the variable <VAR> equal to <VALUE> in the configuration file - of highest precedence that already exists, and is writable. If - no files fit this description, the routine does nothing and - returns a non-zero exit status. - ### PKGBUILD ROUTINES These two routines deal with loading `PKGBUILD`(5) files. diff --git a/test/lib-conf-test.sh b/test/lib-conf-test.sh index 0d028b8..efad907 100644 --- a/test/lib-conf-test.sh +++ b/test/lib-conf-test.sh @@ -16,7 +16,7 @@ it_sets_makepkg_vars_in_custom_file() { unset PKGDEST touch "$tmpdir/makepkg.conf" . $(librelib conf.sh) - MAKEPKG_CONF="$tmpdir/makepkg.conf" set_conf_makepkg PKGDEST /pkgdest + MAKEPKG_CONF="$tmpdir/makepkg.conf" set_var makepkg PKGDEST /pkgdest . "$tmpdir/makepkg.conf" [[ $PKGDEST == /pkgdest ]] } |