abuild: parse $ORIGIN in rpaths correctly

This commit is contained in:
Sertonix 2024-10-24 20:00:29 +02:00 committed by Natanael Copa
parent b274749838
commit 5ad0236004
2 changed files with 61 additions and 4 deletions

View File

@ -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

View File

@ -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 <ncopa@alpinelinux.org>"
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