From ec11f495cd058cfb1474859f54ab0720ecada004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Fri, 22 Mar 2024 21:36:53 +0200 Subject: [PATCH] abuild: add an option to keep all directories This is mainly needed for alpine-baselayout which creates all directories, and most of them are empty. The code in question would remove directories we explicitly want alpine-baselayout to create and own. --- abuild.in | 14 ++++++++------ tests/abuild_test | 27 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/abuild.in b/abuild.in index 0fc699e..6219d9f 100644 --- a/abuild.in +++ b/abuild.in @@ -1788,12 +1788,14 @@ human_size() { create_apks() { local file= dir= name= ver= apk= datadir= size= local gzip=$(command -v pigz || echo gzip) - rmdir "$pkgdir"/usr/lib \ - "$pkgdir"/usr/bin \ - "$pkgdir"/usr/share \ - "$pkgdir"/usr \ - "$pkgdir"/etc/ \ - 2>/dev/null || : + if ! options_has "keepdirs"; then + rmdir "$pkgdir"/usr/lib \ + "$pkgdir"/usr/bin \ + "$pkgdir"/usr/share \ + "$pkgdir"/usr \ + "$pkgdir"/etc/ \ + 2>/dev/null || : + fi if ! options_has "!tracedeps"; then for file in "$pkgbasedir"/.control.*/.PKGINFO; do dir="${file%/.PKGINFO}" diff --git a/tests/abuild_test b/tests/abuild_test index 58ec1a3..890ed8b 100755 --- a/tests/abuild_test +++ b/tests/abuild_test @@ -32,6 +32,7 @@ init_tests \ abuild_git_ceiling \ abuild_package_size_zero \ abuild_package_size_nonzero \ + abuild_keepdirs \ abuild_amove \ abuild_doc \ abuild_dev \ @@ -619,6 +620,32 @@ abuild_package_size_nonzero_body() { cat pkg/.control.test-size/.PKGINFO } +abuild_keepdirs_body() { + init_keys + mkdir -p test-amove + + cd test-amove + cat > APKBUILD <<-EOF + # Maintainer: Test User 123 <123@example.com> + + # test package + pkgname="test-keepdirs" + pkgver="1.0" + pkgrel=0 + pkgdesc='Dummy test package - keepdirs' + url='https://gitlab.alpinelinux.org/alpine/aports' + arch='noarch' + license='MIT' + options='keepdirs' + + package() { + mkdir -p "\$pkgdir"/usr/bin + } + EOF + abuild rootpkg || atf_fail "abuild rootpkg failed" + test -d pkg/test-keepdirs/usr/bin || atf_fail "$i failed" +} + abuild_amove_body() { init_keys mkdir -p test-amove