[dsymutil] Create the temporary files in the system temp directory.
authorFrederic Riss <friss@apple.com>
Mon, 2 May 2016 21:06:14 +0000 (21:06 +0000)
committerFrederic Riss <friss@apple.com>
Mon, 2 May 2016 21:06:14 +0000 (21:06 +0000)
llvm-dsymutil used to create the temporary files in the output directory.
This works fine except when the output directory contains a '%' char, which
is then replaced by llvm::sys::fs::createUniqueFile() generating an invalid
path.
Just use the default temp dir for those files.

llvm-svn: 268304

llvm/test/tools/dsymutil/fat-binary-output.test
llvm/tools/dsymutil/dsymutil.cpp

index fafef14..94345a8 100644 (file)
@@ -24,9 +24,7 @@ CHECK:   DW_AT_name{{.*}} "x86_64h_var"
 
 CHECK: Running lipo
 CHECK-NEXT: lipo -create
-CHECK-SAME: [[INPUTS_PATH]]fat-test.dylib.tmp{{......}}.dwarf
-CHECK-SAME: [[INPUTS_PATH]]fat-test.dylib.tmp{{......}}.dwarf
-CHECK-SAME: [[INPUTS_PATH]]fat-test.dylib.tmp{{......}}.dwarf
+CHECK-SAME  [[TMP_PATH:.*?]]fat-test.dylib.tmp{{......}}.dwarf [[TMP_PATH]]fat-test.dylib.tmp{{......}}.dwarf [[TMP_PATH]]fat-test.dylib.tmp{{......}}.dwarf
 CHECK-SAME: -segalign x86_64 20 -segalign i386 20 -segalign x86_64h 20
 CHECK-SAME: -output [[INPUTS_PATH]]fat-test.dylib.dwarf
 
index e9ee57f..aeb0fd2 100644 (file)
@@ -176,14 +176,17 @@ static std::error_code getUniqueFile(const llvm::Twine &Model, int &ResultFD,
 static std::string getOutputFileName(llvm::StringRef InputFile,
                                      bool TempFile = false) {
   if (TempFile) {
+    llvm::SmallString<128> TmpFile;
+    llvm::sys::path::system_temp_directory(true, TmpFile);
     llvm::StringRef Basename =
         OutputFileOpt.empty() ? InputFile : llvm::StringRef(OutputFileOpt);
-    llvm::Twine OutputFile = Basename + ".tmp%%%%%%.dwarf";
+    llvm::sys::path::append(TmpFile, llvm::sys::path::filename(Basename));
+
     int FD;
     llvm::SmallString<128> UniqueFile;
-    if (auto EC = getUniqueFile(OutputFile, FD, UniqueFile)) {
+    if (auto EC = getUniqueFile(TmpFile + ".tmp%%%%%.dwarf", FD, UniqueFile)) {
       llvm::errs() << "error: failed to create temporary outfile '"
-                   << OutputFile << "': " << EC.message() << '\n';
+                   << TmpFile << "': " << EC.message() << '\n';
       return "";
     }
     llvm::sys::RemoveFileOnSignal(UniqueFile);