diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index d3ab2efda..8643cb3f7 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -435,6 +435,15 @@ int cmCTestScriptHandler::ReadInScript(const std::string& total_script_arg) return 2; } + // Add definitions of variables passed in on the command line: + const std::map &defs = + this->CTest->GetDefinitions(); + for (std::map::const_iterator it = defs.begin(); + it != defs.end(); ++it) + { + this->Makefile->AddDefinition(it->first.c_str(), it->second.c_str()); + } + // finally read in the script if (!this->Makefile->ReadListFile(0, script.c_str()) || cmSystemTools::GetErrorOccuredFlag()) diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index cc4a34115..05e823768 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -2229,6 +2229,22 @@ void cmCTest::HandleScriptArguments(size_t &i, } } +//---------------------------------------------------------------------- +bool cmCTest::AddVariableDefinition(const std::string &arg) +{ + std::string name; + std::string value; + cmCacheManager::CacheEntryType type = cmCacheManager::UNINITIALIZED; + + if (cmCacheManager::ParseEntry(arg.c_str(), name, value, type)) + { + this->Definitions[name] = value; + return true; + } + + return false; +} + //---------------------------------------------------------------------- // the main entry point of ctest, called from main int cmCTest::Run(std::vector &args, std::string* output) @@ -2265,8 +2281,11 @@ int cmCTest::Run(std::vector &args, std::string* output) // into the separate stages if (!this->AddTestsForDashboardType(targ)) { - this->ErrorMessageUnknownDashDValue(targ); - executeTests = false; + if (!this->AddVariableDefinition(targ)) + { + this->ErrorMessageUnknownDashDValue(targ); + executeTests = false; + } } } diff --git a/Source/cmCTest.h b/Source/cmCTest.h index 68811f8d9..beffe9e7a 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -418,6 +418,11 @@ public: std::string GetCostDataFile(); + const std::map &GetDefinitions() + { + return this->Definitions; + } + private: std::string ConfigType; std::string ScheduleType; @@ -520,6 +525,9 @@ private: //! read as "emit an error message for an unknown -D value" void ErrorMessageUnknownDashDValue(std::string &val); + //! add a variable definition from a command line -D value + bool AddVariableDefinition(const std::string &arg); + //! parse and process most common command line arguments void HandleCommandLineArguments(size_t &i, std::vector &args); @@ -562,6 +570,8 @@ private: int OutputLogFileLastTag; bool OutputTestOutputOnTestFailure; + + std::map Definitions; }; class cmCTestLogWrite diff --git a/Source/ctest.cxx b/Source/ctest.cxx index d41627e26..d65077748 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -103,6 +103,12 @@ static const char * cmDocumentationOptions[][3] = "a dashboard test. All tests are , where Mode can be " "Experimental, Nightly, and Continuous, and Test can be Start, Update, " "Configure, Build, Test, Coverage, and Submit."}, + {"-D :=", "Define a variable for script mode", + "Pass in variable values on the command line. Use in " + "conjunction with -S to pass variable values to a dashboard script. " + "Parsing -D arguments as variable values is only attempted if " + "the value following -D does not match any of the known dashboard " + "types."}, {"-M , --test-model ", "Sets the model for a dashboard", "This option tells ctest to act as a Dart client " "where the TestModel can be Experimental, "