]> granicus.if.org Git - clang/commitdiff
Driver: Executing piped jobs with a single command is easy.
authorDaniel Dunbar <daniel@zuster.org>
Thu, 19 Mar 2009 08:01:45 +0000 (08:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Thu, 19 Mar 2009 08:01:45 +0000 (08:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67295 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Compilation.h
lib/Driver/Compilation.cpp

index eaa57914b822fbb136f7c53fdc6d53ea74a65794..1a6d7b02ea8bfbd9440e368e83ce6f0be1cc3359 100644 (file)
@@ -109,6 +109,11 @@ private:
   void PrintJob(llvm::raw_ostream &OS, const Job &J, 
                 const char *Terminator, bool Quote) const;
 
+  /// ExecuteCommand - Execute an actual command.
+  ///
+  /// \return The result code of the subprocess.
+  int ExecuteCommand(const Command &C) const;
+
   /// ExecuteJob - Execute a single job.
   ///
   /// \return The accumulated result code of the job.
index 5234165ab5bb6d3c6864f7b525fcc3d9a7a6533c..4b323a64577ea7c76fb867425379eb73a61b114f 100644 (file)
@@ -108,32 +108,39 @@ bool Compilation::CleanupFileList(const ArgStringList &Files,
   return Success;
 }
 
+int Compilation::ExecuteCommand(const Command &C) const {
+  llvm::sys::Path Prog(C.getExecutable());
+  const char **Argv = new const char*[C.getArguments().size() + 2];
+  Argv[0] = C.getExecutable();
+  std::copy(C.getArguments().begin(), C.getArguments().end(), Argv+1);
+  Argv[C.getArguments().size() + 1] = 0;
+  
+  if (getDriver().CCCEcho || getArgs().hasArg(options::OPT_v))
+    PrintJob(llvm::errs(), C, "\n", false);
+    
+  std::string Error;
+  int Res = 
+    llvm::sys::Program::ExecuteAndWait(Prog, Argv,
+                                       /*env*/0, /*redirects*/0,
+                                       /*secondsToWait*/0, /*memoryLimit*/0,
+                                       &Error);
+  if (!Error.empty()) {
+    assert(Res && "Error string set with 0 result code!");
+    getDriver().Diag(clang::diag::err_drv_command_failure) << Error;
+  }
+  
+  delete[] Argv;
+  return Res;
+}
+
 int Compilation::ExecuteJob(const Job &J) const {
   if (const Command *C = dyn_cast<Command>(&J)) {
-    llvm::sys::Path Prog(C->getExecutable());
-    const char **Argv = new const char*[C->getArguments().size() + 2];
-    Argv[0] = C->getExecutable();
-    std::copy(C->getArguments().begin(), C->getArguments().end(), Argv+1);
-    Argv[C->getArguments().size() + 1] = 0;
-
-    if (getDriver().CCCEcho || getArgs().hasArg(options::OPT_v))
-      PrintJob(llvm::errs(), J, "\n", false);
-    
-    std::string Error;
-    int Res = 
-      llvm::sys::Program::ExecuteAndWait(Prog, Argv,
-                                         /*env*/0, /*redirects*/0,
-                                         /*secondsToWait*/0, /*memoryLimit*/0,
-                                         &Error);
-    if (!Error.empty()) {
-      assert(Res && "Error string set with 0 result code!");
-      getDriver().Diag(clang::diag::err_drv_command_failure) << Error;
-    }
-    
-    delete[] Argv;
-    return Res;
+    return ExecuteCommand(*C);
   } else if (const PipedJob *PJ = dyn_cast<PipedJob>(&J)) {
-    (void) PJ;
+    // Piped commands with a single job are easy.
+    if (PJ->size() == 1)
+      return ExecuteCommand(**PJ->begin());
+      
     getDriver().Diag(clang::diag::err_drv_unsupported_opt) << "-pipe";
     return 1;
   } else {