Allow Clang modules to be listed in the explicit module map.

This lets users of `-explicit-swift-module-map-file` use a single mapping
for all module dependencies, regardless of whether they're Swift or Clang
modules, instead of manually splitting them among this file and command
line flags.
This commit is contained in:
Tony Allevato
2023-01-22 19:34:28 -08:00
parent 0f266b8919
commit dda1cda4df
6 changed files with 188 additions and 17 deletions

View File

@@ -554,6 +554,20 @@ bool CompilerInstance::setUpModuleLoaders() {
Context->addModuleLoader(std::move(MemoryBufferLoader));
}
// If using `-explicit-swift-module-map-file`, create the explicit loader
// before creating `ClangImporter` because the entries in the map influence
// the Clang flags. The loader is added to the context below.
std::unique_ptr<ExplicitSwiftModuleLoader> ESML = nullptr;
bool ExplicitModuleBuild =
Invocation.getFrontendOptions().DisableImplicitModules;
if (ExplicitModuleBuild ||
!Invocation.getSearchPathOptions().ExplicitSwiftModuleMap.empty()) {
ESML = ExplicitSwiftModuleLoader::create(
*Context, getDependencyTracker(), MLM,
Invocation.getSearchPathOptions().ExplicitSwiftModuleMap,
IgnoreSourceInfoFile);
}
// Wire up the Clang importer. If the user has specified an SDK, use it.
// Otherwise, we just keep it around as our interface to Clang's ABI
// knowledge.
@@ -575,15 +589,9 @@ bool CompilerInstance::setUpModuleLoaders() {
*Context, ModuleCachePath, FEOpts.PrebuiltModuleCachePath,
FEOpts.BackupModuleInterfaceDir, LoaderOpts,
RequireOSSAModules_t(Invocation.getSILOptions())));
// If implicit modules are disabled, we need to install an explicit module
// loader.
bool ExplicitModuleBuild = Invocation.getFrontendOptions().DisableImplicitModules;
if (ExplicitModuleBuild || !Invocation.getSearchPathOptions().ExplicitSwiftModuleMap.empty()) {
auto ESML = ExplicitSwiftModuleLoader::create(
*Context,
getDependencyTracker(), MLM,
Invocation.getSearchPathOptions().ExplicitSwiftModuleMap,
IgnoreSourceInfoFile);
// Install an explicit module loader if it was created earlier.
if (ESML) {
this->DefaultSerializedLoader = ESML.get();
Context->addModuleLoader(std::move(ESML));
}