aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Compilation.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-18 22:16:03 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-18 22:16:03 +0000
commite530ad407af4a8904377592bfdb236acd320c6c2 (patch)
tree0ea82e8f5c7cece34a8449f36714c1bd6652366c /lib/Driver/Compilation.cpp
parentec099f1f9d1384cec624944744a9fe92df4b389b (diff)
Driver: Cleanup temporary/result files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67248 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Compilation.cpp')
-rw-r--r--lib/Driver/Compilation.cpp48
1 files changed, 46 insertions, 2 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp
index 364f328157..0bd573856e 100644
--- a/lib/Driver/Compilation.cpp
+++ b/lib/Driver/Compilation.cpp
@@ -11,14 +11,19 @@
#include "clang/Driver/Action.h"
#include "clang/Driver/ArgList.h"
+#include "clang/Driver/Driver.h"
+#include "clang/Driver/DriverDiagnostic.h"
#include "clang/Driver/ToolChain.h"
#include "llvm/Support/raw_ostream.h"
+#include <sys/stat.h>
+#include <errno.h>
using namespace clang::driver;
-Compilation::Compilation(ToolChain &_DefaultToolChain,
+Compilation::Compilation(Driver &D,
+ ToolChain &_DefaultToolChain,
ArgList *_Args)
- : DefaultToolChain(_DefaultToolChain), Args(_Args) {
+ : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args) {
}
Compilation::~Compilation() {
@@ -69,12 +74,51 @@ void Compilation::PrintJob(llvm::raw_ostream &OS, const Job *J,
}
}
+bool Compilation::CleanupFileList(const ArgStringList &Files,
+ bool IssueErrors) const {
+ bool Success = true;
+
+ for (ArgStringList::const_iterator
+ it = Files.begin(), ie = Files.end(); it != ie; ++it) {
+ llvm::sys::Path P(*it);
+ std::string Error;
+
+ if (P.eraseFromDisk(false, &Error)) {
+ // Failure is only failure if the file doesn't exist. There is a
+ // race condition here due to the limited interface of
+ // llvm::sys::Path, we want to know if the removal gave E_NOENT.
+
+ // FIXME: Grumble, P.exists() is broken. PR3837.
+ struct stat buf;
+ if (::stat(P.c_str(), &buf) || errno != ENOENT) {
+ if (IssueErrors)
+ getDriver().Diag(clang::diag::err_drv_unable_to_remove_file)
+ << Error;
+ Success = false;
+ }
+ }
+ }
+
+ return Success;
+}
+
int Compilation::Execute() const {
// Just print if -### was present.
if (getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
PrintJob(llvm::errs(), &Jobs, "\n");
return 0;
}
+
+ // FIXME: Execute.
+
+ int Res = 0;
+ // Remove temp files.
+ CleanupFileList(TempFiles);
+
+ // If the compilation failed, remove result files as well.
+ if (Res != 0)
+ CleanupFileList(ResultFiles, true);
+
return 0;
}