From f5f9a4d7db5bc4bb70e551d3ba2d0419425a5cc1 Mon Sep 17 00:00:00 2001 From: Mikhail Glushenkov Date: Thu, 9 Jul 2009 19:37:17 +0000 Subject: [PATCH] Remove some duplication. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75163 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CompilerDriver/Main.cpp | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/CompilerDriver/Main.cpp b/lib/CompilerDriver/Main.cpp index 86863dcae2c..cd7bc474d12 100644 --- a/lib/CompilerDriver/Main.cpp +++ b/lib/CompilerDriver/Main.cpp @@ -31,31 +31,29 @@ namespace { sys::Path getTempDir() { sys::Path tempDir; - if (! TempDirname.empty()) { + // The --temp-dir option. + if (!TempDirname.empty()) { 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. - if (SaveTemps == SaveTempsEnum::Unset) { + else if (SaveTemps == SaveTempsEnum::Unset) { tempDir = sys::Path::GetTemporaryDirectory(); + return tempDir; } else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) { tempDir = OutputFilename; 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; } @@ -64,17 +62,19 @@ namespace { int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) { int ret; const sys::Path& tempDir = getTempDir(); + bool toDelete = + (SaveTemps == SaveTempsEnum::Unset && TempDirname.empty()); try { ret = graph.Build(tempDir, langMap); } catch(...) { - if (SaveTemps == SaveTempsEnum::Unset) + if (toDelete) tempDir.eraseFromDisk(true); throw; } - if (SaveTemps == SaveTempsEnum::Unset) + if (toDelete) tempDir.eraseFromDisk(true); return ret; }