From 6e28861c188316ead00c750cb71b130237179812 Mon Sep 17 00:00:00 2001 From: Alexander Neundorf Date: Tue, 12 Jun 2007 10:56:40 -0400 Subject: ENH: remove non/scriptable cmake commands from the script handler in ctest, as discussed with David. This also gives a better ctest man page with just the commands you should actually use in ctest scripts. Until now these commands were more or less executed, but e.g. add_executable() didn't create an executable, project() failed with an error. Now you get an error instantly if using one of these commands. Alex --- Source/CTest/cmCTestScriptHandler.cxx | 21 +++++++++++++++++++++ Source/cmake.cxx | 11 +++++++++++ Source/cmake.h | 1 + 3 files changed, 33 insertions(+) diff --git a/Source/CTest/cmCTestScriptHandler.cxx b/Source/CTest/cmCTestScriptHandler.cxx index e8d4029..da7e7c5 100644 --- a/Source/CTest/cmCTestScriptHandler.cxx +++ b/Source/CTest/cmCTestScriptHandler.cxx @@ -301,6 +301,27 @@ void cmCTestScriptHandler::CreateCMake() this->LocalGenerator->SetGlobalGenerator(this->GlobalGenerator); this->Makefile = this->LocalGenerator->GetMakefile(); + // remove all cmake commands which are not scriptable, since they can't be + // used in ctest scripts + std::vector unscriptableCommands; + cmake::RegisteredCommandsMap* commands = this->CMake->GetCommands(); + for (cmake::RegisteredCommandsMap::const_iterator pos = commands->begin(); + pos != commands->end(); + ++pos) + { + if (!pos->second->IsScriptable()) + { + unscriptableCommands.push_back(pos->first); + } + } + + for(std::vector::const_iterator it=unscriptableCommands.begin(); + it != unscriptableCommands.end(); + ++it) + { +// fprintf(stderr, "Removing %s\n", it->c_str()); + this->CMake->RemoveCommand(it->c_str()); + } // add any ctest specific commands, probably should have common superclass // for ctest commands to clean this up. If a couple more commands are diff --git a/Source/cmake.cxx b/Source/cmake.cxx index a040b55..664108e 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -260,6 +260,17 @@ void cmake::RenameCommand(const char*oldName, const char* newName) this->Commands.erase(pos); } +void cmake::RemoveCommand(const char* name) +{ + std::string sName = cmSystemTools::LowerCase(name); + RegisteredCommandsMap::iterator pos = this->Commands.find(sName); + if ( pos != this->Commands.end() ) + { + delete pos->second; + this->Commands.erase(pos); + } +} + void cmake::AddCommand(cmCommand* wg) { std::string name = cmSystemTools::LowerCase(wg->GetName()); diff --git a/Source/cmake.h b/Source/cmake.h index 5149d82..9edbd67 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -193,6 +193,7 @@ class cmake */ void AddCommand(cmCommand* ); void RenameCommand(const char* oldName, const char* newName); + void RemoveCommand(const char* name); /** * Get a command by its name -- cgit v0.12