diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-28 03:49:04 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-28 03:49:04 +0000 |
| commit | 8ffd0a4eb8875f452e407effe49d86d1620a4499 (patch) | |
| tree | d0ce914e48876d8354becaaf46124c16c8836c44 /lib/Frontend/CompilerInstance.cpp | |
| parent | 1d7bb6c8b5b8f98fe79607718441f6543de598f1 (diff) | |
| download | clang-8ffd0a4eb8875f452e407effe49d86d1620a4499.tar.gz clang-8ffd0a4eb8875f452e407effe49d86d1620a4499.tar.bz2 clang-8ffd0a4eb8875f452e407effe49d86d1620a4499.tar.xz | |
Update for llvm::sys::fs::unique_file not creating directories.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185127 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend/CompilerInstance.cpp')
| -rw-r--r-- | lib/Frontend/CompilerInstance.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index ec1f959060..5ffee3032d 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -539,24 +539,27 @@ CompilerInstance::createOutputFile(StringRef OutputPath, } 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(CompilerInstance &ImportingInstance, 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: |
