aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/CompilerDriver/Main.inc
diff options
context:
space:
mode:
authorMikhail Glushenkov <foldr@codedgers.com>2009-06-25 18:20:10 +0000
committerMikhail Glushenkov <foldr@codedgers.com>2009-06-25 18:20:10 +0000
commit7defa2d3d5cf1e4f773360886d17fd3bc99c0930 (patch)
tree5344665f73a9603f0089bd864dee2928d5a47ac9 /include/llvm/CompilerDriver/Main.inc
parent3ea93ded0f9027f662907443c1e41362def14557 (diff)
Make -save-temps behave like in GCC 4.5.
The -save-temps option now behaves like described in GCC 4.5 release notes (you can specify output directory for temporary files with -save-temps=obj -o $DIRNAME). I do not have GCC 4.5 installed, so if there are any inconsistencies between llvmc and GCC in the implementation of this feature, please let me know. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@74190 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/CompilerDriver/Main.inc')
-rw-r--r--include/llvm/CompilerDriver/Main.inc46
1 files changed, 38 insertions, 8 deletions
diff --git a/include/llvm/CompilerDriver/Main.inc b/include/llvm/CompilerDriver/Main.inc
index 638189387c..4a83d56300 100644
--- a/include/llvm/CompilerDriver/Main.inc
+++ b/include/llvm/CompilerDriver/Main.inc
@@ -17,6 +17,7 @@
#ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
#define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
+#include "llvm/CompilerDriver/BuiltinOptions.h"
#include "llvm/CompilerDriver/CompilationGraph.h"
#include "llvm/CompilerDriver/Error.h"
#include "llvm/CompilerDriver/ForceLinkage.h"
@@ -58,27 +59,56 @@ cl::opt<bool> WriteGraph("write-graph",
cl::opt<bool> ViewGraph("view-graph",
cl::desc("Show compilation graph in GhostView"),
cl::Hidden);
-cl::opt<bool> SaveTemps("save-temps",
- cl::desc("Keep temporary files"),
- cl::Hidden);
+
+cl::opt<SaveTempsEnum::Values> SaveTemps
+("save-temps", cl::desc("Keep temporary files"),
+ cl::init(SaveTempsEnum::Unset),
+ cl::values(clEnumValN(SaveTempsEnum::Obj, "obj",
+ "Save files in the directory specified with -o"),
+ clEnumValN(SaveTempsEnum::Cwd, "cwd",
+ "Use current working directory"),
+ clEnumValN(SaveTempsEnum::Obj, "", "Same as 'cwd'"),
+ clEnumValEnd),
+ cl::ValueOptional);
namespace {
+
+ sys::Path getTempDir() {
+ sys::Path tempDir;
+
+ // GCC 4.5-style -save-temps handling.
+ if (SaveTemps == SaveTempsEnum::Unset) {
+ tempDir = sys::Path::GetTemporaryDirectory();
+ }
+ else if (SaveTemps == SaveTempsEnum::Obj && !OutputFilename.empty()) {
+ tempDir = OutputFilename;
+
+ 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)
+
+ return tempDir;
+ }
+
/// BuildTargets - A small wrapper for CompilationGraph::Build.
int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
int ret;
- const sys::Path& tempDir = SaveTemps
- ? sys::Path("")
- : sys::Path(sys::Path::GetTemporaryDirectory());
+ const sys::Path& tempDir = getTempDir();
try {
ret = graph.Build(tempDir, langMap);
}
catch(...) {
- tempDir.eraseFromDisk(true);
+ if (SaveTemps == SaveTempsEnum::Unset)
+ tempDir.eraseFromDisk(true);
throw;
}
- if (!SaveTemps)
+ if (SaveTemps == SaveTempsEnum::Unset)
tempDir.eraseFromDisk(true);
return ret;
}