From: Argyrios Kyrtzidis Date: Fri, 31 Jul 2015 00:58:32 +0000 (+0000) Subject: [modules] Fix issue where building a module from a relative path when -working-direct... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1716d63b0dc6c882dc4cfa983df73b34184dc3a;p=clang [modules] Fix issue where building a module from a relative path when -working-directory option is set, results in error. The error was "module '' was built in directory '' but now resides in directory '' rdar://21330027 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243718 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/FileManager.h b/include/clang/Basic/FileManager.h index a08d3c894f..219422b9c7 100644 --- a/include/clang/Basic/FileManager.h +++ b/include/clang/Basic/FileManager.h @@ -254,7 +254,13 @@ public: /// \brief If path is not absolute and FileSystemOptions set the working /// directory, the path is modified to be relative to the given /// working directory. - void FixupRelativePath(SmallVectorImpl &path) const; + /// \returns true if \c path changed. + bool FixupRelativePath(SmallVectorImpl &path) const; + + /// Makes \c Path absolute taking into account FileSystemOptions and the + /// working directory option. + /// \returns true if \c Path changed to absolute. + bool makeAbsolutePath(SmallVectorImpl &Path) const; /// \brief Produce an array mapping from the unique IDs assigned to each /// file to the corresponding FileEntry pointer. diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index 4c84f1b6ad..034ebc5c88 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -389,16 +389,28 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size, return UFE; } -void FileManager::FixupRelativePath(SmallVectorImpl &path) const { +bool FileManager::FixupRelativePath(SmallVectorImpl &path) const { StringRef pathRef(path.data(), path.size()); if (FileSystemOpts.WorkingDir.empty() || llvm::sys::path::is_absolute(pathRef)) - return; + return false; SmallString<128> NewPath(FileSystemOpts.WorkingDir); llvm::sys::path::append(NewPath, pathRef); path = NewPath; + return true; +} + +bool FileManager::makeAbsolutePath(SmallVectorImpl &Path) const { + bool Changed = FixupRelativePath(Path); + + if (!llvm::sys::path::is_absolute(StringRef(Path.data(), Path.size()))) { + llvm::sys::fs::make_absolute(Path); + Changed = true; + } + + return Changed; } llvm::ErrorOr> diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index f1c907394b..f21b173c1d 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -1074,14 +1074,7 @@ void ASTWriter::WriteBlockInfoBlock() { /// \return \c true if the path was changed. static bool cleanPathForOutput(FileManager &FileMgr, SmallVectorImpl &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); + return FileMgr.makeAbsolutePath(Path) | FileMgr.removeDotPaths(Path); } /// \brief Adjusts the given filename to only write out the portion of the @@ -1429,7 +1422,7 @@ void ASTWriter::WriteControlBlock(Preprocessor &PP, ASTContext &Context, SmallString<128> OutputPath(OutputFile); - llvm::sys::fs::make_absolute(OutputPath); + SM.getFileManager().makeAbsolutePath(OutputPath); StringRef origDir = llvm::sys::path::parent_path(OutputPath); RecordData Record; diff --git a/test/Modules/Inputs/working-dir-test/Test.framework/Headers/Test.h b/test/Modules/Inputs/working-dir-test/Test.framework/Headers/Test.h new file mode 100644 index 0000000000..ecc54bfc72 --- /dev/null +++ b/test/Modules/Inputs/working-dir-test/Test.framework/Headers/Test.h @@ -0,0 +1 @@ +void test_me_call(void); diff --git a/test/Modules/Inputs/working-dir-test/Test.framework/Modules/module.modulemap b/test/Modules/Inputs/working-dir-test/Test.framework/Modules/module.modulemap new file mode 100644 index 0000000000..3040ac722f --- /dev/null +++ b/test/Modules/Inputs/working-dir-test/Test.framework/Modules/module.modulemap @@ -0,0 +1,6 @@ +framework module Test { + umbrella header "Test.h" + + export * + module * { export * } +} diff --git a/test/Modules/working-dir-flag.m b/test/Modules/working-dir-flag.m new file mode 100644 index 0000000000..0e258c0d2f --- /dev/null +++ b/test/Modules/working-dir-flag.m @@ -0,0 +1,9 @@ +// RUN: rm -rf %t.mcp +// RUN: %clang_cc1 -fmodules-cache-path=%t.mcp -fmodules -fimplicit-module-maps -F . -working-directory=%S/Inputs/working-dir-test %s -verify +// expected-no-diagnostics + +@import Test; + +void foo() { + test_me_call(); +}