diff mbox

[pacman-dev] makepkg: use the `declare` builtin when backing up variables to eval

Message ID 20180315005613.26775-1-eschwartz@archlinux.org
State Superseded, archived
Headers show

Commit Message

Eli Schwartz March 15, 2018, 12:56 a.m. UTC
Rather than manually crafting foo_backup in a loop and eval'ing them
with a complicated escape pattern, store every splitpkg_overrides
element into a single variable via the eval-friendly `declare` builtin.

An alternative to eval would be using `printf -v` but this does not work
for arrays.

This has the additional benefit of reducing the number of
variables/arrays floating around in the environment.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 scripts/makepkg.sh.in | 20 ++++----------------
 1 file changed, 4 insertions(+), 16 deletions(-)

Comments

Allan McRae March 15, 2018, 2:01 a.m. UTC | #1
On 15/03/18 10:56, Eli Schwartz wrote:
> Rather than manually crafting foo_backup in a loop and eval'ing them
> with a complicated escape pattern, store every splitpkg_overrides
> element into a single variable via the eval-friendly `declare` builtin.
> 
> An alternative to eval would be using `printf -v` but this does not work
> for arrays.
> 
> This has the additional benefit of reducing the number of
> variables/arrays floating around in the environment.
> 

Stop submitting patches without even basic testing.


==> Entering fakeroot environment...
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
pkgdesc: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
url: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
license: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
groups: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
backup: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
options: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
install: not found
/home/allan/arch/code/pacman/scripts/.lib/makepkg: line 1118: declare:
changelog: not found
diff mbox

Patch

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index f0703d41..d6cb00da 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1111,34 +1111,22 @@  check_build_status() {
 backup_package_variables() {
 	local var
 	for var in ${splitpkg_overrides[@]}; do
-		local indirect="${var}_backup"
-		eval "${indirect}=(\"\${$var[@]}\")"
-	done
-}
-
-restore_package_variables() {
-	local var
-	for var in ${splitpkg_overrides[@]}; do
-		local indirect="${var}_backup"
-		if [[ -n ${!indirect} ]]; then
-			eval "${var}=(\"\${$indirect[@]}\")"
-		else
-			unset ${var}
-		fi
+		declare -p $var || printf '%s\n'  "unset $var"
 	done
 }
 
 run_split_packaging() {
 	local pkgname_backup=("${pkgname[@]}")
+	local restore_package_variables
 	for pkgname in ${pkgname_backup[@]}; do
 		pkgdir="$pkgdirbase/$pkgname"
 		mkdir "$pkgdir"
-		backup_package_variables
+		restore_package_variables="$(backup_package_variables)"
 		run_package $pkgname
 		tidy_install
 		lint_package || exit $E_PACKAGE_FAILED
 		create_package
-		restore_package_variables
+		eval "$restore_package_variables"
 	done
 	pkgname=("${pkgname_backup[@]}")
 	create_debug_package