]> granicus.if.org Git - clang/commitdiff
Driver: Construct temporary file names.
authorDaniel Dunbar <daniel@zuster.org>
Wed, 18 Mar 2009 19:34:39 +0000 (19:34 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 18 Mar 2009 19:34:39 +0000 (19:34 +0000)
 - 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

include/clang/Basic/DiagnosticDriverKinds.def
include/clang/Basic/DiagnosticDriverKinds.td
include/clang/Driver/Driver.h
lib/Driver/Driver.cpp

index a11435bea062f2497147eb9c9b5f4b7290bad777..135b0e1695b40899553b4e695dd21154582f64d9 100644 (file)
@@ -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")
index df24648dde6bd49c63abb2e96a9269af304d4cd1..fecae53ad83d1a2c9d2ef159f7e89ccceffa7aa4 100644 (file)
@@ -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">;
index b43fa8f6f73465e7ac51e0eb23d83d42ef0936f9..2a91842884025f6ba9b7913ebd21283880f8fad3 100644 (file)
@@ -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;
index 49a4dca54cebc6e78ab0cf4807cf001a5184af48..9d913a1601dd28bad11c0f87a6b8b0fe0c40c85a 100644 (file)
@@ -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