[cfe-commits] r148148 - in /cfe/trunk: lib/Lex/HeaderSearch.cpp test/Modules/subframeworks.m

Douglas Gregor dgregor at apple.com
Fri Jan 13 14:31:52 PST 2012


Author: dgregor
Date: Fri Jan 13 16:31:52 2012
New Revision: 148148

URL: http://llvm.org/viewvc/llvm-project?rev=148148&view=rev
Log:
When inferring a module for a framework, first determine whether that
framework is actually a subframework within a top-level framework. If
so, only infer a module for the top-level framework and then dig out
the appropriate submodule.

This helps us cope with an amusing subframeworks anti-pattern, where
one uses -F <framework>/Frameworks to get direct include access to the
subframeworks of a framework (which otherwise would not be
permitted).

Modified:
    cfe/trunk/lib/Lex/HeaderSearch.cpp
    cfe/trunk/test/Modules/subframeworks.m

Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=148148&r1=148147&r2=148148&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Jan 13 16:31:52 2012
@@ -860,7 +860,7 @@
 }
   
 Module *HeaderSearch::getFrameworkModule(StringRef Name, 
-                                                    const DirectoryEntry *Dir) {
+                                         const DirectoryEntry *Dir) {
   if (Module *Module = ModMap.findModule(Name))
     return Module;
   
@@ -876,9 +876,50 @@
   case LMM_NewlyLoaded:
     return ModMap.findModule(Name);
   }
+
+  // The top-level framework directory, from which we'll infer a framework
+  // module.
+  const DirectoryEntry *TopFrameworkDir = Dir;
+  
+  // The path from the module we're actually looking for back to the top-level
+  // framework name.
+  llvm::SmallVector<StringRef, 2> SubmodulePath;
+  SubmodulePath.push_back(Name);
+  
+  // Walk the directory structure to find any enclosing frameworks.
+  StringRef DirName = Dir->getName();
+  do {
+    // Get the parent directory name.
+    DirName = llvm::sys::path::parent_path(DirName);
+    if (DirName.empty())
+      break;
+    
+    // Determine whether this directory exists.
+    Dir = FileMgr.getDirectory(DirName);
+    if (!Dir)
+      break;
+    
+    // If this is a framework directory, then we're a subframework of this
+    // framework.
+    if (llvm::sys::path::extension(DirName) == ".framework") {
+      SubmodulePath.push_back(llvm::sys::path::stem(DirName));
+      TopFrameworkDir = Dir;
+    }
+  } while (true);
   
-  // Try to infer a module map.
-  return ModMap.inferFrameworkModule(Name, Dir, /*Parent=*/0);
+  // Try to infer a module map from the top-level framework directory.
+  Module *Result = ModMap.inferFrameworkModule(SubmodulePath.back(), 
+                                               TopFrameworkDir, 
+                                               /*Parent=*/0);
+  
+  // Follow the submodule path to find the requested (sub)framework module
+  // within the top-level framework module.
+  SubmodulePath.pop_back();
+  while (!SubmodulePath.empty() && Result) {
+    Result = ModMap.lookupModuleQualified(SubmodulePath.back(), Result);
+    SubmodulePath.pop_back();
+  }
+  return Result;
 }
 
 

Modified: cfe/trunk/test/Modules/subframeworks.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/subframeworks.m?rev=148148&r1=148147&r2=148148&view=diff
==============================================================================
--- cfe/trunk/test/Modules/subframeworks.m (original)
+++ cfe/trunk/test/Modules/subframeworks.m Fri Jan 13 16:31:52 2012
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
-// RUN: %clang_cc1 -x objective-c++ -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs %s -verify
+// RUN: %clang_cc1 -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs -F %S/Inputs/DependsOnModule.framework/Frameworks %s -verify
+// RUN: %clang_cc1 -x objective-c++ -Wauto-import -fmodule-cache-path %t -fmodules -F %S/Inputs -F %S/Inputs/DependsOnModule.framework/Frameworks %s -verify
 
 @import DependsOnModule;
 





More information about the cfe-commits mailing list