Browse Source

cmCTest: De-duplicate working directory code

Brad King 9 months ago
parent
commit
f54699d31d
1 changed files with 13 additions and 29 deletions
  1. 13 29
      Source/cmCTest.cxx

+ 13 - 29
Source/cmCTest.cxx

@@ -716,20 +716,6 @@ int cmCTest::ProcessSteps()
   this->Impl->Verbose = true;
   this->Impl->ProduceXML = true;
 
-  std::string const currDir = cmSystemTools::GetLogicalWorkingDirectory();
-  std::string workDir = currDir;
-  if (!this->Impl->TestDir.empty()) {
-    workDir = cmSystemTools::ToNormalizedPathOnDisk(this->Impl->TestDir);
-  }
-
-  cmWorkingDirectory changeDir(workDir);
-  if (changeDir.Failed()) {
-    cmCTestLog(this, ERROR_MESSAGE, changeDir.GetError() << std::endl);
-    return 1;
-  }
-
-  this->Impl->BinaryDir = workDir;
-  cmSystemTools::ConvertToUnixSlashes(this->Impl->BinaryDir);
   this->UpdateCTestConfiguration();
   this->BlockTestErrorDiagnostics();
 
@@ -2648,6 +2634,19 @@ int cmCTest::Run(std::vector<std::string> const& args)
     return this->RunScripts(runScripts);
   }
 
+  // Establish the working directory.
+  std::string const currDir = cmSystemTools::GetLogicalWorkingDirectory();
+  std::string workDir = currDir;
+  if (!this->Impl->TestDir.empty()) {
+    workDir = cmSystemTools::ToNormalizedPathOnDisk(this->Impl->TestDir);
+  }
+  cmWorkingDirectory changeDir(workDir);
+  if (changeDir.Failed()) {
+    cmCTestLog(this, ERROR_MESSAGE, changeDir.GetError() << std::endl);
+    return 1;
+  }
+  this->Impl->BinaryDir = workDir;
+
   // -D, -T, and/or -M was specified
   if (processSteps) {
     return this->ProcessSteps();
@@ -2682,18 +2681,6 @@ int cmCTest::ExecuteTests(std::vector<std::string> const& args)
   this->Impl->ExtraVerbose = this->Impl->Verbose;
   this->Impl->Verbose = true;
 
-  std::string const currDir = cmSystemTools::GetLogicalWorkingDirectory();
-  std::string workDir = currDir;
-  if (!this->Impl->TestDir.empty()) {
-    workDir = cmSystemTools::ToNormalizedPathOnDisk(this->Impl->TestDir);
-  }
-
-  cmWorkingDirectory changeDir(workDir);
-  if (changeDir.Failed()) {
-    cmCTestLog(this, ERROR_MESSAGE, changeDir.GetError() << std::endl);
-    return 1;
-  }
-
   cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);
   if (!this->Impl->InteractiveDebugMode) {
     this->BlockTestErrorDiagnostics();
@@ -2701,9 +2688,6 @@ int cmCTest::ExecuteTests(std::vector<std::string> const& args)
     cmSystemTools::PutEnv("CTEST_INTERACTIVE_DEBUG_MODE=1");
   }
 
-  this->Impl->BinaryDir = workDir;
-  cmSystemTools::ConvertToUnixSlashes(this->Impl->BinaryDir);
-
   this->UpdateCTestConfiguration();
 
   cmCTestLog(this, DEBUG, "Here: " << __LINE__ << std::endl);