diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-12-11 20:50:24 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2014-12-11 20:50:24 +0000 |
commit | 54cc3c2f231846e110dcfbc04ff52f266aa6dfb9 (patch) | |
tree | 40917c9ba0ce4b23b2f98595f012d5ab5d50a332 /clang/lib/Serialization/ASTWriter.cpp | |
parent | 72b05aa59c0268f3404af9c3e61c706d1661fd03 (diff) | |
download | bcm5719-llvm-54cc3c2f231846e110dcfbc04ff52f266aa6dfb9.tar.gz bcm5719-llvm-54cc3c2f231846e110dcfbc04ff52f266aa6dfb9.zip |
[modules] When constructing paths relative to a module, strip out /./ directory
components. These sometimes get synthetically added, and we don't want -Ifoo
and -I./foo to be treated fundamentally differently here.
llvm-svn: 224055
Diffstat (limited to 'clang/lib/Serialization/ASTWriter.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index adecf9dab7a..02663ad43d4 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -1058,6 +1058,21 @@ void ASTWriter::WriteBlockInfoBlock() { Stream.ExitBlock(); } +/// \brief Prepares a path for being written to an AST file by converting it +/// to an absolute path and removing nested './'s. +/// +/// \return \c true if the path was changed. +bool cleanPathForOutput(FileManager &FileMgr, SmallVectorImpl<char> &Path) { + bool Changed = false; + + if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) { + llvm::sys::fs::make_absolute(Path); + Changed = true; + } + + return Changed | FileMgr.removeDotPaths(Path); +} + /// \brief Adjusts the given filename to only write out the portion of the /// filename that is not part of the system root directory. /// @@ -1170,8 +1185,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, Record.push_back(MODULE_DIRECTORY); SmallString<128> BaseDir(WritingModule->Directory->getName()); - Context.getSourceManager().getFileManager().FixupRelativePath(BaseDir); - llvm::sys::fs::make_absolute(BaseDir); + cleanPathForOutput(Context.getSourceManager().getFileManager(), BaseDir); Stream.EmitRecordWithBlob(AbbrevCode, Record, BaseDir); // Write out all other paths relative to the base directory if possible. @@ -4076,20 +4090,10 @@ void ASTWriter::AddString(StringRef Str, RecordDataImpl &Record) { } bool ASTWriter::PreparePathForOutput(SmallVectorImpl<char> &Path) { - bool Changed = false; - - if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) { - // Ask the file manager to fixup the relative path for us. This will - // honor the working directory. - if (Context) - Context->getSourceManager().getFileManager().FixupRelativePath(Path); + assert(Context && "should have context when outputting path"); - // We want an absolute path even if we weren't given a spelling for the - // current working directory. - llvm::sys::fs::make_absolute(Path); - - Changed = true; - } + bool Changed = + cleanPathForOutput(Context->getSourceManager().getFileManager(), Path); // Remove a prefix to make the path relative, if relevant. const char *PathBegin = Path.data(); |