From 9619d54003970f9160b31ad6e04c85b1812faf3f Mon Sep 17 00:00:00 2001 From: Andy Cedilnik Date: Wed, 4 May 2005 11:13:35 -0400 Subject: [PATCH] ENH: Improve syntax --- Source/CTest/cmCTestBuildCommand.cxx | 61 +++++++++++++++++++---- Source/CTest/cmCTestBuildCommand.h | 2 +- Source/CTest/cmCTestConfigureCommand.cxx | 62 +++++++++++++++++++---- Source/CTest/cmCTestConfigureCommand.h | 2 +- Source/CTest/cmCTestCoverageHandler.cxx | 8 +-- Source/CTest/cmCTestSubmitCommand.cxx | 41 +++++++++++---- Source/CTest/cmCTestSubmitCommand.h | 2 +- Source/CTest/cmCTestTestCommand.cxx | 63 +++++++++++++++++++----- Source/CTest/cmCTestTestCommand.h | 2 +- Source/CTest/cmCTestUpdateCommand.cxx | 63 +++++++++++++++++++----- Source/CTest/cmCTestUpdateCommand.h | 2 +- 11 files changed, 248 insertions(+), 60 deletions(-) diff --git a/Source/CTest/cmCTestBuildCommand.cxx b/Source/CTest/cmCTestBuildCommand.cxx index 0f9b309b2..d8f1ef7bc 100644 --- a/Source/CTest/cmCTestBuildCommand.cxx +++ b/Source/CTest/cmCTestBuildCommand.cxx @@ -24,16 +24,55 @@ bool cmCTestBuildCommand::InitialPass( std::vector const& args) { - if (args.size() != 2) + const char* build_dir = 0; + const char* res_var = 0; + + bool havereturn_variable = false; + bool havesource = false; + for(size_t i=0; i < args.size(); ++i) { - this->SetError("called with incorrect number of arguments"); - return false; + if ( havereturn_variable ) + { + res_var = args[i].c_str(); + havereturn_variable = false; + } + else if ( havesource ) + { + build_dir = args[i].c_str(); + havesource = false; + } + else if(args[i] == "RETURN_VALUE") + { + if ( res_var ) + { + this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice."); + return false; + } + havereturn_variable = true; + } + else if(args[i] == "BUILD") + { + if ( build_dir ) + { + this->SetError("called with incorrect number of arguments. BUILD specified twice."); + return false; + } + havesource = true; + } + else + { + cmOStringStream str; + str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << "."; + this->SetError(str.str().c_str()); + return false; + } } - const char* build_dir = args[0].c_str(); - const char* res_var = args[1].c_str(); + if ( build_dir ) + { + m_CTest->SetCTestConfiguration("BuildDirectory", build_dir); + } - m_CTest->SetCTestConfiguration("BuildDirectory", build_dir); cmCTestGenericHandler* handler = m_CTest->GetHandler("build"); if ( !handler ) { @@ -62,7 +101,6 @@ bool cmCTestBuildCommand::InitialPass( m_Makefile->GetCMakeInstance()->CreateGlobalGenerator(cmakeGeneratorName); gen->FindMakeProgram(m_Makefile); const char* cmakeMakeProgram = m_Makefile->GetDefinition("CMAKE_MAKE_PROGRAM"); - std::cout << "CMake Make program is: " << cmakeMakeProgram << std::endl; std::string buildCommand = gen->GenerateBuildCommand(cmakeMakeProgram, cmakeProjectName, 0, cmakeBuildConfiguration, true); @@ -78,9 +116,12 @@ bool cmCTestBuildCommand::InitialPass( } int res = handler->ProcessHandler(); - cmOStringStream str; - str << res; - m_Makefile->AddDefinition(res_var, str.str().c_str()); + if ( res_var ) + { + cmOStringStream str; + str << res; + m_Makefile->AddDefinition(res_var, str.str().c_str()); + } return true; } diff --git a/Source/CTest/cmCTestBuildCommand.h b/Source/CTest/cmCTestBuildCommand.h index 82f87a4cb..4284a0813 100644 --- a/Source/CTest/cmCTestBuildCommand.h +++ b/Source/CTest/cmCTestBuildCommand.h @@ -66,7 +66,7 @@ public: virtual const char* GetFullDocumentation() { return - " CTEST_BUILD(build_dir res)\n" + " CTEST_BUILD([BUILD build_dir] [RETURN_VALUE res])\n" "Builds the given build directory and stores results in Build.xml."; } diff --git a/Source/CTest/cmCTestConfigureCommand.cxx b/Source/CTest/cmCTestConfigureCommand.cxx index 7fd1e500e..2925cad69 100644 --- a/Source/CTest/cmCTestConfigureCommand.cxx +++ b/Source/CTest/cmCTestConfigureCommand.cxx @@ -22,17 +22,56 @@ bool cmCTestConfigureCommand::InitialPass( std::vector const& args) { - if (args.size() != 2) + const char* build_dir = 0; + const char* res_var = 0; + + bool havereturn_variable = false; + bool havesource = false; + for(size_t i=0; i < args.size(); ++i) { - this->SetError("called with incorrect number of arguments"); - return false; + if ( havereturn_variable ) + { + res_var = args[i].c_str(); + havereturn_variable = false; + } + else if ( havesource ) + { + build_dir = args[i].c_str(); + havesource = false; + } + else if(args[i] == "RETURN_VALUE") + { + if ( res_var ) + { + this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice."); + return false; + } + havereturn_variable = true; + } + else if(args[i] == "BUILD") + { + if ( build_dir ) + { + this->SetError("called with incorrect number of arguments. BUILD specified twice."); + return false; + } + havesource = true; + } + else + { + cmOStringStream str; + str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << "."; + this->SetError(str.str().c_str()); + return false; + } } - const char* build_dir = args[0].c_str(); - const char* res_var = args[1].c_str(); - m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "ConfigureCommand", "CTEST_CONFIGURE_COMMAND"); - m_CTest->SetCTestConfiguration("BuildDirectory", build_dir); + + if ( build_dir ) + { + m_CTest->SetCTestConfiguration("BuildDirectory", build_dir); + } cmCTestGenericHandler* handler = m_CTest->GetHandler("configure"); if ( !handler ) @@ -41,9 +80,12 @@ bool cmCTestConfigureCommand::InitialPass( return false; } int res = handler->ProcessHandler(); - cmOStringStream str; - str << res; - m_Makefile->AddDefinition(res_var, str.str().c_str()); + if ( res_var ) + { + cmOStringStream str; + str << res; + m_Makefile->AddDefinition(res_var, str.str().c_str()); + } return true; } diff --git a/Source/CTest/cmCTestConfigureCommand.h b/Source/CTest/cmCTestConfigureCommand.h index bd7c00ca5..8508898cf 100644 --- a/Source/CTest/cmCTestConfigureCommand.h +++ b/Source/CTest/cmCTestConfigureCommand.h @@ -66,7 +66,7 @@ public: virtual const char* GetFullDocumentation() { return - " CTEST_CONFIGURE(build_dir res)\n" + " CTEST_CONFIGURE(BUILD build_dir RETURN_VALUE res)\n" "Configures the given build directory and stores results in Configure.xml. The " "second argument is a variable that will hold return value."; } diff --git a/Source/CTest/cmCTestCoverageHandler.cxx b/Source/CTest/cmCTestCoverageHandler.cxx index f5872eaed..de42576e4 100644 --- a/Source/CTest/cmCTestCoverageHandler.cxx +++ b/Source/CTest/cmCTestCoverageHandler.cxx @@ -165,8 +165,8 @@ int cmCTestCoverageHandler::ProcessHandler() cmSystemTools::ConvertToUnixSlashes(sourceDir); cmSystemTools::ConvertToUnixSlashes(binaryDir); - std::string asfGlob = sourceDir + "/*"; - std::string abfGlob = binaryDir + "/*"; + //std::string asfGlob = sourceDir + "/*"; + //std::string abfGlob = binaryDir + "/*"; std::string daGlob = binaryDir + "/*.da"; std::string gcovOutputRex = "[0-9]+\\.[0-9]+% of [0-9]+ (source |)lines executed in file (.*)$"; std::string gcovOutputRex2 = "^Creating (.*\\.gcov)\\."; @@ -347,8 +347,8 @@ int cmCTestCoverageHandler::ProcessHandler() int cnt = 0; long total_tested = 0; long total_untested = 0; - std::string fullSourceDir = sourceDir + "/"; - std::string fullBinaryDir = binaryDir + "/"; + //std::string fullSourceDir = sourceDir + "/"; + //std::string fullBinaryDir = binaryDir + "/"; for ( fileIterator = totalCoverage.begin(); fileIterator != totalCoverage.end(); ++fileIterator ) diff --git a/Source/CTest/cmCTestSubmitCommand.cxx b/Source/CTest/cmCTestSubmitCommand.cxx index 72fccb8b9..4e0d74aee 100644 --- a/Source/CTest/cmCTestSubmitCommand.cxx +++ b/Source/CTest/cmCTestSubmitCommand.cxx @@ -22,13 +22,33 @@ bool cmCTestSubmitCommand::InitialPass( std::vector const& args) { - if (args.size() != 1) - { - this->SetError("called with incorrect number of arguments"); - return false; - } + const char* res_var = 0; - const char* res_var = args[0].c_str(); + bool havereturn_variable = false; + for(size_t i=0; i < args.size(); ++i) + { + if ( havereturn_variable ) + { + res_var = args[i].c_str(); + havereturn_variable = false; + } + else if(args[i] == "RETURN_VALUE") + { + if ( res_var ) + { + this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice."); + return false; + } + havereturn_variable = true; + } + else + { + cmOStringStream str; + str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << "."; + this->SetError(str.str().c_str()); + return false; + } + } m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropMethod", "CTEST_DROP_METHOD"); m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "DropSite", "CTEST_DROP_SITE"); @@ -45,9 +65,12 @@ bool cmCTestSubmitCommand::InitialPass( return false; } int res = handler->ProcessHandler(); - cmOStringStream str; - str << res; - m_Makefile->AddDefinition(res_var, str.str().c_str()); + if ( res_var ) + { + cmOStringStream str; + str << res; + m_Makefile->AddDefinition(res_var, str.str().c_str()); + } return true; } diff --git a/Source/CTest/cmCTestSubmitCommand.h b/Source/CTest/cmCTestSubmitCommand.h index e71d34ca8..8eb077165 100644 --- a/Source/CTest/cmCTestSubmitCommand.h +++ b/Source/CTest/cmCTestSubmitCommand.h @@ -66,7 +66,7 @@ public: virtual const char* GetFullDocumentation() { return - " CTEST_SUBMIT(res)\n" + " CTEST_SUBMIT([RETURN_VALUE res])\n" "Submits the test results for the project."; } diff --git a/Source/CTest/cmCTestTestCommand.cxx b/Source/CTest/cmCTestTestCommand.cxx index c0a48f342..38b705144 100644 --- a/Source/CTest/cmCTestTestCommand.cxx +++ b/Source/CTest/cmCTestTestCommand.cxx @@ -22,16 +22,54 @@ bool cmCTestTestCommand::InitialPass( std::vector const& args) { - if (args.size() != 2) + const char* build_dir = 0; + const char* res_var = 0; + + bool havereturn_variable = false; + bool havesource = false; + for(size_t i=0; i < args.size(); ++i) { - this->SetError("called with incorrect number of arguments"); - return false; + if ( havereturn_variable ) + { + res_var = args[i].c_str(); + havereturn_variable = false; + } + else if ( havesource ) + { + build_dir = args[i].c_str(); + havesource = false; + } + else if(args[i] == "RETURN_VALUE") + { + if ( res_var ) + { + this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice."); + return false; + } + havereturn_variable = true; + } + else if(args[i] == "BUILD") + { + if ( build_dir ) + { + this->SetError("called with incorrect number of arguments. BUILD specified twice."); + return false; + } + havesource = true; + } + else + { + cmOStringStream str; + str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << "."; + this->SetError(str.str().c_str()); + return false; + } } - const char* build_dir = args[0].c_str(); - const char* res_var = args[1].c_str(); - - m_CTest->SetCTestConfiguration("BuildDirectory", build_dir); + if ( build_dir ) + { + m_CTest->SetCTestConfiguration("BuildDirectory", build_dir); + } cmCTestGenericHandler* handler = m_CTest->GetHandler("test"); if ( !handler ) @@ -40,12 +78,15 @@ bool cmCTestTestCommand::InitialPass( return false; } std::string current_dir = cmSystemTools::GetCurrentWorkingDirectory(); - cmSystemTools::ChangeDirectory(build_dir); + cmSystemTools::ChangeDirectory(m_CTest->GetCTestConfiguration("BuildDirectory").c_str()); int res = handler->ProcessHandler(); + if ( res_var ) + { + cmOStringStream str; + str << res; + m_Makefile->AddDefinition(res_var, str.str().c_str()); + } cmSystemTools::ChangeDirectory(current_dir.c_str()); - cmOStringStream str; - str << res; - m_Makefile->AddDefinition(res_var, str.str().c_str()); return true; } diff --git a/Source/CTest/cmCTestTestCommand.h b/Source/CTest/cmCTestTestCommand.h index 907cb543e..c0e6bf3f9 100644 --- a/Source/CTest/cmCTestTestCommand.h +++ b/Source/CTest/cmCTestTestCommand.h @@ -66,7 +66,7 @@ public: virtual const char* GetFullDocumentation() { return - " CTEST_TEST(build_dir res)\n" + " CTEST_TEST([BUILD build_dir] [RETURN_VALUE res])\n" "Tests the given build directory and stores results in Test.xml. The " "second argument is a variable that will hold value."; } diff --git a/Source/CTest/cmCTestUpdateCommand.cxx b/Source/CTest/cmCTestUpdateCommand.cxx index d8ba8661c..c0e00ae3d 100644 --- a/Source/CTest/cmCTestUpdateCommand.cxx +++ b/Source/CTest/cmCTestUpdateCommand.cxx @@ -22,14 +22,49 @@ bool cmCTestUpdateCommand::InitialPass( std::vector const& args) { - if (args.size() != 2) - { - this->SetError("called with incorrect number of arguments"); - return false; - } + const char* source_dir = 0; + const char* res_var = 0; - const char* source_dir = args[0].c_str(); - const char* res_var = args[1].c_str(); + bool havereturn_variable = false; + bool havesource = false; + for(size_t i=0; i < args.size(); ++i) + { + if ( havereturn_variable ) + { + res_var = args[i].c_str(); + havereturn_variable = false; + } + else if ( havesource ) + { + source_dir = args[i].c_str(); + havesource = false; + } + else if(args[i] == "RETURN_VALUE") + { + if ( res_var ) + { + this->SetError("called with incorrect number of arguments. RETURN_VALUE specified twice."); + return false; + } + havereturn_variable = true; + } + else if(args[i] == "SOURCE") + { + if ( source_dir ) + { + this->SetError("called with incorrect number of arguments. SOURCE specified twice."); + return false; + } + havesource = true; + } + else + { + cmOStringStream str; + str << "called with incorrect number of arguments. Extra argument is: " << args[i].c_str() << "."; + this->SetError(str.str().c_str()); + return false; + } + } m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "CVSCommand", "CTEST_CVS_COMMAND"); m_CTest->SetCTestConfigurationFromCMakeVariable(m_Makefile, "SVNCommand", "CTEST_SVN_COMMAND"); @@ -40,11 +75,17 @@ bool cmCTestUpdateCommand::InitialPass( this->SetError("internal CTest error. Cannot instantiate update handler"); return false; } - handler->SetOption("SourceDirectory", source_dir); + if ( source_dir ) + { + handler->SetOption("SourceDirectory", source_dir); + } int res = handler->ProcessHandler(); - cmOStringStream str; - str << res; - m_Makefile->AddDefinition(res_var, str.str().c_str()); + if ( res_var ) + { + cmOStringStream str; + str << res; + m_Makefile->AddDefinition(res_var, str.str().c_str()); + } return true; } diff --git a/Source/CTest/cmCTestUpdateCommand.h b/Source/CTest/cmCTestUpdateCommand.h index ace980ec8..543e4b586 100644 --- a/Source/CTest/cmCTestUpdateCommand.h +++ b/Source/CTest/cmCTestUpdateCommand.h @@ -66,7 +66,7 @@ public: virtual const char* GetFullDocumentation() { return - " CTEST_UPDATE(source res)\n" + " CTEST_UPDATE([SOURCE source] [RETURN_VALUE res])\n" "Updates the given source directory and stores results in Update.xml. The " "second argument is a variable that will hold the number of files " "modified. If there is a problem, the variable will be -1.";