Переглянути джерело

instrumentation: Fix expected location of Labels when using CTest launchers

Martin Duffy 8 місяців тому
батько
коміт
d2a3d596d6

+ 6 - 0
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;

+ 2 - 2
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.

+ 1 - 0
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;

+ 2 - 1
Source/cmake.cxx

@@ -2667,7 +2667,8 @@ int cmake::ActualConfigure()
         cmStrCat("\"", cmSystemTools::GetCTestCommand(), "\" --instrument ");
     }
     std::string common_args =
-      cmStrCat(" --target-name <TARGET_NAME> ", "--build-dir \"",
+      cmStrCat(" --target-name <TARGET_NAME> --current-build-dir ",
+               "<CMAKE_CURRENT_BINARY_DIR> --build-dir \"",
                this->State->GetBinaryDirectory(), "\" ");
     this->State->SetGlobalProperty(
       "RULE_LAUNCH_COMPILE",

+ 3 - 0
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")