1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-14 10:47:59 +08:00

cmCTest: De-duplicate working directory code

This commit is contained in:
Brad King
2025-03-06 09:11:14 -05:00
parent 2b0d0b1544
commit f54699d31d

View File

@@ -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);