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
@@ -318,10 +318,11 @@ class ExplicitModuleMapParser {
|
||||
public:
|
||||
ExplicitModuleMapParser(llvm::BumpPtrAllocator &Allocator) : Saver(Allocator) {}
|
||||
|
||||
std::error_code
|
||||
parseSwiftExplicitModuleMap(llvm::MemoryBufferRef BufferRef,
|
||||
llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap) {
|
||||
std::error_code parseSwiftExplicitModuleMap(
|
||||
llvm::MemoryBufferRef BufferRef,
|
||||
llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap,
|
||||
llvm::StringMap<std::string> &moduleAliases) {
|
||||
using namespace llvm::yaml;
|
||||
// Use a new source manager instead of the one from ASTContext because we
|
||||
// don't want the JSON file to be persistent.
|
||||
@@ -331,7 +332,8 @@ public:
|
||||
assert(DI != Stream.end() && "Failed to read a document");
|
||||
if (auto *MN = dyn_cast_or_null<SequenceNode>(DI->getRoot())) {
|
||||
for (auto &entry : *MN) {
|
||||
if (parseSingleModuleEntry(entry, swiftModuleMap, clangModuleMap)) {
|
||||
if (parseSingleModuleEntry(entry, swiftModuleMap, clangModuleMap,
|
||||
moduleAliases)) {
|
||||
return std::make_error_code(std::errc::invalid_argument);
|
||||
}
|
||||
}
|
||||
@@ -359,16 +361,19 @@ private:
|
||||
llvm_unreachable("Unexpected JSON value for isFramework");
|
||||
}
|
||||
|
||||
bool parseSingleModuleEntry(llvm::yaml::Node &node,
|
||||
llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap) {
|
||||
bool parseSingleModuleEntry(
|
||||
llvm::yaml::Node &node,
|
||||
llvm::StringMap<ExplicitSwiftModuleInputInfo> &swiftModuleMap,
|
||||
llvm::StringMap<ExplicitClangModuleInputInfo> &clangModuleMap,
|
||||
llvm::StringMap<std::string> &moduleAliases) {
|
||||
using namespace llvm::yaml;
|
||||
auto *mapNode = dyn_cast<MappingNode>(&node);
|
||||
if (!mapNode)
|
||||
return true;
|
||||
StringRef moduleName;
|
||||
std::optional<std::string> swiftModulePath, swiftModuleDocPath,
|
||||
swiftModuleSourceInfoPath, swiftModuleCacheKey, clangModuleCacheKey;
|
||||
swiftModuleSourceInfoPath, swiftModuleCacheKey, clangModuleCacheKey,
|
||||
moduleAlias;
|
||||
std::optional<std::vector<std::string>> headerDependencyPaths;
|
||||
std::string clangModuleMapPath = "", clangModulePath = "";
|
||||
bool isFramework = false, isSystem = false,
|
||||
@@ -405,6 +410,8 @@ private:
|
||||
clangModuleCacheKey = val.str();
|
||||
} else if (key == "isBridgingHeaderDependency") {
|
||||
isBridgingHeaderDependency = parseBoolValue(val);
|
||||
} else if (key == "moduleAlias") {
|
||||
moduleAlias = val.str();
|
||||
} else {
|
||||
// Being forgiving for future fields.
|
||||
continue;
|
||||
@@ -439,6 +446,9 @@ private:
|
||||
clangModuleCacheKey);
|
||||
didInsert = clangModuleMap.try_emplace(moduleName, std::move(entry)).second;
|
||||
}
|
||||
if (didInsert && moduleAlias.has_value()) {
|
||||
moduleAliases[*moduleAlias] = moduleName;
|
||||
}
|
||||
// Prevent duplicate module names.
|
||||
return !didInsert;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user