diff options
author | psykose <alice@ayaya.dev> | 2022-08-05 14:00:36 +0000 |
---|---|---|
committer | psykose <alice@ayaya.dev> | 2022-08-05 16:00:36 +0200 |
commit | 927f14f6b3253e8600de0bc64df63909cff078d1 (patch) | |
tree | 5d07b4491f2cb71a22ac0868cd768a33a1bb31a0 | |
parent | 3a235e4d3caf7446e7c316fadd6a3cded30d0407 (diff) |
abuild: fix package size for script-only packages
-rwxr-xr-x | abuild.in | 15 | ||||
-rwxr-xr-x | tests/abuild_test | 76 |
2 files changed, 84 insertions, 7 deletions
@@ -1075,12 +1075,15 @@ prepare_metafiles() { esac local size=$(du -sk | awk '{print $1 * 1024}') - # If package contains only empty files, the size might be 0. But due to - # apk-tools 2 considering packages with size = 0 virtual, nothing is - # extracted. That will be solved in apk-tools 3. As a workaround we can - # set the size to 1 if any files are present. - if [ "$size" -eq 0 ] && [ -n "$(find . ! -name .)" ]; then - size=1 + # If package contains only empty files (or only install scripts), the size + # might be 0. But due to apk-tools 2 considering packages with size = 0 + # virtual, nothing is extracted (and no scripts are ran). That will be + # solved in apk-tools 3. As a workaround we can set the size to 1 if any + # files are present or install scripts are defined. + if [ "$size" -eq 0 ]; then + if [ -n "$install" ] || [ -n "$(find . ! -name .)" ]; then + size=1 + fi fi if [ "$arch" != "$apkbuild_arch" ]; then diff --git a/tests/abuild_test b/tests/abuild_test index ee25f96..f127abf 100755 --- a/tests/abuild_test +++ b/tests/abuild_test @@ -22,7 +22,9 @@ init_tests \ abuild_invalid_subpkgnames \ abuild_invalid_subpkg_version \ abuild_multiline_license \ - abuild_git_ceiling + abuild_git_ceiling \ + abuild_package_size_zero \ + abuild_package_size_nonzero export ABUILD_SHAREDIR=$(atf_get_srcdir)/.. export ABUILD_CONF=/dev/null @@ -443,3 +445,75 @@ abuild_git_ceiling_body() { -e match:"ERROR: git-pkg: build failed" \ abuild } + + +create_fake_du() { + mkdir -p bin + cat > bin/du <<-EOF + #!/bin/sh + echo 0 + EOF + chmod +x bin/du + PATH="$PWD/bin:$PATH" +} + +abuild_package_size_zero_body() { + init_keys + mkdir -p test-size + create_fake_du + + cd test-size + cat > APKBUILD <<-EOF + # Maintainer: Test User 123 <123@example.com> + + # test package + pkgname="test-size" + pkgver="1.0" + pkgrel=0 + pkgdesc='Dummy test package that has no files' + url='https://gitlab.alpinelinux.org/alpine/aports' + arch='noarch' + license='MIT' + install="\$pkgname.post-install" + + package() { + mkdir -p "\$pkgdir" + } + EOF + cat > test-size.post-install <<-EOF + #!/bin/sh + echo 1 + EOF + abuild rootpkg + # should be set to 1 + atf_check -o match:'^size = 1$' \ + cat pkg/.control.test-size/.PKGINFO +} + +abuild_package_size_nonzero_body() { + init_keys + mkdir -p test-size + + cd test-size + cat > APKBUILD <<-EOF + # Maintainer: Test User 123 <123@example.com> + + # test package + pkgname="test-size" + pkgver="1.0" + pkgrel=0 + pkgdesc='Dummy test package that has files' + url='https://gitlab.alpinelinux.org/alpine/aports' + arch='noarch' + license='MIT' + + package() { + mkdir -p "\$pkgdir" + printf "%s" "very important data" > "\$pkgdir"/testfile + } + EOF + abuild rootpkg + # should not be set to 1 + atf_check -o not-match:'^size = 1$' \ + cat pkg/.control.test-size/.PKGINFO +} |