From eee6b50aa57fae7e6b12f1da3ef7356d335a20c8 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 27 Sep 2021 20:03:54 +0200 Subject: [PATCH 1/5] *: Do not use RETURN traps It has some weird semantics that seem to trip us up after updating bash to 5.1. We tried to use it inside functions to clean up some stuff after function returns. This can be emulated with an EXIT trap within a subshell. Fortunately all the users of the RETURN trap were not setting any global variables - modifications of such variables are local to the subshell and are lost when the subshell exits. --- build_library/release_util.sh | 6 +++++- build_torcx_store | 8 +++++--- jenkins/images.sh | 6 +++++- jenkins/packages.sh | 6 +++++- jenkins/vms.sh | 6 +++++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/build_library/release_util.sh b/build_library/release_util.sh index 7b20d383df..db2e33b220 100644 --- a/build_library/release_util.sh +++ b/build_library/release_util.sh @@ -124,13 +124,16 @@ sign_and_upload_files() { local suffix="$3" shift 3 + # run a subshell to possibly clean the temporary directory with + # signatures without clobbering the global EXIT trap + ( # Create simple GPG detached signature for all uploads. local sigs=() if [[ -n "${FLAGS_sign}" ]]; then local file local sigfile local sigdir=$(mktemp --directory) - trap "rm -rf ${sigdir}" RETURN + trap "rm -rf ${sigdir}" EXIT for file in "$@"; do if [[ "${file}" =~ \.(asc|gpg|sig)$ ]]; then continue @@ -150,6 +153,7 @@ sign_and_upload_files() { fi upload_files "${msg}" "${path}" "${suffix}" "$@" "${sigs[@]}" + ) } upload_packages() { diff --git a/build_torcx_store b/build_torcx_store index 524f69b42a..5572c7d5b0 100755 --- a/build_torcx_store +++ b/build_torcx_store @@ -114,13 +114,16 @@ function torcx_package() { local name=${name##*/} local version=${version%%-r*} + # Run in a subshell to clean tmproot and tmppkgroot up without + # clobbering this shell's EXIT trap. + ( # Set up the base package layout to dump everything into /bin and /lib. # tmproot is what the packages are installed into. # A subset of the files from tmproot are then moved into tmppkgroot, # which is then archived and uploaded. tmproot=$(sudo mktemp --tmpdir="${BUILD_DIR}" -d) tmppkgroot=$(sudo mktemp --tmpdir="${BUILD_DIR}" -d) - trap "sudo rm -rf '${tmproot}' '${tmppkgroot}'" EXIT RETURN + trap "sudo rm -rf '${tmproot}' '${tmppkgroot}'" EXIT sudo chmod 0755 "${tmproot}" "${tmppkgroot}" sudo mkdir -p "${tmproot}"/{.torcx,bin,lib,usr} sudo ln -fns ../bin "${tmproot}/usr/bin" @@ -228,8 +231,7 @@ function torcx_package() { "${source_pkg}" \ "${update_default}" \ "${pkg_locations[@]}" - - trap - EXIT + ) } # This list defines every torcx image that goes into the vendor store for the diff --git a/jenkins/images.sh b/jenkins/images.sh index 9a688d953b..faced8cd66 100755 --- a/jenkins/images.sh +++ b/jenkins/images.sh @@ -43,7 +43,10 @@ sudo rm -rf chroot/build src/build torcx enter() { local verify_key= - trap 'sudo rm -f chroot/etc/portage/gangue.*' RETURN + # Run in a subshell to clean some gangue files on exit without + # possibly clobbering the global EXIT trap. + ( + trap 'sudo rm -f chroot/etc/portage/gangue.*' EXIT [ -s verify.asc ] && sudo ln -f verify.asc chroot/etc/portage/gangue.asc && verify_key=--verify-key=/etc/portage/gangue.asc @@ -55,6 +58,7 @@ enter() { --json-key=/etc/portage/gangue.json $verify_key \ "'"${URI}" "${DISTDIR}/${FILE}"' \ "$@" + ) } script() { diff --git a/jenkins/packages.sh b/jenkins/packages.sh index 8704929b55..670f83aa0b 100755 --- a/jenkins/packages.sh +++ b/jenkins/packages.sh @@ -47,7 +47,10 @@ bin/cork update \ enter() { local verify_key= - trap 'sudo rm -f chroot/etc/portage/gangue.*' RETURN + # Run in a subshell to clean some gangue files on exit without + # possibly clobbering the global EXIT trap. + ( + trap 'sudo rm -f chroot/etc/portage/gangue.*' EXIT [ -s verify.asc ] && sudo ln -f verify.asc chroot/etc/portage/gangue.asc && verify_key=--verify-key=/etc/portage/gangue.asc @@ -60,6 +63,7 @@ enter() { --json-key=/etc/portage/gangue.json $verify_key \ "'"${URI}" "${DISTDIR}/${FILE}"' \ "$@" + ) } script() { diff --git a/jenkins/vms.sh b/jenkins/vms.sh index eee3d719bf..4222b57d86 100755 --- a/jenkins/vms.sh +++ b/jenkins/vms.sh @@ -43,7 +43,10 @@ sudo rm -rf chroot/build tmp enter() { local verify_key= - trap 'sudo rm -f chroot/etc/portage/gangue.*' RETURN + # Run in a subshell to clean some gangue files on exit without + # possibly clobbering the global EXIT trap. + ( + trap 'sudo rm -f chroot/etc/portage/gangue.*' EXIT [ -s verify.asc ] && sudo ln -f verify.asc chroot/etc/portage/gangue.asc && verify_key=--verify-key=/etc/portage/gangue.asc @@ -55,6 +58,7 @@ enter() { --json-key=/etc/portage/gangue.json $verify_key \ "'"${URI}" "${DISTDIR}/${FILE}"' \ "$@" + ) } script() { From 69d0f05b44a000ef71595e27e4813030cdcb0a54 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 27 Sep 2021 20:08:20 +0200 Subject: [PATCH 2/5] build_torcx_store: Make a variable local --- build_torcx_store | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_torcx_store b/build_torcx_store index 5572c7d5b0..4e190c1fc5 100755 --- a/build_torcx_store +++ b/build_torcx_store @@ -108,7 +108,7 @@ function torcx_package() { local version=${pkg:${#name}+1} local manifest_path="${2}" local type="${3}" - local deppkg digest file rpath sha512sum source_pkg rdepends tmproot tmppkgroot update_default + local deppkg digest file rpath sha512sum source_pkg rdepends tmproot tmppkgroot update_default tmpfile local pkg_cas_file pkg_cas_root local pkg_locations=() local name=${name##*/} From b797cdb723c6ba9ce39c6a39fcc88c64f6fc5706 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Mon, 27 Sep 2021 20:15:48 +0200 Subject: [PATCH 3/5] build_torcx_store: Fix pipeline error handling --- build_torcx_store | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build_torcx_store b/build_torcx_store index 4e190c1fc5..61f59eabbc 100755 --- a/build_torcx_store +++ b/build_torcx_store @@ -178,10 +178,11 @@ function torcx_package() { find -H "${tmproot}"/{bin,lib} -type f | while read file do + ( rpath=$(sudo patchelf --print-rpath "${file}" 2>/dev/null) && test "${rpath#/ORIGIN/}" != "${rpath}" && sudo patchelf --set-rpath "${rpath/#?/\$}" "${file}" - : # Set $? to 0 or the pipeline fails and -e quits. + ) || : # Set $? to 0 or the pipeline fails and -e quits. done # Move anything we plan to package to its root. From d801ecccdff0a1c42aaedfa44389b11ad9e56dc5 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 28 Sep 2021 16:31:46 +0200 Subject: [PATCH 4/5] build_library/board_options: Fix pkg_version function The documentation says it always returns zero, which is not true - portageq could return a non-zero return value and that would be the return value of the function. Fix the function to actually follow the documentation - apparently the function should just return an empty string in case of failure (like package not found). --- build_library/board_options.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_library/board_options.sh b/build_library/board_options.sh index e2280ccad1..c454b47bcc 100644 --- a/build_library/board_options.sh +++ b/build_library/board_options.sh @@ -29,7 +29,7 @@ pkg_use_enabled() { # Prints: some-pkg/name-1.2.3 # Note: returns 0 even if the package was not found. pkg_version() { - portageq-"${BOARD}" best_visible "${BOARD_ROOT}" "$1" "$2" + portageq-"${BOARD}" best_visible "${BOARD_ROOT}" "$1" "$2" || : } # Usage: pkg_provides [installed|binary] some-pkg/name-1.2.3 From caa74dfaf8b42541fd1232e9cac0d9974fce7d93 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 28 Sep 2021 16:35:18 +0200 Subject: [PATCH 5/5] common: Do not warn on listing the nonexistent files The subshell was printing the error backtrace, but apparently it was of no consequences. Just assume that listing may fail, so we don't get any confusing backtraces. --- common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common.sh b/common.sh index 6f6aa00435..f194361fff 100644 --- a/common.sh +++ b/common.sh @@ -979,8 +979,8 @@ fixup_liblto_softlinks() { local link local target # check both native (/usr/CHOST/) as well as cross compile (/usr/CHOST/CTARGET) paths - { ls -l "${root}/"usr/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so 2>/dev/null; - ls -l "${root}/"usr/*/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so 2>/dev/null; } \ + { ls -l "${root}/"usr/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so 2>/dev/null || :; + ls -l "${root}/"usr/*/*/binutils-bin/lib/bfd-plugins/liblto_plugin.so 2>/dev/null || :; } \ | sed 's:.* \([^[:space:]]\+\) -> \([^[:space:]]\+\):\1 \2:' \ | while read link target; do local newtarget=$(echo "$target" | sed "s:${root}:/:")