Module aliasing: Use real module names with -scan-dependencies

Resolves rdar://85991587
This commit is contained in:
Ellie Shin
2021-12-01 19:28:04 -08:00
parent 32c8bbe12c
commit 5da881256f
4 changed files with 66 additions and 7 deletions

View File

@@ -1685,6 +1685,7 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
if (subInstance.setup(subInvocation)) {
return std::make_error_code(std::errc::not_supported);
}
info.BuildArguments = BuildArgs;
info.Hash = CacheHash;
auto target = *(std::find(BuildArgs.rbegin(), BuildArgs.rend(), "-target") - 1);
@@ -1826,7 +1827,12 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
bool ExplicitSwiftModuleLoader::canImportModule(
ImportPath::Element mID, llvm::VersionTuple version, bool underlyingVersion) {
StringRef moduleName = mID.Item.str();
// Look up the module with the real name (physical name on disk);
// in case `-module-alias` is used, the name appearing in source files
// and the real module name are different. For example, '-module-alias Foo=Bar'
// maps Foo appearing in source files, e.g. 'import Foo', to the real module
// name Bar (on-disk name), which should be searched for loading.
StringRef moduleName = Ctx.getRealModuleName(mID.Item).str();
auto it = Impl.ExplicitModuleMap.find(moduleName);
// If no provided explicit module matches the name, then it cannot be imported.
if (it == Impl.ExplicitModuleMap.end()) {