Skip to content
Snippets Groups Projects
Commit 8ffd0a4e authored by Rafael Espindola's avatar Rafael Espindola
Browse files

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
parent 1d7bb6c8
No related branches found
No related tags found
No related merge requests found
...@@ -539,24 +539,27 @@ CompilerInstance::createOutputFile(StringRef OutputPath, ...@@ -539,24 +539,27 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
} }
if (UseTemporary) { 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. // Create a temporary file.
SmallString<128> TempPath; SmallString<128> TempPath;
TempPath = OutFile; TempPath = OutFile;
TempPath += "-%%%%%%%%"; TempPath += "-%%%%%%%%";
int fd; int fd;
if (!llvm::sys::fs::unique_file(TempPath.str(), fd, TempPath, llvm::error_code EC = llvm::sys::fs::unique_file(
/*makeAbsolute=*/false, 0664)) { 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)); OS.reset(new llvm::raw_fd_ostream(fd, /*shouldClose=*/true));
OSFile = TempFile = TempPath.str(); OSFile = TempFile = TempPath.str();
} }
...@@ -780,6 +783,11 @@ static void compileModule(CompilerInstance &ImportingInstance, ...@@ -780,6 +783,11 @@ static void compileModule(CompilerInstance &ImportingInstance,
SourceLocation ImportLoc, SourceLocation ImportLoc,
Module *Module, Module *Module,
StringRef ModuleFileName) { 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); llvm::LockFileManager Locked(ModuleFileName);
switch (Locked) { switch (Locked) {
case llvm::LockFileManager::LFS_Error: case llvm::LockFileManager::LFS_Error:
......
// RUN: not %clang_cc1 -emit-llvm -o %S/doesnotexist/somename %s 2> %t // RUN: not %clang_cc1 -emit-llvm -o %S/doesnotexist/somename %s 2> %t
// RUN: FileCheck -check-prefix=OUTPUTFAIL -input-file=%t %s // 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{{.*}}'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment