From 5ad0236004343a534b2591421bffb242b6ea16cc Mon Sep 17 00:00:00 2001 From: Sertonix Date: Thu, 24 Oct 2024 20:00:29 +0200 Subject: [PATCH] abuild: parse $ORIGIN in rpaths correctly --- abuild.in | 18 ++++++++++++++---- tests/abuild_test | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/abuild.in b/abuild.in index 2b87976..68c46e7 100644 --- a/abuild.in +++ b/abuild.in @@ -1244,15 +1244,25 @@ prepare_metafiles() { } prepare_trace_rpaths() { - local dir=${subpkgdir:-$pkgdir} local etype= soname= file= sover= [ "${subpkgarch:-$pkgarch}" = "noarch" ] && return 0 options_has "!tracedeps" && return 0 # lets tell all the places we should look for .so files - all rpaths - scanelf --quiet --recursive --rpath "$dir" \ - | sed -e 's/[[:space:]].*//' -e 's/:/\n/' | sort -u \ - >"$controldir"/.rpaths + ( + cd "${subpkgdir:-$pkgdir}" + scanelf --quiet --recursive --rpath . + ) | awk -F '[:[:space:]]+' '{ + sub(/^\./, "", $NF); + sub("/[^/]*$", "", $NF); + for (i = 1; i < NF; i++) { + # $ORIGIN means relative to the binary + gsub("\\$ORIGIN", $NF, $i); + gsub("\\${ORIGIN}", $NF, $i); + printf("%s\n", $i); + } + }' | sort -u >"$controldir"/.rpaths if grep -q -x '/usr/lib' "$controldir"/.rpaths; then + # FIXME silence warning when $ORIGIN was used warning "Redundant /usr/lib in rpath found" fi if grep '^/home/' "$controldir"/.rpaths; then diff --git a/tests/abuild_test b/tests/abuild_test index e87c65a..6c315b3 100755 --- a/tests/abuild_test +++ b/tests/abuild_test @@ -18,6 +18,7 @@ init_tests \ abuild_py_providers_creation \ abuild_py_dependency_scan \ abuild_py_dependency_scan_conflict \ + abuild_rpaths \ abuild_reject_init_with_improper_shebang \ abuild_valid_pkgnames \ abuild_invalid_pkgnames \ @@ -394,6 +395,52 @@ abuild_py_dependency_scan_conflict_body() { abuild rootpkg } +abuild_rpaths_body() { + init_keys + + mkdir -p bin + cat > bin/scanelf <<-EOF + #!/bin/sh + for i; do + [ "\$i" = --rpath ] || continue + echo "\$ABUILD_RPATH" /usr/lib/pkg/base.so + break + done + EOF + chmod +x bin/scanelf + PATH="$PWD/bin:$PATH" + + mkdir -p testrepo/pkg + cd testrepo/pkg + cat > APKBUILD <<-EOF + maintainer="Natanael Copa " + pkgname="pkg" + pkgver=1.0 + pkgrel=0 + pkgdesc="Dummy test package" + url="https://gitlab.alpinelinux.org/alpine/aports" + arch="all" + license="MIT" + options="!check !strip !textrels !archcheck" + + package() { + mkdir -p "\$pkgdir"/usr/lib + touch "\$pkgdir"/usr/lib/libfoo.so.1 + } + EOF + ABUILD_RPATH='/usr/lib/foo' abuild rootpkg || atf_fail "abuild failed" + atf_check -s exit:0 \ + -o match:"/usr/lib/foo" \ + cat pkg/.control.pkg/.rpaths + ABUILD_RPATH='$ORIGIN/bar:${ORIGIN}/../baf' pkgbasedir=$PWD/pkg abuild rootpkg || atf_fail "abuild failed" + atf_check -s exit:0 \ + -o match:"/usr/lib/pkg/bar" \ + -o match:"/usr/lib/pkg/../baf" \ + cat pkg/.control.pkg/.rpaths + ABUILD_RPATH='/home/builder' atf_check -s exit:1 -o ignore \ + -e match:"ERROR:.*: Has /home/... in rpath" abuild rootpkg +} + abuild_reject_init_with_improper_shebang_body() { mkdir invalid-initd cd invalid-initd