From d2a3d596d61aab38eca8386f5eb750838a7b9f4d Mon Sep 17 00:00:00 2001 From: Martin Duffy Date: Thu, 30 Jan 2025 14:02:43 -0500 Subject: instrumentation: Fix expected location of Labels when using CTest launchers --- Source/CTest/cmCTestLaunch.cxx | 6 ++++++ Source/CTest/cmCTestLaunchReporter.cxx | 4 ++-- Source/CTest/cmCTestLaunchReporter.h | 1 + Source/cmake.cxx | 3 ++- Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake | 3 +++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index 2ab2976..bb0b41f 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -68,6 +68,7 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv) DoingCommandType, DoingRole, DoingBuildDir, + DoingCurrentBuildDir, DoingCount, DoingFilterPrefix }; @@ -95,6 +96,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv) doing = DoingRole; } else if (strcmp(arg, "--build-dir") == 0) { doing = DoingBuildDir; + } else if (strcmp(arg, "--current-build-dir") == 0) { + doing = DoingCurrentBuildDir; } else if (strcmp(arg, "--filter-prefix") == 0) { doing = DoingFilterPrefix; } else if (doing == DoingOutput) { @@ -121,6 +124,9 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv) } else if (doing == DoingBuildDir) { this->Reporter.OptionBuildDir = arg; doing = DoingNone; + } else if (doing == DoingCurrentBuildDir) { + this->Reporter.OptionCurrentBuildDir = arg; + doing = DoingNone; } else if (doing == DoingFilterPrefix) { this->Reporter.OptionFilterPrefix = arg; doing = DoingNone; diff --git a/Source/CTest/cmCTestLaunchReporter.cxx b/Source/CTest/cmCTestLaunchReporter.cxx index 1d887c8..77046a3 100644 --- a/Source/CTest/cmCTestLaunchReporter.cxx +++ b/Source/CTest/cmCTestLaunchReporter.cxx @@ -78,12 +78,12 @@ void cmCTestLaunchReporter::ComputeFileNames() void cmCTestLaunchReporter::LoadLabels() { - if (this->OptionBuildDir.empty() || this->OptionTargetName.empty()) { + if (this->OptionCurrentBuildDir.empty() || this->OptionTargetName.empty()) { return; } // Labels are listed in per-target files. - std::string fname = cmStrCat(this->OptionBuildDir, "/CMakeFiles/", + std::string fname = cmStrCat(this->OptionCurrentBuildDir, "/CMakeFiles/", this->OptionTargetName, ".dir/Labels.txt"); // We are interested in per-target labels for this source file. diff --git a/Source/CTest/cmCTestLaunchReporter.h b/Source/CTest/cmCTestLaunchReporter.h index cf8838e..31cd9f2 100644 --- a/Source/CTest/cmCTestLaunchReporter.h +++ b/Source/CTest/cmCTestLaunchReporter.h @@ -37,6 +37,7 @@ public: std::string OptionTargetLabels; std::string OptionTargetName; std::string OptionTargetType; + std::string OptionCurrentBuildDir; std::string OptionBuildDir; std::string OptionFilterPrefix; std::string OptionCommandType; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index f5265c1..2e3b7f6 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2667,7 +2667,8 @@ int cmake::ActualConfigure() cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --instrument "); } std::string common_args = - cmStrCat(" --target-name ", "--build-dir \"", + cmStrCat(" --target-name --current-build-dir ", + " --build-dir \"", this->State->GetBinaryDirectory(), "\" "); this->State->SetGlobalProperty( "RULE_LAUNCH_COMPILE", diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake b/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake index dbe7bf8..7ed87ea 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake @@ -28,6 +28,7 @@ run_CTestScriptVariable() # 2. Specify subprojects via a CTest script variable on the command line e.g. # ctest -S test.cmake -DCTEST_LABELS_FOR_SUBPROJECTS:STRING="MySubproject" # Note: This test includes a failing build +# Note: Also use --instrumentation mode to ensure it doesn't interfere with label generation function(run_CTestScriptVariableCommandLine) set(CTEST_EXTRA_CONFIG "set(CTEST_USE_LAUNCHERS 1)") set(CASE_TEST_PREFIX_CODE [[ @@ -36,6 +37,8 @@ file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyThirdPartyDependency" ]]) set(CASE_CMAKELISTS_SUFFIX_CODE [[ add_subdirectory(MyThirdPartyDependency) +set(CMAKE_EXPERIMENTAL_INSTRUMENTATION "a37d1069-1972-4901-b9c9-f194aaf2b6e0") +cmake_instrumentation(DATA_VERSION 1 API_VERSION 1) ]]) run_ctest(CTestScriptVariableCommandLine "-DCTEST_LABELS_FOR_SUBPROJECTS:STRING=MyThirdPartyDependency") -- cgit v0.12 From 159571359680c0507484f685dd5ea893c6a9c291 Mon Sep 17 00:00:00 2001 From: Martin Duffy Date: Thu, 30 Jan 2025 14:02:43 -0500 Subject: instrumentation: Fix expected location of Labels when using CTest launchers --- Modules/CTestUseLaunchers.cmake | 2 +- Source/cmake.cxx | 6 ++--- ...riableCommandLineWithInstrumentation-result.txt | 1 + ...riableCommandLineWithInstrumentation-stderr.txt | 2 ++ ...riableCommandLineWithInstrumentation-stdout.txt | 9 +++++++ .../RunCMakeTest.cmake | 29 +++++++++++++++------- 6 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-result.txt create mode 100644 Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stderr.txt create mode 100644 Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stdout.txt diff --git a/Modules/CTestUseLaunchers.cmake b/Modules/CTestUseLaunchers.cmake index 5c544f8..eeea992 100644 --- a/Modules/CTestUseLaunchers.cmake +++ b/Modules/CTestUseLaunchers.cmake @@ -46,7 +46,7 @@ endif() if(CTEST_USE_LAUNCHERS) set(__launch_common_options - "--target-name --build-dir ") + "--target-name --current-build-dir ") set(__launch_compile_options "${__launch_common_options} --output --source --language ") diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 2e3b7f6..d051d68 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2661,14 +2661,14 @@ int cmake::ActualConfigure() std::string launcher; if (mf->IsOn("CTEST_USE_LAUNCHERS")) { launcher = - cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --launch "); + cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --launch ", + "--current-build-dir "); } else { launcher = cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --instrument "); } std::string common_args = - cmStrCat(" --target-name --current-build-dir ", - " --build-dir \"", + cmStrCat(" --target-name --build-dir \"", this->State->GetBinaryDirectory(), "\" "); this->State->SetGlobalProperty( "RULE_LAUNCH_COMPILE", diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-result.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-result.txt new file mode 100644 index 0000000..b57e2de --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-result.txt @@ -0,0 +1 @@ +(-1|255) diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stderr.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stderr.txt new file mode 100644 index 0000000..e9327a3 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stderr.txt @@ -0,0 +1,2 @@ +Unable to find executable:.*MyThirdPartyDependency/src(/[^/ +]+)?/third_party diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stdout.txt b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stdout.txt new file mode 100644 index 0000000..c2c1bc7 --- /dev/null +++ b/Tests/RunCMake/ctest_labels_for_subprojects/CTestScriptVariableCommandLineWithInstrumentation-stdout.txt @@ -0,0 +1,9 @@ +0% tests passed, 1 tests failed out of 1 ++ +Subproject Time Summary: +MyThirdPartyDependency += +[0-9.]+ sec\*proc \(1 test\) ++ +Label Time Summary: +NotASubproject += +[0-9.]+ sec\*proc \(1 test\) ++ +Total Test time \(real\) = +[0-9.]+ sec diff --git a/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake b/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake index 7ed87ea..9b3b6f4 100644 --- a/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_labels_for_subprojects/RunCMakeTest.cmake @@ -29,25 +29,36 @@ run_CTestScriptVariable() # ctest -S test.cmake -DCTEST_LABELS_FOR_SUBPROJECTS:STRING="MySubproject" # Note: This test includes a failing build # Note: Also use --instrumentation mode to ensure it doesn't interfere with label generation -function(run_CTestScriptVariableCommandLine) +function(run_CTestScriptVariableCommandLine USE_INSTRUMENTATION) set(CTEST_EXTRA_CONFIG "set(CTEST_USE_LAUNCHERS 1)") set(CASE_TEST_PREFIX_CODE [[ file(COPY "${CTEST_RUNCMAKE_SOURCE_DIRECTORY}/MyThirdPartyDependency" DESTINATION ${CTEST_SOURCE_DIRECTORY}) ]]) - set(CASE_CMAKELISTS_SUFFIX_CODE [[ -add_subdirectory(MyThirdPartyDependency) -set(CMAKE_EXPERIMENTAL_INSTRUMENTATION "a37d1069-1972-4901-b9c9-f194aaf2b6e0") -cmake_instrumentation(DATA_VERSION 1 API_VERSION 1) - ]]) - - run_ctest(CTestScriptVariableCommandLine "-DCTEST_LABELS_FOR_SUBPROJECTS:STRING=MyThirdPartyDependency") + if(USE_INSTRUMENTATION) + set(CASE_CMAKELISTS_SUFFIX_CODE [[ + add_subdirectory(MyThirdPartyDependency) + set(CMAKE_EXPERIMENTAL_INSTRUMENTATION "a37d1069-1972-4901-b9c9-f194aaf2b6e0") + cmake_instrumentation(DATA_VERSION 1 API_VERSION 1) + ]]) + set(RunCMake-check-file CTestScriptVariableCommandLine-check.cmake) + run_ctest(CTestScriptVariableCommandLineWithInstrumentation + "-DCTEST_LABELS_FOR_SUBPROJECTS:STRING=MyThirdPartyDependency") + unset(RunCMake-check-file) + else() + set(CASE_CMAKELISTS_SUFFIX_CODE [[ + add_subdirectory(MyThirdPartyDependency) + ]]) + run_ctest(CTestScriptVariableCommandLine + "-DCTEST_LABELS_FOR_SUBPROJECTS:STRING=MyThirdPartyDependency") + endif() unset(CTEST_EXTRA_CONFIG) unset(CASE_TEST_PREFIX_CODE) unset(CASE_CMAKELISTS_SUFFIX_CODE) endfunction() -run_CTestScriptVariableCommandLine() +run_CTestScriptVariableCommandLine(ON) +run_CTestScriptVariableCommandLine(OFF) # 3. Set subprojects via a CTest module variable on the command line # (will populate DartConfiguration.tcl) -- cgit v0.12