]> granicus.if.org Git - clang/commitdiff
[modules] Fix issue where building a module from a relative path when -working-direct...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 31 Jul 2015 00:58:32 +0000 (00:58 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 31 Jul 2015 00:58:32 +0000 (00:58 +0000)
The error was "module '<name>' was built in directory '<path>' but now resides in directory '<path>'
rdar://21330027

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243718 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/FileManager.h
lib/Basic/FileManager.cpp
lib/Serialization/ASTWriter.cpp
test/Modules/Inputs/working-dir-test/Test.framework/Headers/Test.h [new file with mode: 0644]
test/Modules/Inputs/working-dir-test/Test.framework/Modules/module.modulemap [new file with mode: 0644]
test/Modules/working-dir-flag.m [new file with mode: 0644]

index a08d3c894f10dc6de29c76c59d5f04f1754b3879..219422b9c73d77ed56ae1173c8161e7c2d1e07ac 100644 (file)
@@ -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<char> &path) const;
+  /// \returns true if \c path changed.
+  bool FixupRelativePath(SmallVectorImpl<char> &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<char> &Path) const;
 
   /// \brief Produce an array mapping from the unique IDs assigned to each
   /// file to the corresponding FileEntry pointer.
index 4c84f1b6ad28e701091f958062d6608d1b9bdad4..034ebc5c88b2ab88a44b02589571faa13c2a8541 100644 (file)
@@ -389,16 +389,28 @@ FileManager::getVirtualFile(StringRef Filename, off_t Size,
   return UFE;
 }
 
-void FileManager::FixupRelativePath(SmallVectorImpl<char> &path) const {
+bool FileManager::FixupRelativePath(SmallVectorImpl<char> &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<char> &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<std::unique_ptr<llvm::MemoryBuffer>>
index f1c907394bfdc7862b41fe2f2ff1eb5ae4cdd327..f21b173c1dd02ef464a238eba9148d2bffb39e43 100644 (file)
@@ -1074,14 +1074,7 @@ void ASTWriter::WriteBlockInfoBlock() {
 /// \return \c true if the path was changed.
 static 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);
+  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 (file)
index 0000000..ecc54bf
--- /dev/null
@@ -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 (file)
index 0000000..3040ac7
--- /dev/null
@@ -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 (file)
index 0000000..0e258c0
--- /dev/null
@@ -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();
+}