r185127 - Update for llvm::sys::fs::unique_file not creating directories.

Rafael Espindola rafael.espindola at gmail.com
Thu Jun 27 20:49:04 PDT 2013


Author: rafael
Date: Thu Jun 27 22:49:04 2013
New Revision: 185127

URL: http://llvm.org/viewvc/llvm-project?rev=185127&view=rev
Log:
Update for llvm::sys::fs::unique_file not creating directories.

Modified:
    cfe/trunk/lib/Frontend/CompilerInstance.cpp
    cfe/trunk/test/Frontend/output-failures.c

Modified: cfe/trunk/lib/Frontend/CompilerInstance.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInstance.cpp?rev=185127&r1=185126&r2=185127&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInstance.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInstance.cpp Thu Jun 27 22:49:04 2013
@@ -539,24 +539,27 @@ CompilerInstance::createOutputFile(Strin
   }
 
   if (UseTemporary) {
-    SmallString<256> AbsPath(OutputPath);
-    llvm::sys::fs::make_absolute(AbsPath);
-
-    // If the parent directory doesn't exist and we can't create it, fail.
-    bool ParentExists =
-        llvm::sys::fs::exists(llvm::sys::path::parent_path(AbsPath.str()));
-    if (!CreateMissingDirectories && !ParentExists) {
-      Error = "Parent directory doesn't exist";
-      return 0;
-    }
-
     // Create a temporary file.
     SmallString<128> TempPath;
     TempPath = OutFile;
     TempPath += "-%%%%%%%%";
     int fd;
-    if (!llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath,
-                                   /*makeAbsolute=*/false, 0664)) {
+    llvm::error_code EC = llvm::sys::fs::unique_file(
+        TempPath.str(), fd, TempPath, /*makeAbsolute=*/ false, 0664);
+
+    if (CreateMissingDirectories &&
+        (EC == llvm::errc::no_such_file_or_directory ||
+         EC == llvm::windows_error::file_not_found ||
+         EC == llvm::windows_error::path_not_found)) {
+      StringRef Parent = llvm::sys::path::parent_path(OutputPath);
+      EC = llvm::sys::fs::create_directories(Parent);
+      if (!EC) {
+        EC = llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath,
+                                        /*makeAbsolute=*/ false, 0664);
+      }
+    }
+
+    if (!EC) {
       OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
       OSFile = TempFile = TempPath.str();
     }
@@ -780,6 +783,11 @@ static void compileModule(CompilerInstan
                           SourceLocation ImportLoc,
                           Module *Module,
                           StringRef ModuleFileName) {
+  // FIXME: have LockFileManager return an error_code so that we can
+  // avoid the mkdir when the directory already exists.
+  StringRef Dir = llvm::sys::path::parent_path(ModuleFileName);
+  llvm::sys::fs::create_directories(Dir);
+
   llvm::LockFileManager Locked(ModuleFileName);
   switch (Locked) {
   case llvm::LockFileManager::LFS_Error:

Modified: cfe/trunk/test/Frontend/output-failures.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/output-failures.c?rev=185127&r1=185126&r2=185127&view=diff
==============================================================================
--- cfe/trunk/test/Frontend/output-failures.c (original)
+++ cfe/trunk/test/Frontend/output-failures.c Thu Jun 27 22:49:04 2013
@@ -1,4 +1,4 @@
 // RUN: not %clang_cc1 -emit-llvm -o %S/doesnotexist/somename %s 2> %t
 // RUN: FileCheck -check-prefix=OUTPUTFAIL -input-file=%t %s
 
-// OUTPUTFAIL:  unable to open output file '{{.*}}doesnotexist{{.*}}': 'Parent directory doesn't exist'
+// OUTPUTFAIL: Error opening output file '{{.*}}doesnotexist{{.*}}'





More information about the cfe-commits mailing list