From f54699d31d482be87bb366d89ef2a4410544e04b Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 6 Mar 2025 09:11:14 -0500 Subject: [PATCH] cmCTest: De-duplicate working directory code --- Source/cmCTest.cxx | 42 +++++++++++++----------------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index 75ddcc9503..0a77b3842c 100644 --- a/Source/cmCTest.cxx +++ b/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 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 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 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);