Remove some duplication.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75163 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Mikhail Glushenkov 2009-07-09 19:37:17 +00:00
parent 3a780d1214
commit f5f9a4d7db

View File

@ -31,31 +31,29 @@ namespace {
sys::Path getTempDir() { sys::Path getTempDir() {
sys::Path tempDir; sys::Path tempDir;
if (! TempDirname.empty()) { // The --temp-dir option.
if (!TempDirname.empty()) {
tempDir = TempDirname; tempDir = TempDirname;
if (!tempDir.exists()) {
std::string ErrMsg;
if (tempDir.createDirectoryOnDisk(true, &ErrMsg))
throw std::runtime_error(ErrMsg);
}
return tempDir;
} }
// GCC 4.5-style -save-temps handling. // GCC 4.5-style -save-temps handling.
if (SaveTemps == SaveTempsEnum::Unset) { else if (SaveTemps == SaveTempsEnum::Unset) {
tempDir = sys::Path::GetTemporaryDirectory(); tempDir = sys::Path::GetTemporaryDirectory();
return tempDir;
} }
else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) { else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) {
tempDir = OutputFilename; tempDir = OutputFilename;
tempDir = tempDir.getDirname(); tempDir = tempDir.getDirname();
if (!tempDir.exists()) {
std::string ErrMsg;
if (tempDir.createDirectoryOnDisk(true, &ErrMsg))
throw std::runtime_error(ErrMsg);
}
} }
// else if (SaveTemps == Cwd) -> use current dir (leave tempDir empty) else {
// SaveTemps == Cwd --> use current dir (leave tempDir empty).
return tempDir;
}
if (!tempDir.exists()) {
std::string ErrMsg;
if (tempDir.createDirectoryOnDisk(true, &ErrMsg))
throw std::runtime_error(ErrMsg);
}
return tempDir; return tempDir;
} }
@ -64,17 +62,19 @@ namespace {
int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) { int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret; int ret;
const sys::Path& tempDir = getTempDir(); const sys::Path& tempDir = getTempDir();
bool toDelete =
(SaveTemps == SaveTempsEnum::Unset && TempDirname.empty());
try { try {
ret = graph.Build(tempDir, langMap); ret = graph.Build(tempDir, langMap);
} }
catch(...) { catch(...) {
if (SaveTemps == SaveTempsEnum::Unset) if (toDelete)
tempDir.eraseFromDisk(true); tempDir.eraseFromDisk(true);
throw; throw;
} }
if (SaveTemps == SaveTempsEnum::Unset) if (toDelete)
tempDir.eraseFromDisk(true); tempDir.eraseFromDisk(true);
return ret; return ret;
} }