Skip to content

[Dependency Scanning] Record whether discovered binary Swift modules are frameworks #62540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2022
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
4 changes: 4 additions & 0 deletions include/swift-c/DependencyScan/DependencyScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
swiftscan_swift_binary_detail_get_module_source_info_path(
swiftscan_module_details_t details);

SWIFTSCAN_PUBLIC bool
swiftscan_swift_binary_detail_get_is_framework(
swiftscan_module_details_t details);

//=== Swift Placeholder Module Details query APIs -------------------------===//

SWIFTSCAN_PUBLIC swiftscan_string_ref_t
Expand Down
3 changes: 3 additions & 0 deletions include/swift/DependencyScan/DependencyScanImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ typedef struct {

/// The path to the .swiftSourceInfo file.
swiftscan_string_ref_t module_source_info_path;

/// A flag to indicate whether or not this module is a framework.
bool is_framework;
} swiftscan_swift_binary_details_t;

/// Swift placeholder modules carry additional details that specify their
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Serialization/SerializedModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class SerializedModuleLoaderBase : public ModuleLoader {
}

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

/// Load the module file into a buffer and also collect its module name.
static std::unique_ptr<llvm::MemoryBuffer>
Expand Down
3 changes: 2 additions & 1 deletion lib/DependencyScan/ModuleDependencyCacheSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,8 @@ void ModuleDependenciesCacheSerializer::writeModuleInfo(ModuleDependencyID modul
Out, ScratchRecord, AbbrCodes[SwiftBinaryModuleDetailsLayout::Code],
getIdentifier(swiftBinDeps->compiledModulePath),
getIdentifier(swiftBinDeps->moduleDocPath),
getIdentifier(swiftBinDeps->sourceInfoPath), swiftBinDeps->isFramework);
getIdentifier(swiftBinDeps->sourceInfoPath),
swiftBinDeps->isFramework);

break;
}
Expand Down
7 changes: 5 additions & 2 deletions lib/DependencyScan/ScanDependencies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,9 @@ static void writeJSON(llvm::raw_ostream &out,
writeJSONSingleField(out, "moduleSourceInfoPath",
swiftBinaryDeps->module_source_info_path,
/*indentLevel=*/5,
/*trailingComma=*/false);
/*trailingComma=*/true);
writeJSONSingleField(out, "isFramework", swiftBinaryDeps->is_framework,
5, /*trailingComma=*/false);
} else {
out << "\"clang\": {\n";

Expand Down Expand Up @@ -893,7 +895,8 @@ generateFullDependencyGraph(CompilerInstance &instance,
details->swift_binary_details = {
create_clone(swiftBinaryDeps->compiledModulePath.c_str()),
create_clone(swiftBinaryDeps->moduleDocPath.c_str()),
create_clone(swiftBinaryDeps->sourceInfoPath.c_str())};
create_clone(swiftBinaryDeps->sourceInfoPath.c_str()),
swiftBinaryDeps->isFramework};
} else {
// Clang module details
details->kind = SWIFTSCAN_DEPENDENCY_INFO_CLANG;
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/ModuleDependencyScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ std::error_code ModuleDependencyScanner::findModuleFilesInDirectory(
if (LoadMode == ModuleLoadingMode::OnlySerialized || !fs.exists(InPath)) {
if (fs.exists(ModPath)) {
// The module file will be loaded directly.
auto dependencies = scanModuleFile(ModPath);
auto dependencies = scanModuleFile(ModPath, IsFramework);
if (dependencies) {
this->dependencies = std::move(dependencies.get());
return std::error_code();
Expand Down
3 changes: 1 addition & 2 deletions lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ std::error_code SerializedModuleLoaderBase::openModuleFile(
}

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

// Load the module file without validation.
std::shared_ptr<const ModuleFileSharedCore> loadedModuleFile;
bool isFramework = false;
serialization::ValidationInfo loadInfo = ModuleFileSharedCore::load(
modulePath.str(), std::move(moduleBuf.get()), nullptr, nullptr,
isFramework, isRequiredOSSAModules(), Ctx.LangOpts.SDKName,
Expand Down
28 changes: 28 additions & 0 deletions test/ScanDependencies/binary_framework_dependency.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %empty-directory(%t)
// RUN: mkdir -p %t/clang-module-cache
// RUN: mkdir -p %t/Frameworks
// RUN: mkdir -p %t/Frameworks/Foo.framework/
// RUN: mkdir -p %t/Frameworks/Foo.framework/Modules
// RUN: mkdir -p %t/Frameworks/Foo.framework/Modules/Foo.swiftmodule

// Build a dependency into a binary module
// RUN: echo "public func foo() {}" >> %t/foo.swift
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/Frameworks/Foo.framework/Modules/Foo.swiftmodule/%target-cpu.swiftmodule -module-cache-path %t.module-cache %t/foo.swift -module-name Foo

// Run the scan
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -F %t/Frameworks/ -sdk %t
// RUN: %FileCheck %s < %t/deps.json

import Foo

// CHECK: "swiftPrebuiltExternal": "Foo"
// CHECK: "swiftPrebuiltExternal": "Foo"
// CHECK-NEXT: },
// CHECK-NEXT: {
// CHECK-NEXT: "modulePath":
// CHECK-NEXT: "directDependencies": [
// CHECK: "details": {
// CHECK-NEXT: "swiftPrebuiltExternal": {
// CHECK-NEXT: "compiledModulePath":
// CHECK-NEXT: "isFramework": true
// CHECK-NEXT: }
5 changes: 5 additions & 0 deletions tools/libSwiftScan/libSwiftScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ swiftscan_swift_binary_detail_get_module_source_info_path(
return details->swift_binary_details.module_source_info_path;
}

bool swiftscan_swift_binary_detail_get_is_framework(
swiftscan_module_details_t details) {
return details->swift_binary_details.is_framework;
}

//=== Swift Placeholder Module Details query APIs -------------------------===//

swiftscan_string_ref_t
Expand Down
1 change: 1 addition & 0 deletions tools/libSwiftScan/libSwiftScan.exports
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ swiftscan_swift_textual_detail_get_is_framework
swiftscan_swift_binary_detail_get_compiled_module_path
swiftscan_swift_binary_detail_get_module_doc_path
swiftscan_swift_binary_detail_get_module_source_info_path
swiftscan_swift_binary_detail_get_is_framework
swiftscan_swift_placeholder_detail_get_compiled_module_path
swiftscan_swift_placeholder_detail_get_module_doc_path
swiftscan_swift_placeholder_detail_get_module_source_info_path
Expand Down