abuild: prune python cache dirs by default

these will be generated post-install in a hook.

ref https://gitlab.alpinelinux.org/alpine/aports/-/issues/11906
This commit is contained in:
psykose 2023-04-14 06:31:50 +00:00 committed by alice
parent ddc6f42ddc
commit 489fc06e40
2 changed files with 62 additions and 1 deletions

View File

@ -790,6 +790,15 @@ postcheck() {
find "$dir" -name '*.la' -type f -delete
fi
# remove all python .pyc cache unless intentionally kept
if ! options_has "keeppycache"; then
# wildcard should always get the system python dir, and this is faster than
# trying to calculate the python version.
find "$dir"/usr/lib/python* \
\( -type d -a -name "__pycache__" \) \
-exec rm -r {} +
fi
# look for /usr/lib/charset.alias
if [ -e "$dir"/usr/lib/charset.alias ] \
&& ! options_has "charset.alias"; then

View File

@ -33,7 +33,8 @@ init_tests \
abuild_devhelp \
abuild_check_maintainer \
abuild_cleanoldpkg \
abuild_path_with_spaces
abuild_path_with_spaces \
abuild_pycache
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
export ABUILD_CONF=/dev/null
@ -824,3 +825,54 @@ abuild_path_with_spaces_body() {
-e match:"Build complete" \
abuild
}
abuild_pycache_body() {
init_keys
mkdir -p pycachetest
cd pycachetest
cat >APKBUILD <<-EOF
# Maintainer: Joe User <juser@example.com>
pkgname="pycachetest"
pkgver="1.0"
pkgrel=0
pkgdesc="Dummy test package"
url="https://gitlab.alpinelinux.org/alpine/aports"
arch="noarch"
license="MIT"
source=""
prepare() {
mkdir -p "\$builddir"
}
check() {
true
}
package() {
mkdir -p "\$pkgdir"/usr/lib/python3.11/site-packages/test/__pycache__/
touch "\$pkgdir"/usr/lib/python3.11/site-packages/test/__pycache__/main.cpython-311.pyc
}
EOF
abuild clean unpack prepare build rootpkg
if [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__/main.cpython-311.pyc ]; then
atf_fail ".pyc was not deleted"
fi
if [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__ ]; then
atf_fail "__pycache__ dir was not deleted"
fi
options="keeppycache" abuild clean unpack prepare build rootpkg
if ! [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__/main.cpython-311.pyc ]; then
atf_fail ".pyc was deleted but shouldn't have been"
fi
if ! [ -e pkg/pycachetest/usr/lib/python3.11/site-packages/test/__pycache__ ]; then
atf_fail "__pycache__ dir was deleted but shouldn't have been"
fi
}