diff options
author | Chad Rosier <mcrosier@apple.com> | 2013-01-24 19:14:47 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2013-01-24 19:14:47 +0000 |
commit | 9d718635fa805674aaba5d938f3dc6b35b8632ba (patch) | |
tree | 3d1dd9b5933e22a130dcdc9e70834934ec3c5c96 /lib/Driver/Compilation.cpp | |
parent | 51d8c52ad36129760eaa586f85176037e2cd0d0e (diff) |
[driver] Associate a JobAction with each result file. This enables the driver
to delete result files for only those commands that fail.
Part of rdar://12984531
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173361 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Compilation.cpp')
-rw-r--r-- | lib/Driver/Compilation.cpp | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 9c7100fb80..96e6048551 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -199,39 +199,56 @@ void Compilation::PrintDiagnosticJob(raw_ostream &OS, const Job &J) const { } } +bool Compilation::CleanupFile(const char *File, bool IssueErrors) const { + llvm::sys::Path P(File); + std::string Error; + + // Don't try to remove files which we don't have write access to (but may be + // able to remove), or non-regular files. Underlying tools may have + // intentionally not overwritten them. + if (!P.canWrite() || !P.isRegularFile()) + return true; + + if (P.eraseFromDisk(false, &Error)) { + // Failure is only failure if the file exists and is "regular". There is + // a race condition here due to the limited interface of + // llvm::sys::Path, we want to know if the removal gave ENOENT. + + // FIXME: Grumble, P.exists() is broken. PR3837. + struct stat buf; + if (::stat(P.c_str(), &buf) == 0 ? (buf.st_mode & S_IFMT) == S_IFREG : + (errno != ENOENT)) { + if (IssueErrors) + getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) + << Error; + return false; + } + } + return true; +} + 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) { + it = Files.begin(), ie = Files.end(); it != ie; ++it) + Success &= CleanupFile(*it, IssueErrors); + return Success; +} - llvm::sys::Path P(*it); - std::string Error; +bool Compilation::CleanupFileMap(const ArgStringMap &Files, + const JobAction *JA, + bool IssueErrors) const { + bool Success = true; + for (ArgStringMap::const_iterator + it = Files.begin(), ie = Files.end(); it != ie; ++it) { - // Don't try to remove files which we don't have write access to (but may be - // able to remove), or non-regular files. Underlying tools may have - // intentionally not overwritten them. - if (!P.canWrite() || !P.isRegularFile()) + // If specified, only delete the files associated with the JobAction. + // Otherwise, delete all files in the map. + if (JA && it->first != JA) continue; - - if (P.eraseFromDisk(false, &Error)) { - // Failure is only failure if the file exists and is "regular". There is - // a race condition here due to the limited interface of - // llvm::sys::Path, we want to know if the removal gave ENOENT. - - // FIXME: Grumble, P.exists() is broken. PR3837. - struct stat buf; - if (::stat(P.c_str(), &buf) == 0 ? (buf.st_mode & S_IFMT) == S_IFREG : - (errno != ENOENT)) { - if (IssueErrors) - getDriver().Diag(clang::diag::err_drv_unable_to_remove_file) - << Error; - Success = false; - } - } + Success &= CleanupFile(it->second, IssueErrors); } - return Success; } |