abuild: default_dbg: various fixes

- fix symlinks
- fix hard links
- fix dbg not first
- fix scan race condition
- fix (non-extended) attrs
- general refactoring
This commit is contained in:
Alex Xu (Hello71) 2020-07-02 12:47:29 -04:00 committed by Kevin Daudt
parent 02652f5dd6
commit 3ad93d9a83
3 changed files with 39 additions and 41 deletions

View File

@ -210,14 +210,6 @@ default_sanitycheck() {
esac
done
# check that -dbg comes first
if subpackages_has "$pkgname-dbg"; then
set -- $subpackages
if [ "$1" != "$pkgname-dbg" ]; then
warning "$pkgname-dbg should be first in subpackages"
fi
fi
for i in $install; do
local n=${i%.*}
local suff=${i##*.}
@ -1898,23 +1890,27 @@ default_dbg() {
local f
pkgdesc="$pkgdesc (debug symbols)"
scanelf -R "$pkgdir" | grep ET_DYN | sed "s:$pkgdir\/::g" | sed "s:ET_DYN ::g" | while read f; do
local ddbg_srcdir=$(dirname "$pkgdir/$f")
local ddbg_srcfile=$(basename "$pkgdir/$f")
local ddbg_dstdir=$(dirname "$subpkgdir/usr/lib/debug/$f.debug")
local ddbg_dstfile=$(basename "$subpkgdir/usr/lib/debug/$f.debug")
mkdir -p "$ddbg_dstdir"
cd "$ddbg_srcdir"
local xattr=$(getfattr --match="" --dump "${ddbg_srcfile}")
${CROSS_COMPILE}objcopy --only-keep-debug "$ddbg_srcfile" "$ddbg_dstfile"
${CROSS_COMPILE}objcopy --add-gnu-debuglink="$ddbg_dstfile" "$ddbg_srcdir/$ddbg_srcfile"
mv "$ddbg_dstfile" "$ddbg_dstdir"
${CROSS_COMPILE}strip "$ddbg_srcfile"
if [ -n "$xattr" ]; then
echo "$xattr" | "$SETFATTR" --restore=-
# assume $pkgbasedir is all one filesystem
mkdir "$pkgbasedir/.dbg-tmp"
# note: the subpkgdir doesn't exist when the glob is evaluated
scanelf -Ry "$pkgbasedir"/* | while read type src; do
if [ "$type" != ET_DYN ]; then
continue
fi
local dst=$subpkgdir/usr/lib/debug/${src#"$pkgbasedir"/*/}.debug
mkdir -p "${dst%/*}"
local ino=$(stat -c %i "$src")
if ! [ -e "$pkgbasedir/.dbg-tmp/$ino" ]; then
local tmp=$pkgbasedir/.dbg-tmp/${src##*/}
${CROSS_COMPILE}objcopy --only-keep-debug "$src" "$dst"
${CROSS_COMPILE}objcopy --add-gnu-debuglink="$dst" --strip-unneeded -R .comment "$src" "$tmp"
# preserve attributes, links
cat "$tmp" > "$src"
rm "$tmp"
ln "$dst" "$pkgbasedir/.dbg-tmp/$ino"
fi
done
rm -r "$pkgbasedir/.dbg-tmp"
return 0
}

View File

@ -63,7 +63,25 @@ teardown() {
@test "abuild: test -dbg subpackage" {
cd testrepo/dbgpkg
arch=$($ABUILD -A)
$ABUILD
mkdir "$tmpdir/dbgpkg-1.0-r0"
cd "$tmpdir/dbgpkg-1.0-r0"
tar -xf "$REPODEST"/testrepo/$arch/dbgpkg-1.0-r0.apk
! [ -e usr/lib/debug ]
debuginfo=$(readelf -wk usr/bin/hello | grep '^ Separate debug info file: [^/]*\.debug$')
debuginfo_file=${debuginfo#" Separate debug info file: "}
[ "$(nm usr/bin/hello 2>&1)" = "nm: usr/bin/hello: no symbols" ]
[ usr/bin/hello -ef usr/bin/hello-hard ]
mkdir "$tmpdir/dbgpkg-dbg-1.0-r0"
cd "$tmpdir/dbgpkg-dbg-1.0-r0"
tar -xf "$REPODEST"/testrepo/$arch/dbgpkg-dbg-1.0-r0.apk
! [ -e usr/bin ]
[ -n "$(nm usr/lib/debug/usr/bin/$debuginfo_file)" ]
! [ -e usr/lib/debug/usr/bin/hello-sym.debug ]
! [ -e usr/lib/debug/usr/bin/hello.debug ] || ! [ -e usr/lib/debug/usr/bin/hello-hard.debug ]
}
@test "abuild: test SETFATTR in -dbg subpackage" {
@ -122,24 +140,6 @@ teardown() {
[ $status -ne 0 ]
}
@test "abuild: test that -dbg should be first" {
mkdir -p "$tmpdir"/foo
cat > "$tmpdir"/foo/APKBUILD <<-EOF
# Maintainer: Test user <user@example.com>
pkgname="foo"
pkgver="1.0"
pkgrel=0
pkgdesc="dummy package for test"
url="https://alpinelinux.org"
license="MIT"
subpackages="\$pkgname-dev \$pkgname-dbg"
package() { :; }
EOF
cd "$tmpdir"/foo
run $ABUILD sanitycheck
[[ $output[1] == *WARNING*dbg* ]]
}
@test "abuild: verify main package does not inherit subpackage dependencies" {
mkdir -p "$tmpdir"/testrepo/subpkg-dep-leak
cd "$tmpdir"/testrepo/subpkg-dep-leak

View File

@ -27,6 +27,8 @@ check() {
package() {
install -D -m755 hello "$pkgdir"/usr/bin/hello
ln "$pkgdir"/usr/bin/hello "$pkgdir"/usr/bin/hello-hard
ln -s "$pkgdir"/usr/bin/hello "$pkgdir"/usr/bin/hello-sym
}
sha512sums="