From 4c2d06e69bb8353dc167f88a4cc2659609a31eb7 Mon Sep 17 00:00:00 2001 From: Arha Gatram Date: Fri, 10 Jul 2026 15:36:19 -0700 Subject: [PATCH] CTest: Add support for relative paths in GENERATED_RESOURCE_SPEC_FILE --- .../GENERATED_RESOURCE_SPEC_FILE.rst | 6 +++++ .../dev/ctest-dyn-rsrc-spec-rel-path.rst | 5 +++++ Source/CTest/cmCTestMultiProcessHandler.cxx | 8 ------- .../CTestResourceAllocation/CMakeLists.txt | 3 +++ .../RunCMakeTest.cmake | 22 +++++++++++++++++++ ...-resource-relative-path-ctest-s-result.txt | 1 - ...-resource-relative-path-ctest-s-stderr.txt | 4 ---- ...-resource-relative-path-subdirectory.cmake | 2 ++ ...amic-resource-relative-path-test-dir.cmake | 2 ++ .../subdir/CMakeLists.txt | 10 +++++++++ 10 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 Help/release/dev/ctest-dyn-rsrc-spec-rel-path.rst create mode 100644 Tests/RunCMake/CTestResourceAllocation/CMakeLists.txt delete mode 100644 Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-result.txt delete mode 100644 Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-stderr.txt create mode 100644 Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-subdirectory.cmake create mode 100644 Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-test-dir.cmake create mode 100644 Tests/RunCMake/CTestResourceAllocation/subdir/CMakeLists.txt diff --git a/Help/prop_test/GENERATED_RESOURCE_SPEC_FILE.rst b/Help/prop_test/GENERATED_RESOURCE_SPEC_FILE.rst index 89596acb6f..743935b58a 100644 --- a/Help/prop_test/GENERATED_RESOURCE_SPEC_FILE.rst +++ b/Help/prop_test/GENERATED_RESOURCE_SPEC_FILE.rst @@ -5,3 +5,9 @@ GENERATED_RESOURCE_SPEC_FILE Path to the :ref:`dynamically-generated resource spec file ` generated by this test. + +.. versionchanged:: 4.5 + Relative paths are interpreted relative to the + :variable:`CMAKE_BINARY_DIR` or the directory specified by the + CTest option :ctest-option:`--test-dir` if provided. Prior to CMake 4.5, + this property only accepted absolute paths. diff --git a/Help/release/dev/ctest-dyn-rsrc-spec-rel-path.rst b/Help/release/dev/ctest-dyn-rsrc-spec-rel-path.rst new file mode 100644 index 0000000000..09e72cba62 --- /dev/null +++ b/Help/release/dev/ctest-dyn-rsrc-spec-rel-path.rst @@ -0,0 +1,5 @@ +ctest-dyn-rsrc-spec-rel-path +---------------------------- + +* The :prop_test:`GENERATED_RESOURCE_SPEC_FILE` test property gained support + for relative paths. diff --git a/Source/CTest/cmCTestMultiProcessHandler.cxx b/Source/CTest/cmCTestMultiProcessHandler.cxx index 4954e0d55b..3ad8855791 100644 --- a/Source/CTest/cmCTestMultiProcessHandler.cxx +++ b/Source/CTest/cmCTestMultiProcessHandler.cxx @@ -1650,14 +1650,6 @@ bool cmCTestMultiProcessHandler::CheckGeneratedResourceSpec() return false; } - if (!cmSystemTools::FileIsFullPath( - test.second->GeneratedResourceSpecFile)) { - cmCTestLog(this->CTest, ERROR_MESSAGE, - "GENERATED_RESOURCE_SPEC_FILE must be an absolute path" - << std::endl); - return false; - } - this->ResourceSpecSetupTest = test.first; this->ResourceSpecSetupFixture = *test.second->FixturesSetup.begin(); } diff --git a/Tests/RunCMake/CTestResourceAllocation/CMakeLists.txt b/Tests/RunCMake/CTestResourceAllocation/CMakeLists.txt new file mode 100644 index 0000000000..bf2ef1506e --- /dev/null +++ b/Tests/RunCMake/CTestResourceAllocation/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.10) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/CTestResourceAllocation/RunCMakeTest.cmake b/Tests/RunCMake/CTestResourceAllocation/RunCMakeTest.cmake index 3c3e88fae1..78c23629d0 100644 --- a/Tests/RunCMake/CTestResourceAllocation/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestResourceAllocation/RunCMakeTest.cmake @@ -205,3 +205,25 @@ run_ctest_resource_dynamic(dynamic-resource-conflicting-spec -DCTEST_RESOURCE_SP run_ctest_resource_dynamic(dynamic-resource-circular) run_ctest_resource_dynamic(dynamic-resource-circular-no-required-fixtures) run_ctest_resource_dynamic(dynamic-resource-relative-path) + +function(run_resource_dynamic_subdirectory_cli test_name test_dir) + set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${test_name}-build") + run_cmake(${test_name}) + set(RunCMake_TEST_NO_CLEAN 1) + set(RunCMake_TEST_OUTPUT_MERGE 1) + if(test_dir) + set(RunCMake_TEST_COMMAND_WORKING_DIRECTORY "${test_dir}") + endif() + run_cmake_command(${test_name}-test ${CMAKE_CTEST_COMMAND} -C Debug ${ARGN}) +endfunction() + +block() + run_resource_dynamic_subdirectory_cli( + dynamic-resource-relative-path-subdirectory "" + --test-dir "${RunCMake_BINARY_DIR}/dynamic-resource-relative-path-subdirectory-build" + ) + run_resource_dynamic_subdirectory_cli( + dynamic-resource-relative-path-test-dir "${RunCMake_BINARY_DIR}" + --test-dir "${RunCMake_BINARY_DIR}/dynamic-resource-relative-path-test-dir-build" + ) +endblock() diff --git a/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-result.txt b/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-result.txt deleted file mode 100644 index b57e2deb77..0000000000 --- a/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-result.txt +++ /dev/null @@ -1 +0,0 @@ -(-1|255) diff --git a/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-stderr.txt b/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-stderr.txt deleted file mode 100644 index 6829ffeb8a..0000000000 --- a/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s-stderr.txt +++ /dev/null @@ -1,4 +0,0 @@ -^GENERATED_RESOURCE_SPEC_FILE must be an absolute path -CMake Error at [^ -]*/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-ctest-s/test\.cmake:[0-9]+ \(message\): - Tests did not pass$ diff --git a/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-subdirectory.cmake b/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-subdirectory.cmake new file mode 100644 index 0000000000..6bc8d5cf04 --- /dev/null +++ b/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-subdirectory.cmake @@ -0,0 +1,2 @@ +enable_testing() +add_subdirectory(subdir) diff --git a/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-test-dir.cmake b/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-test-dir.cmake new file mode 100644 index 0000000000..6bc8d5cf04 --- /dev/null +++ b/Tests/RunCMake/CTestResourceAllocation/dynamic-resource-relative-path-test-dir.cmake @@ -0,0 +1,2 @@ +enable_testing() +add_subdirectory(subdir) diff --git a/Tests/RunCMake/CTestResourceAllocation/subdir/CMakeLists.txt b/Tests/RunCMake/CTestResourceAllocation/subdir/CMakeLists.txt new file mode 100644 index 0000000000..7719c63c71 --- /dev/null +++ b/Tests/RunCMake/CTestResourceAllocation/subdir/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME RealTest COMMAND "${CMAKE_COMMAND}" -E true) +add_test(NAME GenerateSpecFile COMMAND "${CMAKE_COMMAND}" -E copy "${CMAKE_SOURCE_DIR}/dynamic-resspec.json" "${CMAKE_CURRENT_BINARY_DIR}") +set_tests_properties(GenerateSpecFile PROPERTIES + GENERATED_RESOURCE_SPEC_FILE "subdir/dynamic-resspec.json" + FIXTURES_SETUP "ResourceSpec" + ) +set_tests_properties(RealTest PROPERTIES + FIXTURES_REQUIRED "ResourceSpec" + RESOURCE_GROUPS "widgets:1" + )