Skip to content

Commit

Permalink
[Driver] Add method to redirect output of Compilation.
Browse files Browse the repository at this point in the history
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

llvm-svn: 273997
  • Loading branch information
Nikolay Haustov authored and Nikolay Haustov committed Jun 28, 2016
1 parent 3e176c7 commit 9c366cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/include/clang/Driver/Compilation.h
Expand Up @@ -252,6 +252,15 @@ class Compilation {

/// 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
Expand Down
5 changes: 5 additions & 0 deletions clang/lib/Driver/Compilation.cpp
Expand Up @@ -45,6 +45,7 @@ Compilation::~Compilation() {

// Free redirections of stdout/stderr.
if (Redirects) {
delete Redirects[0];
delete Redirects[1];
delete Redirects[2];
delete [] Redirects;
Expand Down Expand Up @@ -213,3 +214,7 @@ void Compilation::initCompilationForDiagnostics() {
StringRef Compilation::getSysRoot() const {
return getDriver().SysRoot;
}

void Compilation::Redirect(const StringRef** Redirects) {
this->Redirects = Redirects;
}

0 comments on commit 9c366cd

Please sign in to comment.