Skip to content

Commit 782e41b

Browse files
authored
Merge pull request #62540 from artemcm/BinaryExplicitDependencyIsFramework
[Dependency Scanning] Record whether discovered binary Swift modules are frameworks
2 parents 6ee4c17 + 3db7678 commit 782e41b

File tree

10 files changed

+51
-7
lines changed

10 files changed

+51
-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/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,
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/clang-module-cache
3+
// RUN: mkdir -p %t/Frameworks
4+
// RUN: mkdir -p %t/Frameworks/Foo.framework/
5+
// RUN: mkdir -p %t/Frameworks/Foo.framework/Modules
6+
// RUN: mkdir -p %t/Frameworks/Foo.framework/Modules/Foo.swiftmodule
7+
8+
// Build a dependency into a binary module
9+
// RUN: echo "public func foo() {}" >> %t/foo.swift
10+
// 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
11+
12+
// Run the scan
13+
// RUN: %target-swift-frontend -scan-dependencies %s -o %t/deps.json -F %t/Frameworks/ -sdk %t
14+
// RUN: %FileCheck %s < %t/deps.json
15+
16+
import Foo
17+
18+
// CHECK: "swiftPrebuiltExternal": "Foo"
19+
// CHECK: "swiftPrebuiltExternal": "Foo"
20+
// CHECK-NEXT: },
21+
// CHECK-NEXT: {
22+
// CHECK-NEXT: "modulePath":
23+
// CHECK-NEXT: "directDependencies": [
24+
// CHECK: "details": {
25+
// CHECK-NEXT: "swiftPrebuiltExternal": {
26+
// CHECK-NEXT: "compiledModulePath":
27+
// CHECK-NEXT: "isFramework": true
28+
// CHECK-NEXT: }

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)