From ee06eb541e5aa477880ff0fc575be317eccbd929 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Wed, 20 Apr 2022 18:51:47 +0200 Subject: Avoid building inside the source dir in autopkgtest autopkgtest says: Tests may not modify the source tree (and may not have write access to it). We don't really modify the source of course, but we created our build/ directory in the tree, which seems to work just fine (for now), but lets be nice. --- .gitlab-ci.yml | 1 + debian/tests/run-tests | 27 +++++++++++++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 93a577ad2..700f29b0a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,4 +37,5 @@ test as user: - sudo -u travis env -C build cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -G Ninja .. - sudo -u travis --preserve-env=CCACHE_DIR,CCACHE_BASEDIR ninja -C build - sudo -u travis CTEST_OUTPUT_ON_FAILURE=1 ninja -C build test + - chmod -R o-w $PWD - sudo -u travis unbuffer ./test/integration/run-tests -q -j 4 diff --git a/debian/tests/run-tests b/debian/tests/run-tests index ff3359fae..461042641 100644 --- a/debian/tests/run-tests +++ b/debian/tests/run-tests @@ -1,19 +1,30 @@ #!/bin/sh - set -e -if [ ! -e build/CMakeCache.txt ]; then - mkdir build || true - ( cd build && cmake .. ) +SOURCE_DIR="$(pwd)" +if [ -z "$AUTOPKGTEST_TMP" ]; then + BUILD_DIR='' + cleanup() { + if [ -n "$BUILD_DIR" ]; then cd /; rm -rf -- "$BUILD_DIR"; fi + BUILD_DIR='' + } + trap 'cleanup' 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM + BUILD_DIR="$(mktemp -d)" +else + BUILD_DIR="$AUTOPKGTEST_TMP" +fi + +if [ ! -e "${BUILD_DIR}/CMakeCache.txt" ]; then + cmake -S "$SOURCE_DIR" -B "$BUILD_DIR" fi -make -C build/test/interactive-helper +make -C "${BUILD_DIR}/test/interactive-helper" # run tests against the installed apt, use "env -i" to ensure # the host env does not pollute our environment env -i \ -APT_INTEGRATION_TESTS_SOURCE_DIR=$(pwd) \ -APT_INTEGRATION_TESTS_HELPERS_BIN_DIR=$(pwd)/build/test/interactive-helper \ +APT_INTEGRATION_TESTS_SOURCE_DIR="${SOURCE_DIR}" \ +APT_INTEGRATION_TESTS_HELPERS_BIN_DIR="${BUILD_DIR}/test/interactive-helper" \ APT_INTEGRATION_TESTS_METHODS_DIR=/usr/lib/apt/methods \ APT_INTEGRATION_TESTS_LIBEXEC_DIR=/usr/lib/apt/ \ APT_INTEGRATION_TESTS_INTERNAL_SOLVER=/usr/lib/apt/solvers/apt \ @@ -23,4 +34,4 @@ APT_INTEGRATION_TESTS_BUILD_DIR=/usr/bin \ APT_INTEGRATION_TESTS_FTPARCHIVE_BIN_DIR=/usr/bin \ APT_INTEGRATION_TESTS_LIBRARY_PATH=/dev/null/does/not/exist \ APT_INTEGRATION_TESTS_ARTIFACTS_DIR="${AUTOPKGTEST_ARTIFACTS}" \ -./test/integration/run-tests -q +"${SOURCE_DIR}/test/integration/run-tests" -q -- cgit v1.2.3-70-g09d2