Browse Source

ctest: support a new `--objects-dir` argument

When shorter object directories are used, CTest needs to know where to
look for artifacts.
John Parent 9 months ago
parent
commit
c6763bb021

+ 1 - 1
Modules/CTestUseLaunchers.cmake

@@ -60,7 +60,7 @@ endif()
 
 if(CTEST_USE_LAUNCHERS)
   set(__launch_common_options
-    "--target-name <TARGET_NAME> --current-build-dir <CMAKE_CURRENT_BINARY_DIR>")
+    "--target-name <TARGET_NAME> --current-build-dir <CMAKE_CURRENT_BINARY_DIR> --build-dir <CMAKE_BINARY_DIR> --object-dir <TARGET_SUPPORT_DIR>")
 
   set(__launch_compile_options
     "${__launch_common_options} --output <OBJECT> --source <SOURCE> --language <LANGUAGE>")

+ 24 - 1
Source/CTest/cmCTestLaunch.cxx

@@ -14,6 +14,7 @@
 #include "cmsys/FStream.hxx"
 #include "cmsys/RegularExpression.hxx"
 
+#include "cmCMakePath.h"
 #include "cmCTestLaunchReporter.h"
 #include "cmGlobalGenerator.h"
 #include "cmInstrumentation.h"
@@ -71,7 +72,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv)
     DoingCurrentBuildDir,
     DoingCount,
     DoingFilterPrefix,
-    DoingConfig
+    DoingConfig,
+    DoingObjectDir
   };
   Doing doing = DoingNone;
   int arg0 = 0;
@@ -103,6 +105,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv)
       doing = DoingFilterPrefix;
     } else if (strcmp(arg, "--config") == 0) {
       doing = DoingConfig;
+    } else if (strcmp(arg, "--object-dir") == 0) {
+      doing = DoingObjectDir;
     } else if (doing == DoingOutput) {
       this->Reporter.OptionOutput = arg;
       doing = DoingNone;
@@ -142,9 +146,28 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv)
     } else if (doing == DoingConfig) {
       this->Reporter.OptionConfig = arg;
       doing = DoingNone;
+    } else if (doing == DoingObjectDir) {
+      this->Reporter.OptionObjectDir = arg;
+      doing = DoingNone;
     }
   }
 
+  // Older builds do not pass `--object-dir`, so construct a default if the
+  // components are available.
+  if (this->Reporter.OptionObjectDir.empty() &&
+      !this->Reporter.OptionCurrentBuildDir.empty() &&
+      !this->Reporter.OptionTargetName.empty()) {
+    this->Reporter.OptionObjectDir =
+      cmStrCat(this->Reporter.OptionCurrentBuildDir, "/CMakeFiles/",
+               this->Reporter.OptionTargetName, ".dir");
+  }
+  if (!this->Reporter.OptionObjectDir.empty() &&
+      !cmCMakePath(this->Reporter.OptionObjectDir).IsAbsolute() &&
+      !this->Reporter.OptionBuildDir.empty()) {
+    this->Reporter.OptionObjectDir = cmStrCat(
+      this->Reporter.OptionBuildDir, '/', this->Reporter.OptionObjectDir);
+  }
+
   // Extract the real command line.
   if (arg0) {
     for (int i = 0; i < argc - arg0; ++i) {

+ 2 - 3
Source/CTest/cmCTestLaunchReporter.cxx

@@ -78,13 +78,12 @@ void cmCTestLaunchReporter::ComputeFileNames()
 
 void cmCTestLaunchReporter::LoadLabels()
 {
-  if (this->OptionCurrentBuildDir.empty() || this->OptionTargetName.empty()) {
+  if (this->OptionObjectDir.empty()) {
     return;
   }
 
   // Labels are listed in per-target files.
-  std::string fname = cmStrCat(this->OptionCurrentBuildDir, "/CMakeFiles/",
-                               this->OptionTargetName, ".dir/Labels.txt");
+  std::string fname = cmStrCat(this->OptionObjectDir, "/Labels.txt");
 
   // We are interested in per-target labels for this source file.
   std::string source = this->OptionSource;

+ 1 - 0
Source/CTest/cmCTestLaunchReporter.h

@@ -43,6 +43,7 @@ public:
   std::string OptionCommandType;
   std::string OptionRole;
   std::string OptionConfig;
+  std::string OptionObjectDir;
 
   // The real command line appearing after launcher arguments.
   std::string CWD;

+ 2 - 1
Source/cmake.cxx

@@ -2710,7 +2710,8 @@ int cmake::ActualConfigure()
     if (mf->IsOn("CTEST_USE_LAUNCHERS")) {
       launcher = cmStrCat('"', cmSystemTools::GetCTestCommand(),
                           "\" --launch "
-                          "--current-build-dir <CMAKE_CURRENT_BINARY_DIR> ");
+                          "--current-build-dir <CMAKE_CURRENT_BINARY_DIR> "
+                          "--object-dir <TARGET_SUPPORT_DIR> ");
     } else {
       launcher =
         cmStrCat('"', cmSystemTools::GetCTestCommand(), "\" --instrument ");