Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 29 additions & 22 deletions lib/Frontend/ModuleInterfaceLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,6 @@ bool InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleN
}

struct ExplicitSwiftModuleLoader::Implementation {

// Information about explicitly specified Swift module files.
struct ExplicitModuleInfo {
// Path of the .swiftmodule file.
Expand All @@ -1451,44 +1450,48 @@ struct ExplicitSwiftModuleLoader::Implementation {
return Saver.save(cast<llvm::yaml::ScalarNode>(N)->getValue(Buffer));
}

bool parseSingleModuleEntry(llvm::yaml::KeyValueNode &node) {
bool parseSingleModuleEntry(llvm::yaml::Node &node) {
using namespace llvm::yaml;
auto moduleName = getScalaNodeText(node.getKey());
auto insertRes = ExplicitModuleMap.insert({moduleName,
ExplicitModuleInfo()});
if (!insertRes.second) {
return true;
}
auto moduleDetails = dyn_cast<MappingNode>(node.getValue());
if (!moduleDetails)
auto *mapNode = dyn_cast<MappingNode>(&node);
if (!mapNode)
return true;
for (auto &entry: *moduleDetails) {
StringRef moduleName;
ExplicitModuleInfo result;
for (auto &entry: *mapNode) {
auto key = getScalaNodeText(entry.getKey());
auto val = getScalaNodeText(entry.getValue());
if (key == "SwiftModulePath") {
insertRes.first->second.modulePath = val;
if (key == "SwiftModule") {
moduleName = val;
} else if (key == "SwiftModulePath") {
result.modulePath = val;
} else if (key == "SwiftDocPath") {
insertRes.first->second.moduleDocPath = val;
result.moduleDocPath = val;
} else if (key == "SwiftSourceInfoPath") {
insertRes.first->second.moduleSourceInfoPath = val;
result.moduleSourceInfoPath = val;
} else {
return true;
// Being forgiving for future fields.
continue;
}
}
if (moduleName.empty())
return true;
ExplicitModuleMap[moduleName] = std::move(result);
return false;
}
// {
// "A": {
// [
// {
// "SwiftModule": "A",
// "SwiftModulePath": "A.swiftmodule",
// "SwiftDocPath": "A.swiftdoc",
// "SwiftSourceInfoPath": "A.swiftsourceinfo"
// },
// "B": {
// {
// "SwiftModule": "B",
// "SwiftModulePath": "B.swiftmodule",
// "SwiftDocPath": "B.swiftdoc",
// "SwiftSourceInfoPath": "B.swiftsourceinfo"
// }
// }
// ]
void parseSwiftExplicitModuleMap(StringRef fileName) {
using namespace llvm::yaml;
// Load the input file.
Expand All @@ -1504,7 +1507,7 @@ struct ExplicitSwiftModuleLoader::Implementation {
Ctx.SourceMgr.getLLVMSourceMgr());
for (auto DI = Stream.begin(); DI != Stream.end(); ++ DI) {
assert(DI != Stream.end() && "Failed to read a document");
if (auto *MN = dyn_cast_or_null<MappingNode>(DI->getRoot())) {
if (auto *MN = dyn_cast_or_null<SequenceNode>(DI->getRoot())) {
for (auto &entry: *MN) {
if (parseSingleModuleEntry(entry)) {
Ctx.Diags.diagnose(SourceLoc(),
Expand Down Expand Up @@ -1559,8 +1562,12 @@ std::error_code ExplicitSwiftModuleLoader::findModuleFilesInDirectory(
auto &fs = *Ctx.SourceMgr.getFileSystem();
// Open .swiftmodule file
auto moduleBuf = fs.getBufferForFile(moduleInfo.modulePath);
if (!moduleBuf)
if (!moduleBuf) {
// We cannot read the module content, diagnose.
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
moduleInfo.modulePath);
return moduleBuf.getError();
}
*ModuleBuffer = std::move(moduleBuf.get());

// Open .swiftdoc file
Expand Down
7 changes: 3 additions & 4 deletions test/ScanDependencies/explicit-module-map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
// RUN: echo "public func foo() {}" >> %t/foo.swift
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/inputs/Foo.swiftmodule -emit-module-doc-path %t/inputs/Foo.swiftdoc -emit-module-source-info -emit-module-source-info-path %t/inputs/Foo.swiftsourceinfo -module-cache-path %t.module-cache %t/foo.swift -module-name Foo

// RUN: echo "{" > %t/inputs/map.json
// RUN: echo "\"Foo\": {" >> %t/inputs/map.json
// RUN: echo "[{" > %t/inputs/map.json
// RUN: echo "\"SwiftModule\": \"Foo\"," >> %t/inputs/map.json
// RUN: echo "\"SwiftModulePath\": \"%t/inputs/Foo.swiftmodule\"," >> %t/inputs/map.json
// RUN: echo "\"SwiftDocPath\": \"%t/inputs/Foo.swiftdoc\"," >> %t/inputs/map.json
// RUN: echo "\"SwiftSourceInfoPath\": \"%t/inputs/Foo.swiftsourceinfo\"" >> %t/inputs/map.json
// RUN: echo "}" >> %t/inputs/map.json
// RUN: echo "}" >> %t/inputs/map.json
// RUN: echo "}]" >> %t/inputs/map.json

// RUN: %target-swift-ide-test -print-module-comments -module-to-print=Foo -enable-swiftsourceinfo -source-filename %s -explicit-swift-module-map-file %t/inputs/map.json | %FileCheck %s

Expand Down