Skip to content

Commit f85d496

Browse files
authored
Merge pull request #38738 from nkcsgexi/system-explicit
ExplicitModuleLoader: allow explicit module input map to indicate whether a module is a system module
2 parents 6964a7d + 9cdc39d commit f85d496

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ struct ExplicitModuleInfo {
181181
std::string moduleSourceInfoPath;
182182
// A flag that indicates whether this module is a framework
183183
bool isFramework;
184+
// A flag that indicates whether this module is a system module
185+
// Set the default to be false.
186+
bool isSystem = false;
184187
};
185188

186189
/// Parser of explicit module maps passed into the compiler.
@@ -239,7 +242,18 @@ class ExplicitModuleMapParser {
239242
SmallString<32> Buffer;
240243
return Saver.save(cast<llvm::yaml::ScalarNode>(N)->getValue(Buffer));
241244
}
242-
245+
246+
static bool parseBoolValue(StringRef val) {
247+
auto valStr = val.str();
248+
valStr.erase(std::remove(valStr.begin(), valStr.end(), '\n'), valStr.end());
249+
if (valStr.compare("true") == 0)
250+
return true;
251+
else if (valStr.compare("false") == 0)
252+
return false;
253+
else
254+
llvm_unreachable("Unexpected JSON value for isFramework");
255+
}
256+
243257
bool parseSingleModuleEntry(llvm::yaml::Node &node,
244258
llvm::StringMap<ExplicitModuleInfo> &moduleMap) {
245259
using namespace llvm::yaml;
@@ -260,14 +274,9 @@ class ExplicitModuleMapParser {
260274
} else if (key == "sourceInfoPath") {
261275
result.moduleSourceInfoPath = val.str();
262276
} else if (key == "isFramework") {
263-
auto valStr = val.str();
264-
valStr.erase(std::remove(valStr.begin(), valStr.end(), '\n'), valStr.end());
265-
if (valStr.compare("true") == 0)
266-
result.isFramework = true;
267-
else if (valStr.compare("false") == 0)
268-
result.isFramework = false;
269-
else
270-
llvm_unreachable("Unexpected JSON value for isFramework");
277+
result.isFramework = parseBoolValue(val);
278+
} else if (key == "isSystem") {
279+
result.isSystem = parseBoolValue(val);
271280
} else {
272281
// Being forgiving for future fields.
273282
continue;

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,7 @@ bool ExplicitSwiftModuleLoader::findModule(ImportPath::Element ModuleID,
17221722

17231723
// Set IsFramework bit according to the moduleInfo
17241724
IsFramework = moduleInfo.isFramework;
1725+
IsSystemModule = moduleInfo.isSystem;
17251726

17261727
auto &fs = *Ctx.SourceMgr.getFileSystem();
17271728
// Open .swiftmodule file

test/ScanDependencies/placholder_overlay_deps.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
// RUN: echo "\"modulePath\": \"%/t/inputs/Darwin.swiftmodule\"," >> %/t/inputs/map.json
88
// RUN: echo "\"docPath\": \"%/t/inputs/Darwin.swiftdoc\"," >> %/t/inputs/map.json
99
// RUN: echo "\"sourceInfoPath\": \"%/t/inputs/Darwin.swiftsourceinfo\"," >> %/t/inputs/map.json
10-
// RUN: echo "\"isFramework\": false" >> %/t/inputs/map.json
10+
// RUN: echo "\"isFramework\": false," >> %/t/inputs/map.json
11+
// RUN: echo "\"isSystem\": true" >> %/t/inputs/map.json
1112
// RUN: echo "}]" >> %/t/inputs/map.json
1213

1314
// RUN: %target-swift-frontend -scan-dependencies -module-cache-path %t/clang-module-cache %s -placeholder-dependency-module-map-file %t/inputs/map.json -o %t/deps.json

0 commit comments

Comments
 (0)