Driver: Executing piped jobs with a single command is easy.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67295 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h
index eaa5791..1a6d7b0 100644
--- a/include/clang/Driver/Compilation.h
+++ b/include/clang/Driver/Compilation.h
@@ -109,6 +109,11 @@
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.
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp
index 5234165..4b323a6 100644
--- a/lib/Driver/Compilation.cpp
+++ b/lib/Driver/Compilation.cpp
@@ -108,32 +108,39 @@
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 {