123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295 |
- #include "cmCTestHandlerCommand.h"
- #include "cmCTest.h"
- #include "cmCTestGenericHandler.h"
- #include "cmMakefile.h"
- #include "cmSystemTools.h"
- #include "cmWorkingDirectory.h"
- #include "cmake.h"
- #include <sstream>
- #include <stdlib.h>
- class cmExecutionStatus;
- cmCTestHandlerCommand::cmCTestHandlerCommand()
- {
- const size_t INIT_SIZE = 100;
- size_t cc;
- this->Arguments.reserve(INIT_SIZE);
- for (cc = 0; cc < INIT_SIZE; ++cc) {
- this->Arguments.push_back(nullptr);
- }
- this->Arguments[ct_RETURN_VALUE] = "RETURN_VALUE";
- this->Arguments[ct_CAPTURE_CMAKE_ERROR] = "CAPTURE_CMAKE_ERROR";
- this->Arguments[ct_SOURCE] = "SOURCE";
- this->Arguments[ct_BUILD] = "BUILD";
- this->Arguments[ct_SUBMIT_INDEX] = "SUBMIT_INDEX";
- this->Last = ct_LAST;
- this->AppendXML = false;
- this->Quiet = false;
- }
- namespace {
- class SaveRestoreErrorState
- {
- public:
- SaveRestoreErrorState()
- {
- this->InitialErrorState = cmSystemTools::GetErrorOccuredFlag();
- cmSystemTools::ResetErrorOccuredFlag();
- this->CaptureCMakeErrorValue = false;
- }
-
-
-
- void CaptureCMakeError() { this->CaptureCMakeErrorValue = true; }
- ~SaveRestoreErrorState()
- {
-
-
-
- if (!this->CaptureCMakeErrorValue) {
- if (this->InitialErrorState) {
- cmSystemTools::SetErrorOccured();
- }
- return;
- }
-
-
- bool currentState = cmSystemTools::GetErrorOccuredFlag();
-
-
- if (currentState != this->InitialErrorState) {
-
- if (this->InitialErrorState) {
- cmSystemTools::SetErrorOccured();
- } else {
- cmSystemTools::ResetErrorOccuredFlag();
- }
- }
- }
- private:
- bool InitialErrorState;
- bool CaptureCMakeErrorValue;
- };
- }
- bool cmCTestHandlerCommand::InitialPass(std::vector<std::string> const& args,
- cmExecutionStatus& )
- {
-
- SaveRestoreErrorState errorState;
-
- this->Values.clear();
- this->Values.resize(this->Last, nullptr);
-
- this->ArgumentDoing = ArgumentDoingNone;
-
-
-
- bool foundBadArgument = false;
- for (std::string const& arg : args) {
-
- if (!this->CheckArgumentKeyword(arg) && !this->CheckArgumentValue(arg)) {
- std::ostringstream e;
- e << "called with unknown argument \"" << arg << "\".";
- this->SetError(e.str());
- foundBadArgument = true;
- }
-
- if (this->ArgumentDoing == ArgumentDoingError) {
- foundBadArgument = true;
- }
- }
- bool capureCMakeError = (this->Values[ct_CAPTURE_CMAKE_ERROR] &&
- *this->Values[ct_CAPTURE_CMAKE_ERROR]);
-
-
- if (capureCMakeError) {
- errorState.CaptureCMakeError();
- }
-
- if (foundBadArgument) {
-
- if (capureCMakeError) {
- this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
- "-1");
- std::string const err = this->GetName() + " " + this->GetError();
- if (!cmSystemTools::FindLastString(err.c_str(), "unknown error.")) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n");
- }
-
- return true;
- }
-
- return false;
- }
-
-
-
-
- const char* ctestConfigType =
- this->Makefile->GetDefinition("CTEST_CONFIGURATION_TYPE");
- if (ctestConfigType) {
- this->CTest->SetConfigType(ctestConfigType);
- }
- if (this->Values[ct_BUILD]) {
- this->CTest->SetCTestConfiguration(
- "BuildDirectory",
- cmSystemTools::CollapseFullPath(this->Values[ct_BUILD]).c_str(),
- this->Quiet);
- } else {
- const char* bdir =
- this->Makefile->GetSafeDefinition("CTEST_BINARY_DIRECTORY");
- if (bdir) {
- this->CTest->SetCTestConfiguration(
- "BuildDirectory", cmSystemTools::CollapseFullPath(bdir).c_str(),
- this->Quiet);
- } else {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "CTEST_BINARY_DIRECTORY not set"
- << std::endl;);
- }
- }
- if (this->Values[ct_SOURCE]) {
- cmCTestLog(this->CTest, DEBUG, "Set source directory to: "
- << this->Values[ct_SOURCE] << std::endl);
- this->CTest->SetCTestConfiguration(
- "SourceDirectory",
- cmSystemTools::CollapseFullPath(this->Values[ct_SOURCE]).c_str(),
- this->Quiet);
- } else {
- this->CTest->SetCTestConfiguration(
- "SourceDirectory",
- cmSystemTools::CollapseFullPath(
- this->Makefile->GetSafeDefinition("CTEST_SOURCE_DIRECTORY"))
- .c_str(),
- this->Quiet);
- }
- if (const char* changeId =
- this->Makefile->GetDefinition("CTEST_CHANGE_ID")) {
- this->CTest->SetCTestConfiguration("ChangeId", changeId, this->Quiet);
- }
- cmCTestLog(this->CTest, DEBUG, "Initialize handler" << std::endl;);
- cmCTestGenericHandler* handler = this->InitializeHandler();
- if (!handler) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, "Cannot instantiate test handler "
- << this->GetName() << std::endl);
- if (capureCMakeError) {
- this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
- "-1");
- const char* err = this->GetError();
- if (err && !cmSystemTools::FindLastString(err, "unknown error.")) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, err << " error from command\n");
- }
- return true;
- }
- return false;
- }
- handler->SetAppendXML(this->AppendXML);
- handler->PopulateCustomVectors(this->Makefile);
- if (this->Values[ct_SUBMIT_INDEX]) {
- if (!this->CTest->GetDropSiteCDash() &&
- this->CTest->GetDartVersion() <= 1) {
- cmCTestLog(
- this->CTest, ERROR_MESSAGE,
- "Dart before version 2.0 does not support collecting submissions."
- << std::endl
- << "Please upgrade the server to Dart 2 or higher, or do not use "
- "SUBMIT_INDEX."
- << std::endl);
- } else {
- handler->SetSubmitIndex(atoi(this->Values[ct_SUBMIT_INDEX]));
- }
- }
- cmWorkingDirectory workdir(
- this->CTest->GetCTestConfiguration("BuildDirectory"));
- int res = handler->ProcessHandler();
- if (this->Values[ct_RETURN_VALUE] && *this->Values[ct_RETURN_VALUE]) {
- std::ostringstream str;
- str << res;
- this->Makefile->AddDefinition(this->Values[ct_RETURN_VALUE],
- str.str().c_str());
- }
- this->ProcessAdditionalValues(handler);
-
- if (capureCMakeError) {
- const char* returnString = "0";
- if (cmSystemTools::GetErrorOccuredFlag()) {
- returnString = "-1";
- const char* err = this->GetError();
-
-
- if (err && !cmSystemTools::FindLastString(err, "unknown error.")) {
- cmCTestLog(this->CTest, ERROR_MESSAGE, err);
- }
- }
-
- this->Makefile->AddDefinition(this->Values[ct_CAPTURE_CMAKE_ERROR],
- returnString);
- }
- return true;
- }
- void cmCTestHandlerCommand::ProcessAdditionalValues(cmCTestGenericHandler*)
- {
- }
- bool cmCTestHandlerCommand::CheckArgumentKeyword(std::string const& arg)
- {
-
- if (arg == "APPEND") {
- this->ArgumentDoing = ArgumentDoingNone;
- this->AppendXML = true;
- return true;
- }
- if (arg == "QUIET") {
- this->ArgumentDoing = ArgumentDoingNone;
- this->Quiet = true;
- return true;
- }
-
- for (unsigned int k = 0; k < this->Arguments.size(); ++k) {
- if (this->Arguments[k] && arg == this->Arguments[k]) {
- this->ArgumentDoing = ArgumentDoingKeyword;
- this->ArgumentIndex = k;
- return true;
- }
- }
- return false;
- }
- bool cmCTestHandlerCommand::CheckArgumentValue(std::string const& arg)
- {
- if (this->ArgumentDoing == ArgumentDoingKeyword) {
- this->ArgumentDoing = ArgumentDoingNone;
- unsigned int k = this->ArgumentIndex;
- if (this->Values[k]) {
- std::ostringstream e;
- e << "Called with more than one value for " << this->Arguments[k];
- this->Makefile->IssueMessage(cmake::FATAL_ERROR, e.str());
- this->ArgumentDoing = ArgumentDoingError;
- return true;
- }
- this->Values[k] = arg.c_str();
- cmCTestLog(this->CTest, DEBUG, "Set " << this->Arguments[k] << " to "
- << arg << "\n");
- return true;
- }
- return false;
- }
|