]> granicus.if.org Git - clang/commitdiff
Introduce a cc1-level option to provide the path to the module cache,
authorDouglas Gregor <dgregor@apple.com>
Mon, 12 Sep 2011 20:41:59 +0000 (20:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Mon, 12 Sep 2011 20:41:59 +0000 (20:41 +0000)
where the compiler will look for module files. Eliminates the
egregious hack where we looked into the header search paths for
modules.

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

14 files changed:
include/clang/Driver/CC1Options.td
include/clang/Frontend/HeaderSearchOptions.h
include/clang/Lex/HeaderSearch.h
lib/Frontend/CompilerInstance.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Frontend/InitHeaderSearch.cpp
lib/Lex/HeaderSearch.cpp
test/Modules/diamond.c
test/Modules/load_failure.c
test/Modules/lookup.cpp
test/Modules/lookup.m
test/Modules/macros.c
test/Modules/module-private.cpp
test/Modules/objc-categories.m

index c1ceba87d1c19d85dbe205a93308a6380618e03c..e3d79ac385a947c07b07dcb023c96bb0292e79c2 100644 (file)
@@ -605,6 +605,10 @@ def nostdincxx : Flag<"-nostdinc++">,
   HelpText<"Disable standard #include directories for the C++ standard library">;
 def nobuiltininc : Flag<"-nobuiltininc">,
   HelpText<"Disable builtin #include directories">;
+def fmodule_cache_path : JoinedOrSeparate<"-fmodule-cache-path">, 
+  MetaVarName<"<directory>">,
+  HelpText<"Specify the module cache path">;           
+
 def F : JoinedOrSeparate<"-F">, MetaVarName<"<directory>">,
   HelpText<"Add directory to framework include search path">;
 def I : JoinedOrSeparate<"-I">, MetaVarName<"<directory>">,
index e1b1273ff4d1cc973249baa51ed340d47f712ad3..a81a0cb99294f9a5d75945f2b15df6087b470242 100644 (file)
@@ -75,6 +75,9 @@ public:
   /// etc.).
   std::string ResourceDir;
 
+  /// \brief The directory used for the module cache.
+  std::string ModuleCachePath;
+  
   /// Include the compiler builtin includes.
   unsigned UseBuiltinIncludes : 1;
 
index 676a245305d3125079662a8a880cd5c649322fb1..f6552a4014e7ccdae27fc0c964dee539c213adc6 100644 (file)
@@ -129,6 +129,9 @@ class HeaderSearch {
   unsigned SystemDirIdx;
   bool NoCurDirSearch;
 
+  /// \brief The path to the module cache.
+  std::string ModuleCachePath;
+  
   /// FileInfo - This contains all of the preprocessor-specific data about files
   /// that are included.  The vector is indexed by the FileEntry's UID.
   ///
@@ -193,6 +196,11 @@ public:
     //LookupFileCache.clear();
   }
 
+  /// \brief Set the path to the module cache.
+  void setModuleCachePath(StringRef Path) {
+    ModuleCachePath = Path;
+  }
+  
   /// ClearFileInfo - Forget everything we know about headers so far.
   void ClearFileInfo() {
     FileInfo.clear();
@@ -308,6 +316,13 @@ public:
   /// FileEntry, uniquing them through the the 'HeaderMaps' datastructure.
   const HeaderMap *CreateHeaderMap(const FileEntry *FE);
 
+  /// \brief Search in the module cache path for a module with the given
+  /// name.
+  ///
+  /// \returns A file describing the named module, if available, or NULL to
+  /// indicate that the module could not be found.
+  const FileEntry *lookupModule(StringRef ModuleName);
+  
   void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; }
 
   typedef std::vector<HeaderFileInfo>::const_iterator header_file_iterator;
index bd019e0cf231fe0395227552351a674e813a8e6b..1106e48e9103b2eff2bcef1a2725024502143a83 100644 (file)
@@ -636,14 +636,8 @@ ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
     CurFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
 
   // Search for a module with the given name.
-  std::string Filename = ModuleName.getName().str();
-  Filename += ".pcm";
-  const DirectoryLookup *CurDir = 0;  
   const FileEntry *ModuleFile
-    = PP->getHeaderSearchInfo().LookupFile(Filename, /*isAngled=*/false,
-                                           /*FromDir=*/0, CurDir, CurFile, 
-                                           /*SearchPath=*/0, 
-                                           /*RelativePath=*/0);
+    = PP->getHeaderSearchInfo().lookupModule(ModuleName.getName());
   if (!ModuleFile) {
     getDiagnostics().Report(ModuleNameLoc, diag::err_module_not_found)
       << ModuleName.getName()
index 7ea31613bd3b401c982e6d2f233d81471320fae4..e7b8854224180da8b3d12d982e5287c8f6eee97f 100644 (file)
@@ -576,6 +576,10 @@ static void HeaderSearchOptsToArgs(const HeaderSearchOptions &Opts,
     Res.push_back("-resource-dir");
     Res.push_back(Opts.ResourceDir);
   }
+  if (!Opts.ModuleCachePath.empty()) {
+    Res.push_back("-fmodule-cache-path");
+    Res.push_back(Opts.ModuleCachePath);
+  }
   if (!Opts.UseStandardIncludes)
     Res.push_back("-nostdinc");
   if (!Opts.UseStandardCXXIncludes)
@@ -1378,7 +1382,8 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
   if (const Arg *A = Args.getLastArg(OPT_stdlib_EQ))
     Opts.UseLibcxx = (strcmp(A->getValue(Args), "libc++") == 0);
   Opts.ResourceDir = Args.getLastArgValue(OPT_resource_dir);
-
+  Opts.ModuleCachePath = Args.getLastArgValue(OPT_fmodule_cache_path);
+  
   // Add -I..., -F..., and -index-header-map options in order.
   bool IsIndexHeaderMap = false;
   for (arg_iterator it = Args.filtered_begin(OPT_I, OPT_F, 
@@ -1426,7 +1431,7 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
                  ((*it)->getOption().matches(OPT_cxx_isystem) ?
                    frontend::CXXSystem : frontend::System),
                  true, false, !(*it)->getOption().matches(OPT_iwithsysroot));
-
+  
   // FIXME: Need options for the various environment variables!
 }
 
index 08af53226754f4caca4e77df2b4c61f8b46ca270..05152a77b2f305f64593d44832f8412133ed990d 100644 (file)
@@ -1161,5 +1161,7 @@ void clang::ApplyHeaderSearchOptions(HeaderSearch &HS,
   if (HSOpts.UseStandardIncludes)
     Init.AddDefaultSystemIncludePaths(Lang, Triple, HSOpts);
 
+  HS.setModuleCachePath(HSOpts.ModuleCachePath);
+  
   Init.Realize(Lang);
 }
index 0ba76327421e52c2c7d16771e7871007a3c4ea80..36826756b8b8a6fcedb6ba65f58530a4a6b9ea37 100644 (file)
@@ -98,6 +98,16 @@ const HeaderMap *HeaderSearch::CreateHeaderMap(const FileEntry *FE) {
   return 0;
 }
 
+const FileEntry *HeaderSearch::lookupModule(StringRef ModuleName) {
+  // If we don't have a module cache path, we can't do anything.
+  if (ModuleCachePath.empty())
+    return 0;
+  
+  llvm::SmallString<256> FileName(ModuleCachePath);
+  llvm::sys::path::append(FileName, ModuleName + ".pcm");
+  return getFileMgr().getFile(FileName);
+}
+
 //===----------------------------------------------------------------------===//
 // File lookup within a DirectoryLookup scope
 //===----------------------------------------------------------------------===//
index 6f6ff7bf466cfbdd3cca85c6263bffe6ba0cdb48..13389e2b6ac66d5c58c275fe3f35808e782f413f 100644 (file)
@@ -21,7 +21,7 @@ void test_diamond(int i, float f, double d, char c) {
 }
 
 // RUN: %clang_cc1 -emit-module -o %T/diamond_top.pcm %S/Inputs/diamond_top.h
-// RUN: %clang_cc1 -I %T -emit-module -o %T/diamond_left.pcm %S/Inputs/diamond_left.h
-// RUN: %clang_cc1 -I %T -emit-module -o %T/diamond_right.pcm %S/Inputs/diamond_right.h
-// RUN: %clang_cc1 -I %T -emit-module -o %T/diamond_bottom.pcm %S/Inputs/diamond_bottom.h
-// RUN: %clang_cc1 -I %T %s -verify
+// RUN: %clang_cc1 -fmodule-cache-path %T -emit-module -o %T/diamond_left.pcm %S/Inputs/diamond_left.h
+// RUN: %clang_cc1 -fmodule-cache-path %T -emit-module -o %T/diamond_right.pcm %S/Inputs/diamond_right.h
+// RUN: %clang_cc1 -fmodule-cache-path %T -emit-module -o %T/diamond_bottom.pcm %S/Inputs/diamond_bottom.h
+// RUN: %clang_cc1 -fmodule-cache-path %T %s -verify
index f034c78739693a42663c453e0980654ffbc5100f..4685a41ef6b6a88e565c4afbcaa7ad473c590ab2 100644 (file)
@@ -7,10 +7,10 @@ __import_module__ load_failure;
 #endif
 
 // RUN: %clang_cc1 -x c++ -emit-module -o %T/load_failure.pcm %S/Inputs/load_failure.h
-// RUN: %clang_cc1 -I %T %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
+// RUN: %clang_cc1 -fmodule-cache-path %T %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
 // CHECK-NONEXISTENT: load_failure.c:2:19: fatal error: module 'load_nonexistent' not found
 
-// RUN: not %clang_cc1 -I %T %s -DFAILURE 2> %t
+// RUN: not %clang_cc1 -fmodule-cache-path %T %s -DFAILURE 2> %t
 // RUN: FileCheck -check-prefix=CHECK-FAILURE %s < %t
 
 // FIXME: Clean up diagnostic text below and give it a location
index 7c53106e8a0fa5f90f5c288eb63e109e85f6d95f..c8f7993540d79cdfd74bbc9f7e814dc4682d062e 100644 (file)
@@ -16,8 +16,8 @@ void test(int i, float f) {
 
 // RUN: %clang_cc1 -emit-module -x c++ -verify -o %T/lookup_left_cxx.pcm %S/Inputs/lookup_left.hpp
 // RUN: %clang_cc1 -emit-module -x c++ -o %T/lookup_right_cxx.pcm %S/Inputs/lookup_right.hpp
-// RUN: %clang_cc1 -x c++ -I %T %s -verify
-// RUN: %clang_cc1 -ast-print -x c++ -I %T %s | FileCheck -check-prefix=CHECK-PRINT %s
+// RUN: %clang_cc1 -x c++ -fmodule-cache-path %T %s -verify
+// RUN: %clang_cc1 -ast-print -x c++ -fmodule-cache-path %T %s | FileCheck -check-prefix=CHECK-PRINT %s
 
 // CHECK-PRINT: int *f0(int *);
 // CHECK-PRINT: float *f0(float *);
index 02898a5dcfce4def1b8e37d1c64271b1eb1b4e99..ca68e89e0e61c2ccc97c817a342d46d0f7530624 100644 (file)
@@ -10,8 +10,8 @@ void test(id x) {
 
 // RUN: %clang_cc1 -emit-module -x objective-c -o %T/lookup_left_objc.pcm %S/Inputs/lookup_left.h
 // RUN: %clang_cc1 -emit-module -x objective-c -o %T/lookup_right_objc.pcm %S/Inputs/lookup_right.h
-// RUN: %clang_cc1 -x objective-c -I %T -verify %s
-// RUN: %clang_cc1 -ast-print -x objective-c -I %T %s | FileCheck -check-prefix=CHECK-PRINT %s
+// RUN: %clang_cc1 -x objective-c -fmodule-cache-path %T -verify %s
+// RUN: %clang_cc1 -ast-print -x objective-c -fmodule-cache-path %T %s | FileCheck -check-prefix=CHECK-PRINT %s
 
 // CHECK-PRINT: - (int) method;
 // CHECK-PRINT: - (double) method
index 691e8ec0ec1843e60650c5c3ec55ddd4fa1d15d4..346f91f22154f7e3c9554cdb831c831c69091878 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -emit-module -o %t/macros.pcm -DMODULE %s
-// RUN: %clang_cc1 -verify -I %t %s
+// RUN: %clang_cc1 -verify -fmodule-cache-path %t %s
 
 #if defined(MODULE)
 #define INTEGER(X) int
index 33ec32048af92de0dc0881653bafe8eaa67fa1f9..539e591e093456e15f736e00e62300c321961d3f 100644 (file)
@@ -1,7 +1,7 @@
 // RUN: mkdir -p %t
 // RUN: %clang_cc1 -x c++ -emit-module -o %t/left.pcm %s -D MODULE_LEFT
 // RUN: %clang_cc1 -x c++ -emit-module -o %t/right.pcm %s -D MODULE_RIGHT
-// RUN: %clang_cc1 -I %t %s -verify
+// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
 
 #if defined(MODULE_LEFT)
 
index 3bae4b8a99f13c948c776d02d779c717e59e3366..57978588700c961f0e52ed253f01b31b75c2b463 100644 (file)
@@ -1,9 +1,9 @@
 // RUN: mkdir -p %t
 // RUN: %clang_cc1 -emit-module -o %t/diamond_top.pcm %s -D MODULE_TOP
-// RUN: %clang_cc1 -I %t -emit-module -o %t/diamond_left.pcm %s -D MODULE_LEFT
-// RUN: %clang_cc1 -I %t -emit-module -o %t/diamond_right.pcm %s -D MODULE_RIGHT
-// RUN: %clang_cc1 -I %t -emit-module -o %t/diamond_bottom.pcm %s -D MODULE_BOTTOM
-// RUN: %clang_cc1 -I %t %s -verify
+// RUN: %clang_cc1 -fmodule-cache-path %t -emit-module -o %t/diamond_left.pcm %s -D MODULE_LEFT
+// RUN: %clang_cc1 -fmodule-cache-path %t -emit-module -o %t/diamond_right.pcm %s -D MODULE_RIGHT
+// RUN: %clang_cc1 -fmodule-cache-path %t -emit-module -o %t/diamond_bottom.pcm %s -D MODULE_BOTTOM
+// RUN: %clang_cc1 -fmodule-cache-path %t %s -verify
 
 /*============================================================================*/
 #ifdef MODULE_TOP