cmCTestBuildAndTestHandler: Simplify RunCMakeAndTest signature

Since commit 1a165dc60d (ENH: Move the build-and-test code to a handler,
2005-06-03, v2.4.0~1632), factored RunCMakeAndTest out of cmCTest, its
argument has been unnecessary.  In commit e60e4dfc88
(cmWorkingDirectory: Check success of current dir changes, 2018-03-04,
v3.12.0-rc1~395^2~1) unnecessary branching was added based on the
argument.  Remove both the argument and branching.
This commit is contained in:
Brad King
2024-10-11 09:13:27 -04:00
parent f521d20cb4
commit 270ab612b9
2 changed files with 18 additions and 54 deletions
+15 -51
View File
@@ -34,15 +34,13 @@ const char* cmCTestBuildAndTestHandler::GetOutput()
int cmCTestBuildAndTestHandler::ProcessHandler()
{
this->Output.clear();
std::string output;
cmSystemTools::ResetErrorOccurredFlag();
int retv = this->RunCMakeAndTest(&this->Output);
int retv = this->RunCMakeAndTest();
cmSystemTools::ResetErrorOccurredFlag();
return retv;
}
int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
std::ostringstream& out,
int cmCTestBuildAndTestHandler::RunCMake(std::ostringstream& out,
std::string& cmakeOutString,
cmake* cm)
{
@@ -79,11 +77,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
if (cm->Run(args) != 0) {
out << "Error: cmake execution failed\n";
out << cmakeOutString << "\n";
if (outstring) {
*outstring = out.str();
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str() << std::endl);
}
this->Output = out.str();
return 1;
}
// do another config?
@@ -91,11 +85,7 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
if (cm->Run(args) != 0) {
out << "Error: cmake execution failed\n";
out << cmakeOutString << "\n";
if (outstring) {
*outstring = out.str();
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str() << std::endl);
}
this->Output = out.str();
return 1;
}
}
@@ -144,15 +134,13 @@ public:
const cmCTestBuildAndTestCaptureRAII&) = delete;
};
int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
int cmCTestBuildAndTestHandler::RunCMakeAndTest()
{
// if the generator and make program are not specified then it is an error
if (this->BuildGenerator.empty()) {
if (outstring) {
*outstring = "--build-and-test requires that the generator "
this->Output = "--build-and-test requires that the generator "
"be provided using the --build-generator "
"command line option.\n";
}
return 1;
}
@@ -193,11 +181,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
if (workdir.Failed()) {
auto msg = "Failed to change working directory to " + this->BinaryDir +
" : " + std::strerror(workdir.GetLastResult()) + "\n";
if (outstring) {
*outstring = msg;
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, msg);
}
this->Output = msg;
return 1;
}
@@ -216,7 +200,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
cm.LoadCache(this->BinaryDir);
} else {
// do the cmake step, no timeout here since it is not a sub process
if (this->RunCMake(outstring, out, cmakeOutString, &cm)) {
if (this->RunCMake(out, cmakeOutString, &cm)) {
return 1;
}
}
@@ -231,9 +215,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
remainingTime =
this->Timeout - (std::chrono::steady_clock::now() - clock_start);
if (remainingTime <= std::chrono::seconds(0)) {
if (outstring) {
*outstring = "--build-and-test timeout exceeded. ";
}
this->Output = "--build-and-test timeout exceeded. ";
return 1;
}
}
@@ -253,15 +235,11 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
buildOptions, false, remainingTime);
// if the build failed then return
if (retVal) {
if (outstring) {
*outstring = out.str();
}
this->Output = out.str();
return 1;
}
}
if (outstring) {
*outstring = out.str();
}
this->Output = out.str();
// if no test was specified then we are done
if (this->TestCommand.empty()) {
@@ -291,11 +269,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
for (std::string const& fail : failed) {
out << fail << "\n";
}
if (outstring) {
*outstring = out.str();
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str());
}
this->Output = out.str();
return 1;
}
@@ -312,11 +286,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
if (!workdir.SetDirectory(this->BuildRunDir)) {
out << "Failed to change working directory : "
<< std::strerror(workdir.GetLastResult()) << "\n";
if (outstring) {
*outstring = out.str();
} else {
cmCTestLog(this->CTest, ERROR_MESSAGE, out.str());
}
this->Output = out.str();
return 1;
}
}
@@ -332,9 +302,7 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
remainingTime =
this->Timeout - (std::chrono::steady_clock::now() - clock_start);
if (remainingTime <= std::chrono::seconds(0)) {
if (outstring) {
*outstring = "--build-and-test timeout exceeded. ";
}
this->Output = "--build-and-test timeout exceeded. ";
return 1;
}
}
@@ -348,10 +316,6 @@ int cmCTestBuildAndTestHandler::RunCMakeAndTest(std::string* outstring)
}
out << outs << "\n";
if (outstring) {
*outstring = out.str();
} else {
cmCTestLog(this->CTest, OUTPUT, out.str() << std::endl);
}
this->Output = out.str();
return retval;
}
+3 -3
View File
@@ -38,9 +38,9 @@ public:
protected:
//! Run CMake and build a test and then run it as a single test.
int RunCMakeAndTest(std::string* output);
int RunCMake(std::string* outstring, std::ostringstream& out,
std::string& cmakeOutString, cmake* cm);
int RunCMakeAndTest();
int RunCMake(std::ostringstream& out, std::string& cmakeOutString,
cmake* cm);
std::string Output;