abuild: fix package size for script-only packages

This commit is contained in:
psykose 2022-08-05 14:00:36 +00:00
parent 3a235e4d3c
commit 927f14f6b3
No known key found for this signature in database
2 changed files with 84 additions and 7 deletions

View File

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

View File

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