]> granicus.if.org Git - clang/commitdiff
[driver] When generating temporary files allow a prefix to be added. In many
authorChad Rosier <mcrosier@apple.com>
Fri, 26 Aug 2011 21:28:44 +0000 (21:28 +0000)
committerChad Rosier <mcrosier@apple.com>
Fri, 26 Aug 2011 21:28:44 +0000 (21:28 +0000)
cases we want the prefix to be the original file name less the suffix.  For an
input such as test.c to named temporary would be something like test-3O4Clq.o
Part of <rdar://problem/8314451>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138662 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Driver.h
lib/Driver/Driver.cpp
lib/Driver/Tools.cpp

index e979146724c8f438b1e7730fbcb224e84745d882..2145d724c3454ff04d61c2e38141deffb071e1fe 100644 (file)
@@ -373,11 +373,11 @@ 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.
+  /// GetTemporaryPath - Return the pathname of a temporary file to use 
+  /// as part of compilation; the file will have the given prefix and suffix.
   ///
   /// GCC goes to extra lengths here to be a bit more robust.
-  std::string GetTemporaryPath(const char *Suffix) const;
+  std::string GetTemporaryPath(const char *Prefix, const char *Suffix) const;
 
   /// GetHostInfo - Construct a new host info object for the given
   /// host triple.
index 2baed75e0c19ac828774a715306ed1fd43ea2d3d..acdfdc21a2581f6d0c1659459fc5efce8b28a24e 100644 (file)
@@ -1335,6 +1335,15 @@ void Driver::BuildJobsForAction(Compilation &C,
   }
 }
 
+// Strip the directory and suffix from BaseInput.
+static const char *getBaseName (const char *BaseInput) {
+  std::pair<StringRef, StringRef> Split = StringRef(BaseInput).rsplit('/');
+  if (Split.second != "")
+    return Split.second.split('.').first.str().c_str();
+  else
+    return Split.first.split('.').first.str().c_str();
+}
+
 const char *Driver::GetNamedOutputPath(Compilation &C,
                                        const JobAction &JA,
                                        const char *BaseInput,
@@ -1355,7 +1364,8 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
   if ((!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) ||
       CCGenDiagnostics) {
     std::string TmpName =
-      GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+      GetTemporaryPath(getBaseName(BaseInput), 
+                       types::getTypeTempSuffix(JA.getType()));
     return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
   }
 
@@ -1388,9 +1398,10 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
   // If we're saving temps and the temp filename conflicts with the input
   // filename, then avoid overwriting input file.
   if (!AtTopLevel && C.getArgs().hasArg(options::OPT_save_temps) &&
-    NamedOutput == BaseName) {
+      NamedOutput == BaseName) {
     std::string TmpName =
-      GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+      GetTemporaryPath(getBaseName(BaseInput),
+                       types::getTypeTempSuffix(JA.getType()));
     return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
   }
 
@@ -1475,7 +1486,8 @@ std::string Driver::GetProgramPath(const char *Name, const ToolChain &TC,
   return Name;
 }
 
-std::string Driver::GetTemporaryPath(const char *Suffix) const {
+std::string Driver::GetTemporaryPath(const char *Prefix, 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;
@@ -1487,7 +1499,7 @@ std::string Driver::GetTemporaryPath(const char *Suffix) const {
   if (!TmpDir)
     TmpDir = "/tmp";
   llvm::sys::Path P(TmpDir);
-  P.appendComponent("cc");
+  P.appendComponent(Prefix);
   if (P.makeUnique(false, &Error)) {
     Diag(clang::diag::err_drv_unable_to_make_temp) << Error;
     return "";
index d91285b0a8360fb7efa82acdfb27fd98ee5ed4cc..22747e4c8f1629a36c8f0b28db4a5932f0287a1b 100644 (file)
@@ -2983,7 +2983,7 @@ void darwin::Compile::ConstructJob(Compilation &C, const JobAction &JA,
     // NOTE: gcc uses a temp .s file for this, but there doesn't seem
     // to be a good reason.
     const char *TmpPath = C.getArgs().MakeArgString(
-      D.GetTemporaryPath("s"));
+      D.GetTemporaryPath("cc", "s"));
     C.addTempFile(TmpPath);
     CmdArgs.push_back(TmpPath);
 
@@ -3125,7 +3125,7 @@ void darwin::Link::AddLinkArgs(Compilation &C,
   // dsymutil step.
   if (Version[0] >= 116 && D.IsUsingLTO(Args)) {
     const char *TmpPath = C.getArgs().MakeArgString(
-      D.GetTemporaryPath(types::getTypeTempSuffix(types::TY_Object)));
+      D.GetTemporaryPath("cc", types::getTypeTempSuffix(types::TY_Object)));
     C.addTempFile(TmpPath);
     CmdArgs.push_back("-object_path_lto");
     CmdArgs.push_back(TmpPath);