[Driver] Preserve filelists when a subprocess crashes. (#9849)

This should make it easier to rerun crashed jobs that use filelists;
previously you'd have to run the top-level driver command again with
-save-temps. I didn't want to save /all/ temporary files because that
often includes things like .o files, which could fill up your disk
pretty quickly. But we can always tweak this later.
This commit is contained in:
Jordan Rose
2017-05-22 17:14:20 -07:00
committed by GitHub
parent ae984977e0
commit a875d8c7c7
8 changed files with 66 additions and 25 deletions

View File

@@ -57,6 +57,13 @@ enum class OutputLevel {
Parseable,
};
/// Indicates whether a temporary file should always be preserved if a part of
/// the compilation crashes.
enum class PreserveOnSignal : bool {
No,
Yes
};
class Compilation {
friend class PerformJobsState;
private:
@@ -87,8 +94,8 @@ private:
/// Temporary files that should be cleaned up after the compilation finishes.
///
/// These apply whether the compilation succeeds or fails.
std::vector<std::string> TempFilePaths;
/// These apply whether the compilation succeeds or fails. If the
llvm::StringMap<PreserveOnSignal> TempFilePaths;
/// Write information about this compilation to this file.
///
@@ -174,14 +181,13 @@ public:
}
Job *addJob(std::unique_ptr<Job> J);
void addTemporaryFile(StringRef file) {
TempFilePaths.push_back(file.str());
void addTemporaryFile(StringRef file,
PreserveOnSignal preserve = PreserveOnSignal::No) {
TempFilePaths[file] = preserve;
}
bool isTemporaryFile(StringRef file) {
// TODO: Use a set instead of a linear search.
return std::find(TempFilePaths.begin(), TempFilePaths.end(), file) !=
TempFilePaths.end();
return TempFilePaths.count(file);
}
const llvm::opt::DerivedArgList &getArgs() const { return *TranslatedArgs; }
@@ -255,9 +261,12 @@ public:
private:
/// \brief Perform all jobs.
///
/// \returns exit code of the first failed Job, or 0 on success. A return
/// value of -2 indicates that a Job crashed during execution.
int performJobsImpl();
/// \param[out] abnormalExit Set to true if any job exits abnormally (i.e.
/// crashes).
///
/// \returns exit code of the first failed Job, or 0 on success. If a Job
/// crashes during execution, a negative value will be returned.
int performJobsImpl(bool &abnormalExit);
/// \brief Performs a single Job by executing in place, if possible.
///