Selaa lähdekoodia

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.
Brad King 14 vuotta sitten
vanhempi
sitoutus
c45c60b24f
3 muutettua tiedostoa jossa 20 lisäystä ja 3 poistoa
  1. 16 0
      Source/cmSystemTools.cxx
  2. 2 0
      Source/cmSystemTools.h
  3. 2 3
      Tests/CMakeLib/run_compile_commands.cxx

+ 16 - 0
Source/cmSystemTools.cxx

@@ -440,6 +440,13 @@ public:
       args.push_back(*arg);
       }
     }
+  void Store(std::vector<cmStdString>& 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<cmStdString>& 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)
 {

+ 2 - 0
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<std::string>& args);
+  static void ParseUnixCommandLine(const char* command,
+                                   std::vector<cmStdString>& args);
 
   /** Compute an escaped version of the given argument for use in a
       windows shell.  See kwsys/System.h.in for details.  */

+ 2 - 3
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::string> std_command;
-    cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), std_command);
-    std::vector<cmStdString> command(std_command.begin(), std_command.end());
+    std::vector<cmStdString> command;
+    cmSystemTools::ParseUnixCommandLine(it->at("command").c_str(), command);
     if (!cmSystemTools::RunSingleCommand(
             command, 0, 0, it->at("directory").c_str()))
       {