summaryrefslogtreecommitdiffstats
path: root/clang/lib/Frontend/CompilerInstance.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2012-03-03 00:36:02 +0000
committerDaniel Dunbar <daniel@zuster.org>2012-03-03 00:36:02 +0000
commitb9c62c0773757562b1abed808c5441e52fc0b77c (patch)
treea1d50e1fcdca5fef72f8bd4b6ce8fd88a0e5d0a4 /clang/lib/Frontend/CompilerInstance.cpp
parent62a58f492801b199fde60fea9a9fd7f5e5ce8ed4 (diff)
downloadbcm5719-llvm-b9c62c0773757562b1abed808c5441e52fc0b77c.tar.gz
bcm5719-llvm-b9c62c0773757562b1abed808c5441e52fc0b77c.zip
Frontend: Don't automatically create missing directories when using temporary files with createOutputFile()
- This would otherwise happen as a side effect of llvm::sys::fs::unique_file creating parent directories. llvm-svn: 151960
Diffstat (limited to 'clang/lib/Frontend/CompilerInstance.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInstance.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 2ade1c17e13..a7855112e65 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -478,12 +478,14 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
bool Binary, bool RemoveFileOnSignal,
StringRef InFile,
StringRef Extension,
- bool UseTemporary) {
+ bool UseTemporary,
+ bool CreateMissingDirectories) {
std::string Error, OutputPathName, TempPathName;
llvm::raw_fd_ostream *OS = createOutputFile(OutputPath, Error, Binary,
RemoveFileOnSignal,
InFile, Extension,
UseTemporary,
+ CreateMissingDirectories,
&OutputPathName,
&TempPathName);
if (!OS) {
@@ -508,8 +510,12 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
StringRef InFile,
StringRef Extension,
bool UseTemporary,
+ bool CreateMissingDirectories,
std::string *ResultPathName,
std::string *TempPathName) {
+ assert((!CreateMissingDirectories || UseTemporary) &&
+ "CreateMissingDirectories is only allowed when using temporary files");
+
std::string OutFile, TempFile;
if (!OutputPath.empty()) {
OutFile = OutputPath;
@@ -528,12 +534,20 @@ CompilerInstance::createOutputFile(StringRef OutputPath,
std::string OSFile;
if (UseTemporary && OutFile != "-") {
- llvm::sys::Path OutPath(OutFile);
- // Only create the temporary if we can actually write to OutPath, otherwise
- // we want to fail early.
+ // Only create the temporary if the parent directory exists (or create
+ // missing directories is true) and we can actually write to OutPath,
+ // otherwise we want to fail early.
+ SmallString<256> AbsPath(OutputPath);
+ llvm::sys::fs::make_absolute(AbsPath);
+ llvm::sys::Path OutPath(AbsPath);
+ bool ParentExists = false;
+ if (llvm::sys::fs::exists(llvm::sys::path::parent_path(AbsPath.str()),
+ ParentExists))
+ ParentExists = false;
bool Exists;
- if ((llvm::sys::fs::exists(OutPath.str(), Exists) || !Exists) ||
- (OutPath.isRegularFile() && OutPath.canWrite())) {
+ if ((CreateMissingDirectories || ParentExists) &&
+ ((llvm::sys::fs::exists(AbsPath.str(), Exists) || !Exists) ||
+ (OutPath.isRegularFile() && OutPath.canWrite()))) {
// Create a temporary file.
SmallString<128> TempPath;
TempPath = OutFile;
OpenPOWER on IntegriCloud