Skip to content

Commit d51f808

Browse files
committed
ctest: use same target folder for build rerun test
1 parent 70f555f commit d51f808

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ if(BUILD_TESTING)
168168
add_test(NAME cxx_qt_gen_test_outputs_gen COMMAND rustfmt --check ${CXX_QT_GEN_TEST_OUTPUTS})
169169

170170
# Add test which checks that a build rerun doesn't recompile and uses caches instead
171-
add_test(NAME cargo_build_rerun COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/check_cargo_build_rerun.sh" "${CMAKE_CURRENT_SOURCE_DIR}")
171+
add_test(NAME cargo_build_rerun COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/scripts/check_cargo_build_rerun.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${CARGO_TARGET_DIR}")
172172

173173
# Ensure that cargo_build_rerun doesn't run while we are already building
174174
set_tests_properties(cargo_build_rerun PROPERTIES RUN_SERIAL TRUE)

scripts/check_cargo_build_rerun.sh

+9-8
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77

88
set -ex
99

10+
SOURCE_FOLDER=$1
11+
BUILD_FOLDER=$2
12+
1013
# Ensure we are in the right directory
11-
SCRIPT=$(realpath "$0")
12-
SCRIPTPATH=$(dirname "$SCRIPT")
13-
cd "$SCRIPTPATH/../"
14+
cd "$SOURCE_FOLDER"
1415

1516
# Ensure that we do see a "Compiling" in the output
1617
# as if we do it means we have a cargo::rerun-if-changed incorrectly
1718
function check_build_contains_compiling() {
18-
BUILD=$(cargo build -p qml-minimal-no-cmake 2>&1)
19+
BUILD=$(cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1)
1920

2021
if ! echo "$BUILD" | grep -q Compiling; then
2122
echo "cargo build is missing text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script."
@@ -26,7 +27,7 @@ function check_build_contains_compiling() {
2627
# Ensure that we don't see any "Compiling" in the output
2728
# as if we do it means we have a cargo::rerun-if-changed incorrectly
2829
function check_build_no_compiling() {
29-
BUILD=$(cargo build -p qml-minimal-no-cmake 2>&1)
30+
BUILD=$(cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake 2>&1)
3031

3132
if echo "$BUILD" | grep -q Compiling; then
3233
echo "cargo build contained text 'Compiling', likely an incorrect cargo::rerun-if-changed in a build script."
@@ -35,20 +36,20 @@ function check_build_no_compiling() {
3536
}
3637

3738
# Build once
38-
cargo build -p qml-minimal-no-cmake
39+
cargo build --target-dir="$BUILD_FOLDER" -p qml-minimal-no-cmake
3940

4041
# Build a second time
4142
check_build_no_compiling
4243

4344
# Modify a qml file
44-
touch "$SCRIPTPATH/../examples/cargo_without_cmake/qml/main.qml"
45+
touch "$SOURCE_FOLDER/examples/cargo_without_cmake/qml/main.qml"
4546

4647
# Build a third and fourth time
4748
check_build_contains_compiling
4849
check_build_no_compiling
4950

5051
# Modify a Rust file
51-
touch "$SCRIPTPATH/../examples/cargo_without_cmake/src/cxxqt_object.rs"
52+
touch "$SOURCE_FOLDER/examples/cargo_without_cmake/src/cxxqt_object.rs"
5253

5354
# Build a fifth and sixth time
5455
check_build_contains_compiling

0 commit comments

Comments
 (0)