[cfe-commits] r172439 - in /cfe/trunk: include/clang/Basic/Module.h lib/Lex/ModuleMap.cpp test/Modules/Inputs/Module.framework/Module test/Modules/Inputs/NoUmbrella.framework/NoUmbrella test/Modules/autolink.m

Douglas Gregor dgregor at apple.com
Mon Jan 14 09:57:51 PST 2013


Author: dgregor
Date: Mon Jan 14 11:57:51 2013
New Revision: 172439

URL: http://llvm.org/viewvc/llvm-project?rev=172439&view=rev
Log:
Infer "link" lines for top-level frameworks. Essentially, a framework
will have a shared library with the same name as its framework (and no
suffix!) within its .framework directory. Detect this both when
inferring the whole top-level framework and when parsing a module map.


Added:
    cfe/trunk/test/Modules/Inputs/Module.framework/Module
    cfe/trunk/test/Modules/Inputs/NoUmbrella.framework/NoUmbrella
Modified:
    cfe/trunk/include/clang/Basic/Module.h
    cfe/trunk/lib/Lex/ModuleMap.cpp
    cfe/trunk/test/Modules/autolink.m

Modified: cfe/trunk/include/clang/Basic/Module.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Module.h?rev=172439&r1=172438&r2=172439&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/Module.h (original)
+++ cfe/trunk/include/clang/Basic/Module.h Mon Jan 14 11:57:51 2013
@@ -237,7 +237,13 @@
     
     return false;
   }
-  
+
+  /// \brief Determine whether this module is a subframework of another
+  /// framework.
+  bool isSubFramework() const {
+    return IsFramework && Parent && Parent->isPartOfFramework();
+  }
+
   /// \brief Retrieve the full name of this module, including the path from
   /// its top-level module.
   std::string getFullModuleName() const;

Modified: cfe/trunk/lib/Lex/ModuleMap.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/ModuleMap.cpp?rev=172439&r1=172438&r2=172439&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/ModuleMap.cpp (original)
+++ cfe/trunk/lib/Lex/ModuleMap.cpp Mon Jan 14 11:57:51 2013
@@ -383,6 +383,23 @@
   return canInfer;
 }
 
+/// \brief For a framework module, infer the framework against which we
+/// should link.
+static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir,
+                               FileManager &FileMgr) {
+  assert(Mod->IsFramework && "Can only infer linking for framework modules");
+  assert(!Mod->isSubFramework() &&
+         "Can only infer linking for top-level frameworks");
+
+  SmallString<128> LibName;
+  LibName += FrameworkDir->getName();
+  llvm::sys::path::append(LibName, Mod->Name);
+  if (FileMgr.getFile(LibName)) {
+    Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
+                                                     /*IsFramework=*/true));
+  }
+}
+
 Module *
 ModuleMap::inferFrameworkModule(StringRef ModuleName,
                                 const DirectoryEntry *FrameworkDir,
@@ -537,6 +554,12 @@
     }
   }
 
+  // If the module is a top-level framework, automatically link against the
+  // framework.
+  if (!Result->isSubFramework()) {
+    inferFrameworkLink(Result, FrameworkDir, FileMgr);
+  }
+
   return Result;
 }
 
@@ -1147,6 +1170,13 @@
     HadError = true;
   }
 
+  // If the active module is a top-level framework, and there are no link
+  // libraries, automatically link against the framework.
+  if (ActiveModule->IsFramework && !ActiveModule->isSubFramework() &&
+      ActiveModule->LinkLibraries.empty()) {
+    inferFrameworkLink(ActiveModule, Directory, SourceMgr.getFileManager());
+  }
+
   // We're done parsing this module. Pop back to the previous module.
   ActiveModule = PreviousActiveModule;
 }

Added: cfe/trunk/test/Modules/Inputs/Module.framework/Module
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/Module.framework/Module?rev=172439&view=auto
==============================================================================
    (empty)

Added: cfe/trunk/test/Modules/Inputs/NoUmbrella.framework/NoUmbrella
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/NoUmbrella.framework/NoUmbrella?rev=172439&view=auto
==============================================================================
    (empty)

Modified: cfe/trunk/test/Modules/autolink.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/autolink.m?rev=172439&r1=172438&r2=172439&view=diff
==============================================================================
--- cfe/trunk/test/Modules/autolink.m (original)
+++ cfe/trunk/test/Modules/autolink.m Mon Jan 14 11:57:51 2013
@@ -13,6 +13,18 @@
   return autolink;
 }
 
-// CHECK: !llvm.link.libraries = !{![[AUTOLINK:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]]}
+ at import Module.SubFramework;
+const char *get_module_subframework() {
+  return module_subframework;
+}
+
+ at import NoUmbrella;
+int use_no_umbrella() {
+  return no_umbrella_A;
+}
+
+// CHECK: !llvm.link.libraries = !{![[AUTOLINK:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]}
 // CHECK: ![[AUTOLINK]] = metadata !{metadata !"autolink", i1 false}
 // CHECK: ![[AUTOLINK_FRAMEWORK]] = metadata !{metadata !"autolink_framework", i1 true}
+// CHECK: ![[MODULE]] = metadata !{metadata !"Module", i1 true}
+// CHECK: ![[NOUMBRELLA]] = metadata !{metadata !"NoUmbrella", i1 true}





More information about the cfe-commits mailing list