abuild: set cache directories to a temporary directory if MOVE_CACHES is set

this allows for isolating cache directories per package
This commit is contained in:
ptrcnull 2023-06-22 03:33:59 +00:00 committed by psykose
parent 8efe527ff3
commit d27b635768
3 changed files with 81 additions and 4 deletions

View File

@ -156,6 +156,7 @@ cleanup() {
fi;;
pkgdir) msg "Cleaning up pkgdir"; rm -rf "$pkgbasedir";;
srcdir) msg "Cleaning up srcdir"; cleanup_srcdir;;
tmpdir) msg "Cleaning up tmpdir"; rm -rf "$tmpdir";;
deps)
if [ -n "$uninstall_after" ]; then
msg "Uninstalling dependencies..."
@ -553,10 +554,11 @@ unpack() {
default_unpack
}
# cleanup source and package dir
# cleanup source, package and temporary dir
clean() {
cleanup srcdir
cleanup pkgdir
cleanup tmpdir
}
# cleanup fetched sources
@ -690,7 +692,17 @@ runpart() {
prepare|build|package|check)
# exclude aports from git repo discovery
export GIT_CEILING_DIRECTORIES="$startdir"
cd "$builddir";;
# prevent using global cache directories
if [ -n "$MOVE_CACHES" ]; then
export GOCACHE="${GOCACHE:-"$tmpdir/go"}"
export GOMODCACHE="${GOCACHE:-"$tmpdir/gomod"}"
export GOTMPDIR="${GOTMPDIR:-"$tmpdir"}"
export CARGO_HOME="${CARGO_HOME:-"$tmpdir/cargo"}"
fi
cd "$builddir"
;;
esac
fi
$part
@ -2900,6 +2912,7 @@ APKBUILD=$(readlink -f "$APKBUILD")
startdir="${APKBUILD%/*}"
srcdir=${srcdir:-"$startdir/src"}
pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
tmpdir=${tmpdir:-"$startdir/tmp"}
repo=${startdir%/*}
repo=${repo##*/}

View File

@ -33,3 +33,6 @@ CLEANUP="srcdir bldroot pkgdir deps"
# what to cleanup after a failed build
ERROR_CLEANUP="bldroot deps"
# uncomment to prevent using global cache directories for Go and Cargo
#MOVE_CACHES=1

View File

@ -42,7 +42,9 @@ init_tests \
abuild_pyc \
abuild_setcap_binary \
abuild_setcap_binary_with_option \
abuild_command_provides
abuild_command_provides \
abuild_gocache_dir \
abuild_cargo_home_dir
export ABUILD_SHAREDIR=$(atf_get_srcdir)/..
export ABUILD_CONF=/dev/null
@ -513,7 +515,6 @@ abuild_git_ceiling_body() {
abuild
}
create_fake_du() {
mkdir -p bin
cat > bin/du <<-EOF
@ -957,3 +958,63 @@ abuild_command_provides_body() {
-o not-match:"provides = cmd:dir=1.0-r0" \
grep '^provides = ' pkg/.control.bin-in-path/.PKGINFO
}
abuild_gocache_dir_body() {
init_keys
mkdir gocache-dir
cd gocache-dir
cat >APKBUILD<<-EOF
# Maintainer: Joe User <juser@example.com>
pkgname="gocache-dir"
pkgver="1.0"
pkgrel=0
pkgdesc="Dummy test package"
url="https://gitlab.alpinelinux.org/alpine/aports"
arch="noarch"
license="MIT"
prepare() {
mkdir -p "\$builddir"
}
build() {
echo "dir:\$GOCACHE"
}
package() {
:
}
EOF
MOVE_CACHES=1 \
atf_check -s exit:0 \
-o match:"dir:.*/tmp/go" \
abuild prepare build
}
abuild_cargo_home_dir_body() {
init_keys
mkdir cargo-home-dir
cd cargo-home-dir
cat >APKBUILD<<-EOF
# Maintainer: Joe User <juser@example.com>
pkgname="cargo-home-dir"
pkgver="1.0"
pkgrel=0
pkgdesc="Dummy test package"
url="https://gitlab.alpinelinux.org/alpine/aports"
arch="noarch"
license="MIT"
prepare() {
mkdir -p "\$builddir"
}
build() {
echo "dir:\$CARGO_HOME"
}
package() {
:
}
EOF
MOVE_CACHES=1 \
atf_check -s exit:0 \
-o match:"dir:.*/tmp/cargo" \
abuild prepare build
}