r273997 - [Driver] Add method to redirect output of Compilation.

Nikolay Haustov via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 28 01:00:43 PDT 2016


Author: nhaustov
Date: Tue Jun 28 03:00:42 2016
New Revision: 273997

URL: http://llvm.org/viewvc/llvm-project?rev=273997&view=rev
Log:
[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

Modified:
    cfe/trunk/include/clang/Driver/Compilation.h
    cfe/trunk/lib/Driver/Compilation.cpp

Modified: cfe/trunk/include/clang/Driver/Compilation.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Compilation.h?rev=273997&r1=273996&r2=273997&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Compilation.h (original)
+++ cfe/trunk/include/clang/Driver/Compilation.h Tue Jun 28 03:00:42 2016
@@ -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

Modified: cfe/trunk/lib/Driver/Compilation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Compilation.cpp?rev=273997&r1=273996&r2=273997&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Compilation.cpp (original)
+++ cfe/trunk/lib/Driver/Compilation.cpp Tue Jun 28 03:00:42 2016
@@ -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::initCompilationForDiag
 StringRef Compilation::getSysRoot() const {
   return getDriver().SysRoot;
 }
+
+void Compilation::Redirect(const StringRef** Redirects) {
+  this->Redirects = Redirects;
+}




More information about the cfe-commits mailing list