mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Allow module aliases to be expressed in the explicit Swift module map JSON file.
For build systems that already generate these files, it makes sense to include the aliases so that the map file serves as a comprehensive index of how the module inputs are referenced.
This commit is contained in:
committed by
Tony Allevato
parent
2b0f9aa765
commit
8752920875
@@ -2183,6 +2183,14 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
|
||||
return action(info);
|
||||
}
|
||||
|
||||
static void addModuleAliasesFromExplicitSwiftModuleMap(
|
||||
ASTContext &Ctx, llvm::StringMap<std::string> ModuleAliases) {
|
||||
for (auto &entry : ModuleAliases) {
|
||||
Ctx.addModuleAlias(/*moduleAlias=*/entry.getKey(),
|
||||
/*realModule=*/entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
struct ExplicitSwiftModuleLoader::Implementation {
|
||||
ASTContext &Ctx;
|
||||
llvm::BumpPtrAllocator Allocator;
|
||||
@@ -2192,6 +2200,7 @@ struct ExplicitSwiftModuleLoader::Implementation {
|
||||
void parseSwiftExplicitModuleMap(StringRef fileName) {
|
||||
ExplicitModuleMapParser parser(Allocator);
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> ExplicitClangModuleMap;
|
||||
llvm::StringMap<std::string> ModuleAliases;
|
||||
// Load the input file.
|
||||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> fileBufOrErr =
|
||||
llvm::MemoryBuffer::getFile(fileName);
|
||||
@@ -2203,7 +2212,7 @@ struct ExplicitSwiftModuleLoader::Implementation {
|
||||
|
||||
auto hasError = parser.parseSwiftExplicitModuleMap(
|
||||
(*fileBufOrErr)->getMemBufferRef(), ExplicitModuleMap,
|
||||
ExplicitClangModuleMap);
|
||||
ExplicitClangModuleMap, ModuleAliases);
|
||||
|
||||
if (hasError)
|
||||
Ctx.Diags.diagnose(SourceLoc(), diag::explicit_swift_module_map_corrupted,
|
||||
@@ -2230,6 +2239,7 @@ struct ExplicitSwiftModuleLoader::Implementation {
|
||||
.str());
|
||||
}
|
||||
}
|
||||
addModuleAliasesFromExplicitSwiftModuleMap(Ctx, ModuleAliases);
|
||||
}
|
||||
|
||||
void addCommandLineExplicitInputs(
|
||||
@@ -2462,6 +2472,7 @@ struct ExplicitCASModuleLoader::Implementation {
|
||||
void parseSwiftExplicitModuleMap(StringRef ID) {
|
||||
ExplicitModuleMapParser parser(Allocator);
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> ExplicitClangModuleMap;
|
||||
llvm::StringMap<std::string> ModuleAliases;
|
||||
auto buf = loadBuffer(ID);
|
||||
if (!buf) {
|
||||
Ctx.Diags.diagnose(SourceLoc(), diag::error_cas,
|
||||
@@ -2477,7 +2488,8 @@ struct ExplicitCASModuleLoader::Implementation {
|
||||
llvm::MemoryBuffer::getFile(ID);
|
||||
|
||||
auto hasError = parser.parseSwiftExplicitModuleMap(
|
||||
(*buf)->getMemBufferRef(), ExplicitModuleMap, ExplicitClangModuleMap);
|
||||
(*buf)->getMemBufferRef(), ExplicitModuleMap, ExplicitClangModuleMap,
|
||||
ModuleAliases);
|
||||
|
||||
if (hasError)
|
||||
Ctx.Diags.diagnose(SourceLoc(), diag::explicit_swift_module_map_corrupted,
|
||||
@@ -2516,6 +2528,7 @@ struct ExplicitCASModuleLoader::Implementation {
|
||||
extraClangArgs.push_back(*cachePath);
|
||||
}
|
||||
}
|
||||
addModuleAliasesFromExplicitSwiftModuleMap(Ctx, ModuleAliases);
|
||||
}
|
||||
|
||||
void addCommandLineExplicitInputs(
|
||||
|
||||
Reference in New Issue
Block a user