r310376 - Use "foo-12345.o.tmp" instead of "foo.o-12345" as temporary file name.

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 8 09:21:23 PDT 2017


Author: nico
Date: Tue Aug  8 09:21:23 2017
New Revision: 310376

URL: http://llvm.org/viewvc/llvm-project?rev=310376&view=rev
Log:
Use "foo-12345.o.tmp" instead of "foo.o-12345" as temporary file name.

This helps some tools that do things based on the output's extension.

For example, we got reports from users on Windows that have a tool that scan a
build output dir (but skip .obj files). The tool would keep the "foo.obj-12345"
file open, and then when clang tried to rename the temp file to the final
output filename, that would fail. By making the tempfile end in ".obj.tmp",
tools like this could now have a rule to ignore .tmp files.
This is a less ambitious reland of https://reviews.llvm.org/D36238

https://reviews.llvm.org/D36413

Modified:
    cfe/trunk/lib/Frontend/CompilerInstance.cpp

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=310376&r1=310375&r2=310376&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Tue Aug  8 09:21:23 2017
@@ -759,9 +759,15 @@ std::unique_ptr<llvm::raw_pwrite_stream>
 
   if (UseTemporary) {
     // Create a temporary file.
-    SmallString<128> TempPath;
-    TempPath = OutFile;
+    // Insert -%%%%%%%% before the extension (if any), and because some tools
+    // (noticeable, clang's own GlobalModuleIndex.cpp) glob for build
+    // artifacts, also append .tmp.
+    StringRef OutputExtension = llvm::sys::path::extension(OutFile);
+    SmallString<128> TempPath =
+        StringRef(OutFile).drop_back(OutputExtension.size());
     TempPath += "-%%%%%%%%";
+    TempPath += OutputExtension;
+    TempPath += ".tmp";
     int fd;
     std::error_code EC =
         llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath);




More information about the cfe-commits mailing list