================
@@ -702,6 +703,56 @@ createScanningDiagOptions(ArrayRef<std::string> 
CommandLine) {
   return DiagOpts;
 }
 
+namespace {
+/// Find the module maps that define modules without loading them.
+class ModuleMapLookup {
+public:
+  explicit ModuleMapLookup(CompilerInstance &CI)
+      : CI(CI), HSOpts(CI.getHeaderSearchOpts()),
+        Diags(DiagnosticIDs::create(), DiagOpts, new IgnoringDiagConsumer()),
+        SourceMgr(Diags, CI.getFileManager()),
+        HS(HSOpts, SourceMgr, Diags, CI.getLangOpts(), &CI.getTarget()) {
+    HSOpts.LazyLoadModuleMaps = true;
+    // Ignore verbose mode as it's already respected by the real scan.
+    HSOpts.Verbose = false;
+    ApplyHeaderSearchOptions(HS, HSOpts, CI.getLangOpts(),
+                             CI.getTarget().getTriple());
+  }
+
+  llvm::StringMap<std::string>
+  computeModuleMapsForModules(ArrayRef<StringRef> ModuleNames) {
+    // Resolve any modulemaps passed directly first.
+    for (const std::string &Filename : CI.getFrontendOpts().ModuleMapFiles)
+      if (OptionalFileEntryRef File =
+              CI.getFileManager().getOptionalFileRef(Filename))
+        HS.parseModuleMapFile(*File, /*IsSystem=*/false,
+                              /*ImplicitlyDiscovered=*/false);
+
+    llvm::StringMap<std::string> Result;
+    // Then resolve modulemaps through header search.
+    for (StringRef Name : ModuleNames) {
+      OptionalFileEntryRef File = HS.lookupModuleMapFileForModule(Name);
+      // Skip over modules that didn't find a modulemap.
+      if (!File)
+        continue;
+      // Canonicalize the path the same way as for the real scan.
+      SmallString<128> Path = File->getNameAsRequested();
+      HS.getModuleMap().canonicalizeModuleMapPath(Path);
+      Result[Name] = std::string(Path);
+    }
+    return Result;
+  }
+
+private:
+  CompilerInstance &CI;
+  HeaderSearchOptions HSOpts;
+  DiagnosticOptions DiagOpts;
+  DiagnosticsEngine Diags;
+  SourceManager SourceMgr;
+  HeaderSearch HS;
----------------
cyndyishida wrote:

They don't interact. The instance has no `HeaderSearch` at this point, since no 
preprocessor is created for this query. The separate `SourceManager` keeps 
diagnostics from module map searching apart from ones when setting up the 
instance.

https://github.com/llvm/llvm-project/pull/235845
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to