aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-18 19:34:39 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-18 19:34:39 +0000
commit214399ebd73545dde02b4a45872e7ca9e1d9e742 (patch)
treee583e8d8faf42173e18967df69c20d1d54bb77b3
parent9a688659ed6bb3f6a3e4d76a88c2c626616e3c90 (diff)
Driver: Construct temporary file names.
- This is still suboptimal, but should at least be workable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67223 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticDriverKinds.def2
-rw-r--r--include/clang/Basic/DiagnosticDriverKinds.td2
-rw-r--r--include/clang/Driver/Driver.h6
-rw-r--r--lib/Driver/Driver.cpp22
4 files changed, 27 insertions, 5 deletions
diff --git a/include/clang/Basic/DiagnosticDriverKinds.def b/include/clang/Basic/DiagnosticDriverKinds.def
index a11435bea0..135b0e1695 100644
--- a/include/clang/Basic/DiagnosticDriverKinds.def
+++ b/include/clang/Basic/DiagnosticDriverKinds.def
@@ -30,6 +30,8 @@ DIAG(err_drv_use_of_Z_option, ERROR,
"unsupported use of internal gcc -Z option '%0'")
DIAG(err_drv_output_argument_with_multiple_files, ERROR,
"cannot specify -o when generating multiple output files")
+DIAG(err_drv_unable_to_make_temp, ERROR,
+ "unable to make temporary file: %0")
DIAG(warn_drv_input_file_unused, WARNING,
"%0: '%1' input file unused when '%2' is present")
diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td
index df24648dde..fecae53ad8 100644
--- a/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/include/clang/Basic/DiagnosticDriverKinds.td
@@ -23,6 +23,8 @@ def err_drv_use_of_Z_option : Error<
"unsupported use of internal gcc -Z option '%0'">;
def err_drv_output_argument_with_multiple_files : Error<
"cannot specify -o when generating multiple output files">;
+def err_drv_unable_to_make_temp : Error<
+ "unable to make temporary file: %0">;
def warn_drv_input_file_unused : Warning<
"%0: '%1' input file unused when '%2' is present">;
diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h
index b43fa8f6f7..2a91842884 100644
--- a/include/clang/Driver/Driver.h
+++ b/include/clang/Driver/Driver.h
@@ -215,6 +215,12 @@ public:
const char *BaseInput,
bool AtTopLevel) const;
+ /// GetTemporaryPath - Return the pathname of a temporary file to
+ /// use as part of compilation; the file will have the given suffix.
+ ///
+ /// GCC goes to extra lengths here to be a bit more robust.
+ std::string GetTemporaryPath(const char *Suffix) const;
+
/// GetHostInfo - Construct a new host info object for the given
/// host triple.
const HostInfo *GetHostInfo(const char *HostTriple) const;
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 49a4dca54c..9d913a1601 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -808,11 +808,9 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
// Output to a temporary file?
if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) {
- // FIXME: Get temporary name.
- std::string Name("/tmp/foo");
- Name += '.';
- Name += types::getTypeTempSuffix(JA.getType());
- return C.addTempFile(C.getArgs().MakeArgString(Name.c_str()));
+ std::string TmpName =
+ GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+ return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
}
llvm::sys::Path BasePath(BaseInput);
@@ -861,6 +859,20 @@ llvm::sys::Path Driver::GetProgramPath(const char *Name,
return llvm::sys::Path(Name);
}
+std::string Driver::GetTemporaryPath(const char *Suffix) const {
+ // FIXME: This is lame; sys::Path should provide this function (in
+ // particular, it should know how to find the temporary files dir).
+ std::string Error;
+ llvm::sys::Path P("/tmp/cc");
+ if (P.makeUnique(false, &Error)) {
+ Diag(clang::diag::err_drv_unable_to_make_temp) << Error;
+ return "";
+ }
+
+ P.appendSuffix(Suffix);
+ return P.toString();
+}
+
const HostInfo *Driver::GetHostInfo(const char *Triple) const {
llvm::PrettyStackTraceString CrashInfo("Constructing host");
// Dice into arch, platform, and OS. This matches