]> git.saurik.com Git - apt.git/commitdiff
test: Automatically discover CMake build directory
authorJulian Andres Klode <jak@debian.org>
Wed, 10 Aug 2016 12:16:52 +0000 (14:16 +0200)
committerJulian Andres Klode <jak@debian.org>
Wed, 10 Aug 2016 14:17:19 +0000 (16:17 +0200)
Look at the project root, and all directories directly below it and
pick the directory with the newest CMakeCache.txt file.

Gbp-Dch: ignore

test/integration/framework
test/integration/run-tests

index 824bd46b6771ee19618091b079dd9f01d4484614..0f442dff43bdf08b25ddc78ed2b9d78012580a84 100644 (file)
@@ -257,6 +257,24 @@ escape_shell() {
     echo "$@" | sed -e "s#'#'\"'\"'#g"
 }
 
+find_project_binary_dir() {
+       local TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
+       if [ -z "$PROJECT_BINARY_DIR" ]; then
+               PROJECT_BINARY_DIR=
+               for dir in ${TESTDIRECTORY}/../../ ${TESTDIRECTORY}/../../*; do
+                       test -e "$dir/CMakeCache.txt"  || continue
+                       if [ -z "$PROJECT_BINARY_DIR" ] ||
+                          [ "$dir/CMakeCache.txt" -nt "$PROJECT_BINARY_DIR/CMakeCache.txt" ]; then
+                               PROJECT_BINARY_DIR="$dir"
+                       fi
+               done
+               if [ -z "$PROJECT_BINARY_DIR" ]; then
+                       echo "Cannot find build directory, you might want to set PROJECT_BINARY_DIR" >&2
+                       exit 1
+               fi
+               export PROJECT_BINARY_DIR
+       fi
+}
 setupenvironment() {
        # privilege dropping and testing doesn't work if /tmp isn't world-writeable (as e.g. with libpam-tmpdir)
        if [ -n "$TMPDIR" ] && [ "$(id -u)" = '0' ] && [ "$(stat --format '%a' "$TMPDIR")" != '1777' ]; then
@@ -281,9 +299,11 @@ setupenvironment() {
        fi
 
        TESTDIRECTORY="$(readlink -f "$(dirname $0)")"
+       # Find the newest build directory (sets PROJECT_BINARY_DIR)
+       find_project_binary_dir
         # allow overriding the default BUILDDIR location
        SOURCEDIRECTORY="${APT_INTEGRATION_TESTS_SOURCE_DIR:-"${TESTDIRECTORY}/../../"}"
-       BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/cmdline"}"
+       BUILDDIRECTORY="${APT_INTEGRATION_TESTS_BUILD_DIR:-"${PROJECT_BINARY_DIR}/cmdline"}"
        LIBRARYPATH="${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}/../apt-pkg"}"
         METHODSDIR="${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/../methods"}"
         APTHELPERBINDIR="${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"}"
index 78f24fbaf024e8f52784b80868fc8258f6e1ef75..e90b4b7558eb13c3b45d04cc5b968fb0c6b9575e 100755 (executable)
@@ -1,4 +1,10 @@
 #!/bin/sh
+
+TESTDIR="$(readlink -f "$(dirname "$0")")"
+. "$TESTDIR/framework"
+
+find_project_binary_dir
+
 set -e
 
 TESTTORUN=''