Skip to content

Commit fa5812f

Browse files
committed
[Dependency Scanning] Record whether discovered binary Swift modules are frameworks
Part of rdar://102824777
1 parent a7726f1 commit fa5812f

File tree

10 files changed

+41
-7
lines changed

10 files changed

+41
-7
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
164164
swiftscan_swift_binary_detail_get_module_source_info_path(
165165
swiftscan_module_details_t details);
166166

167+
SWIFTSCAN_PUBLIC bool
168+
swiftscan_swift_binary_detail_get_is_framework(
169+
swiftscan_module_details_t details);
170+
167171
//=== Swift Placeholder Module Details query APIs -------------------------===//
168172

169173
SWIFTSCAN_PUBLIC swiftscan_string_ref_t

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ typedef struct {
104104

105105
/// The path to the .swiftSourceInfo file.
106106
swiftscan_string_ref_t module_source_info_path;
107+
108+
/// A flag to indicate whether or not this module is a framework.
109+
bool is_framework;
107110
} swiftscan_swift_binary_details_t;
108111

109112
/// Swift placeholder modules carry additional details that specify their

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
137137
}
138138

139139
/// Scan the given serialized module file to determine dependencies.
140-
llvm::ErrorOr<ModuleDependencies> scanModuleFile(Twine modulePath);
140+
llvm::ErrorOr<ModuleDependencies> scanModuleFile(Twine modulePath, bool isFramework);
141141

142142
/// Load the module file into a buffer and also collect its module name.
143143
static std::unique_ptr<llvm::MemoryBuffer>

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(ModuleDependencyID modul
838838
Out, ScratchRecord, AbbrCodes[SwiftBinaryModuleDetailsLayout::Code],
839839
getIdentifier(swiftBinDeps->compiledModulePath),
840840
getIdentifier(swiftBinDeps->moduleDocPath),
841-
getIdentifier(swiftBinDeps->sourceInfoPath), swiftBinDeps->isFramework);
841+
getIdentifier(swiftBinDeps->sourceInfoPath),
842+
swiftBinDeps->isFramework);
842843

843844
break;
844845
}

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,9 @@ static void writeJSON(llvm::raw_ostream &out,
728728
writeJSONSingleField(out, "moduleSourceInfoPath",
729729
swiftBinaryDeps->module_source_info_path,
730730
/*indentLevel=*/5,
731-
/*trailingComma=*/false);
731+
/*trailingComma=*/true);
732+
writeJSONSingleField(out, "isFramework", swiftBinaryDeps->is_framework,
733+
5, /*trailingComma=*/false);
732734
} else {
733735
out << "\"clang\": {\n";
734736

@@ -893,7 +895,8 @@ generateFullDependencyGraph(CompilerInstance &instance,
893895
details->swift_binary_details = {
894896
create_clone(swiftBinaryDeps->compiledModulePath.c_str()),
895897
create_clone(swiftBinaryDeps->moduleDocPath.c_str()),
896-
create_clone(swiftBinaryDeps->sourceInfoPath.c_str())};
898+
create_clone(swiftBinaryDeps->sourceInfoPath.c_str()),
899+
swiftBinaryDeps->isFramework};
897900
} else {
898901
// Clang module details
899902
details->kind = SWIFTSCAN_DEPENDENCY_INFO_CLANG;

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,6 +1993,24 @@ bool ExplicitSwiftModuleLoader::canImportModule(
19931993
if (it == Impl.ExplicitModuleMap.end()) {
19941994
return false;
19951995
}
1996+
1997+
// If the caller doesn't want version info we're done.
1998+
if (!versionInfo)
1999+
return true;
2000+
2001+
// Open .swiftmodule file and read out the version
2002+
auto &fs = *Ctx.SourceMgr.getFileSystem();
2003+
auto moduleBuf = fs.getBufferForFile(it->second.modulePath);
2004+
if (!moduleBuf) {
2005+
Ctx.Diags.diagnose(SourceLoc(), diag::error_opening_explicit_module_file,
2006+
it->second.modulePath);
2007+
return false;
2008+
}
2009+
auto metaData = serialization::validateSerializedAST(
2010+
(*moduleBuf)->getBuffer(), Ctx.SILOpts.EnableOSSAModules,
2011+
Ctx.LangOpts.SDKName, !Ctx.LangOpts.DebuggerSupport);
2012+
versionInfo->setVersion(metaData.userModuleVersion,
2013+
ModuleVersionSourceKind::SwiftBinaryModule);
19962014
return true;
19972015
}
19982016

lib/Serialization/ModuleDependencyScanner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ std::error_code ModuleDependencyScanner::findModuleFilesInDirectory(
4343
if (LoadMode == ModuleLoadingMode::OnlySerialized || !fs.exists(InPath)) {
4444
if (fs.exists(ModPath)) {
4545
// The module file will be loaded directly.
46-
auto dependencies = scanModuleFile(ModPath);
46+
auto dependencies = scanModuleFile(ModPath, IsFramework);
4747
if (dependencies) {
4848
this->dependencies = std::move(dependencies.get());
4949
return std::error_code();

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
392392
}
393393

394394
llvm::ErrorOr<ModuleDependencies> SerializedModuleLoaderBase::scanModuleFile(
395-
Twine modulePath) {
395+
Twine modulePath, bool isFramework) {
396396
// Open the module file
397397
auto &fs = *Ctx.SourceMgr.getFileSystem();
398398
auto moduleBuf = fs.getBufferForFile(modulePath);
@@ -401,7 +401,6 @@ llvm::ErrorOr<ModuleDependencies> SerializedModuleLoaderBase::scanModuleFile(
401401

402402
// Load the module file without validation.
403403
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFile;
404-
bool isFramework = false;
405404
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
406405
modulePath.str(), std::move(moduleBuf.get()), nullptr, nullptr,
407406
isFramework, isRequiredOSSAModules(), Ctx.LangOpts.SDKName,

tools/libSwiftScan/libSwiftScan.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,11 @@ swiftscan_swift_binary_detail_get_module_source_info_path(
311311
return details->swift_binary_details.module_source_info_path;
312312
}
313313

314+
bool swiftscan_swift_binary_detail_get_is_framework(
315+
swiftscan_module_details_t details) {
316+
return details->swift_binary_details.is_framework;
317+
}
318+
314319
//=== Swift Placeholder Module Details query APIs -------------------------===//
315320

316321
swiftscan_string_ref_t

tools/libSwiftScan/libSwiftScan.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ swiftscan_swift_textual_detail_get_is_framework
1818
swiftscan_swift_binary_detail_get_compiled_module_path
1919
swiftscan_swift_binary_detail_get_module_doc_path
2020
swiftscan_swift_binary_detail_get_module_source_info_path
21+
swiftscan_swift_binary_detail_get_is_framework
2122
swiftscan_swift_placeholder_detail_get_compiled_module_path
2223
swiftscan_swift_placeholder_detail_get_module_doc_path
2324
swiftscan_swift_placeholder_detail_get_module_source_info_path

0 commit comments

Comments
 (0)