From: Nikolay Haustov Date: Tue, 28 Jun 2016 08:00:42 +0000 (+0000) Subject: [Driver] Add method to redirect output of Compilation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e6404a0de8f82c7e8e9b580a80d4af9cae0ebeee;p=clang [Driver] Add method to redirect output of Compilation. Summary: Currently output of child process, however in my use case, it needs to be captured and presented to the user. Add Redirect method to Compilation and use existing infrastructure for redirecting output of commands. Reviewers: tstellarAMD Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D21224 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273997 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h index af5440d553..ea84a93cf2 100644 --- a/include/clang/Driver/Compilation.h +++ b/include/clang/Driver/Compilation.h @@ -252,6 +252,15 @@ public: /// Return true if we're compiling for diagnostics. bool isForDiagnostics() const { return ForDiagnostics; } + + /// Redirect - Redirect output of this compilation. Can only be done once. + /// + /// \param Redirects - array of pointers to paths. The array + /// should have a size of three. The inferior process's + /// stdin(0), stdout(1), and stderr(2) will be redirected to the + /// corresponding paths. This compilation instance becomes + /// the owner of Redirects and will delete the array and StringRef's. + void Redirect(const StringRef** Redirects); }; } // end namespace driver diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 46548e638a..6a2616f0c2 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -45,6 +45,7 @@ Compilation::~Compilation() { // Free redirections of stdout/stderr. if (Redirects) { + delete Redirects[0]; delete Redirects[1]; delete Redirects[2]; delete [] Redirects; @@ -213,3 +214,7 @@ void Compilation::initCompilationForDiagnostics() { StringRef Compilation::getSysRoot() const { return getDriver().SysRoot; } + +void Compilation::Redirect(const StringRef** Redirects) { + this->Redirects = Redirects; +}