From: Nico Weber Date: Thu, 3 Aug 2017 21:06:36 +0000 (+0000) Subject: Use "foo-12345.o" instead of "foo.o-12345" as temporary file name. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=764e1d8251b12447aee69092a851e46c0eb63c7d;p=clang Use "foo-12345.o" 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", tools like this will now skip the temp files as well. https://reviews.llvm.org/D36238 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309984 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index bb6a665cb4..d0c1a974af 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -759,9 +759,13 @@ std::unique_ptr CompilerInstance::createOutputFile( if (UseTemporary) { // Create a temporary file. - SmallString<128> TempPath; - TempPath = OutFile; + // Insert -%%%%%%%% before the extension (if any), so that tools doing + // things based on the file extension do the right thing. + StringRef OutputExtension = llvm::sys::path::extension(OutFile); + SmallString<128> TempPath = + StringRef(OutFile).drop_back(OutputExtension.size()); TempPath += "-%%%%%%%%"; + TempPath += OutputExtension; int fd; std::error_code EC = llvm::sys::fs::createUniqueFile(TempPath, fd, TempPath);