]> granicus.if.org Git - clang/commitdiff
[Driver] Add method to redirect output of Compilation.
authorNikolay Haustov <Nikolay.Haustov@amd.com>
Tue, 28 Jun 2016 08:00:42 +0000 (08:00 +0000)
committerNikolay Haustov <Nikolay.Haustov@amd.com>
Tue, 28 Jun 2016 08:00:42 +0000 (08:00 +0000)
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

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

index af5440d5536940921f2a060b18e373249cc4ca6d..ea84a93cf284b25d3e3aec01ea396a89db662966 100644 (file)
@@ -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
index 46548e638a30518d98e6d88539cf9b3127ef1c79..6a2616f0c2a4d03e3d95269753e55bdd185e4721 100644 (file)
@@ -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;
+}