From c45c60b24ff52d9435ceab0de027fbadac130a1f Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 18 May 2011 09:44:28 -0400 Subject: [PATCH] run_compile_commands: Avoid extra stl vector conversion The Sun compiler does not provide the proper vector constructor to initialize it from an iterator pair of a non-matching type. Extend the ParseUnixCommandLine API to provide a vector of the proper type so no conversion is needed. --- Source/cmSystemTools.cxx | 16 ++++++++++++++++ Source/cmSystemTools.h | 2 ++ Tests/CMakeLib/run_compile_commands.cxx | 5 ++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 7bc89a4c49..df6469f5b1 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -440,6 +440,13 @@ public: args.push_back(*arg); } } + void Store(std::vector& args) const + { + for(char** arg = this->ArgV; arg && *arg; ++arg) + { + args.push_back(*arg); + } + } }; //---------------------------------------------------------------------------- @@ -451,6 +458,15 @@ void cmSystemTools::ParseUnixCommandLine(const char* command, argv.Store(args); } +//---------------------------------------------------------------------------- +void cmSystemTools::ParseUnixCommandLine(const char* command, + std::vector& args) +{ + // Invoke the underlying parser. + cmSystemToolsArgV argv = cmsysSystem_Parse_CommandForUnix(command, 0); + argv.Store(args); +} + std::string cmSystemTools::EscapeWindowsShellArgument(const char* arg, int shell_flags) { diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 6f9147c318..dfc6b7df06 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -237,6 +237,8 @@ public: /** Parse arguments out of a unix command line string. */ static void ParseUnixCommandLine(const char* command, std::vector& args); + static void ParseUnixCommandLine(const char* command, + std::vector& args); /** Compute an escaped version of the given argument for use in a windows shell. See kwsys/System.h.in for details. */ diff --git a/Tests/CMakeLib/run_compile_commands.cxx b/Tests/CMakeLib/run_compile_commands.cxx index cfb7ecec4f..a0be2eb631 100644 --- a/Tests/CMakeLib/run_compile_commands.cxx +++ b/Tests/CMakeLib/run_compile_commands.cxx @@ -127,9 +127,8 @@ int main () it = parser.GetTranslationUnits().begin(), end = parser.GetTranslationUnits().end(); it != end; ++it) { - std::vector std_command; - cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), std_command); - std::vector command(std_command.begin(), std_command.end()); + std::vector command; + cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command); if (!cmSystemTools::RunSingleCommand( command, 0, 0, it->at("directory").c_str())) {