]> granicus.if.org Git - clang/commitdiff
PR21217: Slightly more eagerly load -fmodule-map-file= files and provide
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 6 Dec 2014 01:13:41 +0000 (01:13 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sat, 6 Dec 2014 01:13:41 +0000 (01:13 +0000)
diagnostics if they don't exist. Based on a patch by John Thompson!

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

include/clang/Frontend/FrontendOptions.h
include/clang/Lex/HeaderSearchOptions.h
lib/Frontend/CompilerInstance.cpp
lib/Frontend/CompilerInvocation.cpp
lib/Lex/HeaderSearch.cpp

index 4e93b4ee10801ee909c6cb522211c089910a01cd..71c5aa47af99e392170ca7e290adaf8ddf734f08 100644 (file)
@@ -233,6 +233,9 @@ public:
   /// The list of plugins to load.
   std::vector<std::string> Plugins;
 
+  /// \brief The list of module map files to load before processing the input.
+  std::vector<std::string> ModuleMapFiles;
+
   /// \brief The list of additional prebuilt module files to load before
   /// processing the input.
   std::vector<std::string> ModuleFiles;
index 06024b2e90f2544496d00ddb517907ba8e630591..4e6e46939f785f70d5d415c11bd8f5ac8140ef04 100644 (file)
@@ -129,9 +129,6 @@ public:
   /// of computing the module hash.
   llvm::SetVector<std::string> ModulesIgnoreMacros;
 
-  /// \brief The set of user-provided module-map-files.
-  llvm::SetVector<std::string> ModuleMapFiles;
-
   /// \brief The set of user-provided virtual filesystem overlay files.
   std::vector<std::string> VFSOverlayFiles;
 
index dcc824723aa0ebcfbc76a4a425c487e17b1591bf..a5165ad6211a00ae7a2f050ac62f946e53dc602c 100644 (file)
@@ -371,6 +371,14 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
     AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/false, /*OutputPath=*/"",
                            /*ShowDepth=*/true, /*MSStyle=*/true);
   }
+
+  // Load all explictly-specified module map files.
+  for (const auto &Filename : getFrontendOpts().ModuleMapFiles) {
+    if (auto *File = getFileManager().getFile(Filename))
+      PP->getHeaderSearchInfo().loadModuleMapFile(File, /*IsSystem*/false);
+    else
+      getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
+  }
 }
 
 // ASTContext
index 65ffd5475ca48c056fd111d416befeef362e6f89..f01663858e0a0b446af54e999cc641f6e11f6c35 100644 (file)
@@ -848,6 +848,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
   Opts.ASTDumpLookups = Args.hasArg(OPT_ast_dump_lookups);
   Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index);
   Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex;
+  Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file);
   Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file);
 
   Opts.CodeCompleteOpts.IncludeMacros
@@ -1019,9 +1020,6 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) {
     StringRef MacroDef = (*it)->getValue();
     Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first);
   }
-  std::vector<std::string> ModuleMapFiles =
-      Args.getAllArgValues(OPT_fmodule_map_file);
-  Opts.ModuleMapFiles.insert(ModuleMapFiles.begin(), ModuleMapFiles.end());
 
   // Add -I..., -F..., and -index-header-map options in order.
   bool IsIndexHeaderMap = false;
index bbbcf3abec673c62fd3b3c4b30104a72185df119..a3f3737521ec686130e57421c115bf3760856bef 100644 (file)
@@ -569,18 +569,6 @@ const FileEntry *HeaderSearch::LookupFile(
     ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
     SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
     ModuleMap::KnownHeader *SuggestedModule, bool SkipCache) {
-  if (!HSOpts->ModuleMapFiles.empty()) {
-    // Preload all explicitly specified module map files. This enables modules
-    // map files lying in a directory structure separate from the header files
-    // that they describe. These cannot be loaded lazily upon encountering a
-    // header file, as there is no other known mapping from a header file to its
-    // module map file.
-    for (const auto &Filename : HSOpts->ModuleMapFiles)
-      if (const FileEntry *File = FileMgr.getFile(Filename))
-        loadModuleMapFile(File, /*IsSystem=*/false);
-    HSOpts->ModuleMapFiles.clear();
-  }
-
   if (SuggestedModule)
     *SuggestedModule = ModuleMap::KnownHeader();