From ded65775a28ceeb53829ec2bae1bb7a9947f5856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 6 Dec 2017 15:09:54 +0100 Subject: [PATCH] tests: try to autodetect directory better Ignore mkosi.builddir. In the future we can also add other patterns if necessary. run-intergration-tests.sh is updated to use the new script, and modified to work from arbitrary directory. Follow-up for #7494. --- test/Makefile.guess | 14 ------------- test/TEST-01-BASIC/Makefile | 2 +- test/TEST-13-NSPAWN-SMOKE/Makefile | 2 +- test/TEST-17-UDEV-WANTS/Makefile | 2 +- test/TEST-18-FAILUREACTION/Makefile | 2 +- test/TEST-19-DELEGATE/Makefile | 2 +- test/run-integration-tests.sh | 10 ++++------ tools/find-build-dir.sh | 31 +++++++++++++++++++++++++++++ 8 files changed, 40 insertions(+), 25 deletions(-) delete mode 100644 test/Makefile.guess create mode 100755 tools/find-build-dir.sh diff --git a/test/Makefile.guess b/test/Makefile.guess deleted file mode 100644 index 1916d09a6c..0000000000 --- a/test/Makefile.guess +++ /dev/null @@ -1,14 +0,0 @@ -# Try to guess the build directory: -# we look for subdirectories of ../.. that look like ninja build dirs. - -ifeq ($(BUILD_DIR),) - dirs = $(dir $(wildcard ../../*/.ninja_log)) - ifeq ($(dirs),) - $(error Cannot guess build dir, set BUILD_DIR) - endif - ifneq ($(firstword $(dirs)),$(dirs)) - $(warning Candidates: $(dirs)) - $(error Too many build dirs to pick from, set BUILD_DIR) - endif - BUILD_DIR=$(dirs) -endif diff --git a/test/TEST-01-BASIC/Makefile b/test/TEST-01-BASIC/Makefile index b895de8bcb..3a212a07a9 100644 --- a/test/TEST-01-BASIC/Makefile +++ b/test/TEST-01-BASIC/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup clean run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-13-NSPAWN-SMOKE/Makefile b/test/TEST-13-NSPAWN-SMOKE/Makefile index 41cca23c7f..ddcbbc302f 100644 --- a/test/TEST-13-NSPAWN-SMOKE/Makefile +++ b/test/TEST-13-NSPAWN-SMOKE/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-17-UDEV-WANTS/Makefile b/test/TEST-17-UDEV-WANTS/Makefile index b895de8bcb..3a212a07a9 100644 --- a/test/TEST-17-UDEV-WANTS/Makefile +++ b/test/TEST-17-UDEV-WANTS/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup clean run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-18-FAILUREACTION/Makefile b/test/TEST-18-FAILUREACTION/Makefile index b895de8bcb..3a212a07a9 100644 --- a/test/TEST-18-FAILUREACTION/Makefile +++ b/test/TEST-18-FAILUREACTION/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup clean run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/TEST-19-DELEGATE/Makefile b/test/TEST-19-DELEGATE/Makefile index b895de8bcb..3a212a07a9 100644 --- a/test/TEST-19-DELEGATE/Makefile +++ b/test/TEST-19-DELEGATE/Makefile @@ -1,4 +1,4 @@ -include ../Makefile.guess +BUILD_DIR=$(exec ../../tools/find-build-dir.sh) all setup clean run: @basedir=../.. TEST_BASE_DIR=../ BUILD_DIR=$(BUILD_DIR) ./test.sh --$@ diff --git a/test/run-integration-tests.sh b/test/run-integration-tests.sh index 3ece46c771..3a54a8b17c 100755 --- a/test/run-integration-tests.sh +++ b/test/run-integration-tests.sh @@ -1,21 +1,19 @@ #!/bin/bash -e -if ! test -d ../build ; then - echo "Expected build directory in ../build, but couldn't find it." >&2 - exit 1 -fi +BUILD_DIR="$($(dirname "$0")/../tools/find-build-dir.sh)" -ninja -C ../build +ninja -C "$BUILD_DIR" declare -A results RESULT=0 FAILURES=0 +cd "$(dirname "$0")" for TEST in TEST-??-* ; do echo -e "\n--x-- Starting $TEST --x--" set +e - make -C "$TEST" BUILD_DIR=$(pwd)/../build clean setup run + make -C "$TEST" "BUILD_DIR=$BUILD_DIR" clean setup run RESULT=$? set -e echo "--x-- Result of $TEST: $RESULT --x--" diff --git a/tools/find-build-dir.sh b/tools/find-build-dir.sh new file mode 100755 index 0000000000..33b40f93f7 --- /dev/null +++ b/tools/find-build-dir.sh @@ -0,0 +1,31 @@ +#!/bin/sh -e + +# Try to guess the build directory: +# we look for subdirectories of the parent directory that look like ninja build dirs. + +if [ -n "$BUILD_DIR" ]; then + echo "$(realpath "$BUILD_DIR")" + exit 0 +fi + +root="$(dirname "$(realpath "$0")")" + +found= +for i in "$root"/../*/build.ninja; do + c="$(dirname $i)" + [ -d "$c" ] || continue + [ "$(basename "$c")" != mkosi.builddir ] || continue + + if [ -n "$found" ]; then + echo 'Found multiple candidates, specify build directory with $BUILD_DIR' >&2 + exit 2 + fi + found="$c" +done + +if [ -z "$found" ]; then + echo 'Specify build directory with $BUILD_DIR' >&2 + exit 1 +fi + +echo "$(realpath $found)"