Skip to content

Commit 8460fef

Browse files
committed
[Dependency Scanning] Emit header dependencies of binary Swift module dependencies in output and provide libSwiftScan API to query it
1 parent 6c9d462 commit 8460fef

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ SWIFTSCAN_PUBLIC swiftscan_string_ref_t
168168
swiftscan_swift_binary_detail_get_module_source_info_path(
169169
swiftscan_module_details_t details);
170170

171+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
172+
swiftscan_swift_binary_detail_get_header_dependencies(
173+
swiftscan_module_details_t details);
174+
171175
SWIFTSCAN_PUBLIC bool
172176
swiftscan_swift_binary_detail_get_is_framework(
173177
swiftscan_module_details_t details);

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ typedef struct {
109109
/// The path to the .swiftSourceInfo file.
110110
swiftscan_string_ref_t module_source_info_path;
111111

112+
/// (Clang) header dependencies of this binary module.
113+
/// Typically pre-compiled bridging header.
114+
swiftscan_string_set_t *header_dependencies;
115+
112116
/// A flag to indicate whether or not this module is a framework.
113117
bool is_framework;
114118
} swiftscan_swift_binary_details_t;

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,13 @@ static void writeJSON(llvm::raw_ostream &out,
946946
swiftBinaryDeps->module_source_info_path,
947947
/*indentLevel=*/5,
948948
/*trailingComma=*/true);
949+
950+
// Module Header Dependencies
951+
if (swiftBinaryDeps->header_dependencies->count != 0)
952+
writeJSONSingleField(out, "headerDependencies",
953+
swiftBinaryDeps->header_dependencies, 5,
954+
/*trailingComma=*/true);
955+
949956
writeJSONSingleField(out, "isFramework", swiftBinaryDeps->is_framework,
950957
5, /*trailingComma=*/false);
951958
} else {
@@ -1151,6 +1158,7 @@ generateFullDependencyGraph(CompilerInstance &instance,
11511158
create_clone(swiftBinaryDeps->compiledModulePath.c_str()),
11521159
create_clone(swiftBinaryDeps->moduleDocPath.c_str()),
11531160
create_clone(swiftBinaryDeps->sourceInfoPath.c_str()),
1161+
create_set(swiftBinaryDeps->preCompiledBridgingHeaderPaths),
11541162
swiftBinaryDeps->isFramework};
11551163
} else {
11561164
// Clang module details
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %empty-directory(%t/clang-module-cache)
3+
// RUN: %empty-directory(%t/PCH)
4+
// RUN: %empty-directory(%t/SwiftModules)
5+
6+
// - Set up Foo Swift dependency
7+
// RUN: echo "extension Profiler {" >> %t/foo.swift
8+
// RUN: echo " public static let count: Int = 42" >> %t/foo.swift
9+
// RUN: echo "}" >> %t/foo.swift
10+
11+
// - Set up Foo bridging header
12+
// RUN: echo "struct Profiler { void* ptr; };" >> %t/foo.h
13+
14+
// - Compile bridging header
15+
// RUN: %target-swift-frontend -enable-objc-interop -emit-pch %t/foo.h -o %t/PCH/foo.pch -disable-implicit-swift-modules
16+
17+
// - Set up explicit dependencies for Foo
18+
// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/inputs/SwiftShims.pcm
19+
// RUN: %target-swift-emit-pcm -module-name _SwiftConcurrencyShims %swift-lib-dir/swift/shims/module.modulemap -o %t/inputs/_SwiftConcurrencyShims.pcm
20+
// RUN: echo "[{" > %t/foo_inputs_map.json
21+
// RUN: echo "\"moduleName\": \"Swift\"," >> %t/foo_inputs_map.json
22+
// RUN: echo "\"modulePath\": \"%/stdlib_module\"," >> %t/foo_inputs_map.json
23+
// RUN: echo "\"isFramework\": false" >> %t/foo_inputs_map.json
24+
// RUN: echo "}," >> %t/foo_inputs_map.json
25+
// RUN: echo "{" >> %t/foo_inputs_map.json
26+
// RUN: echo "\"moduleName\": \"SwiftOnoneSupport\"," >> %t/foo_inputs_map.json
27+
// RUN: echo "\"modulePath\": \"%/ononesupport_module\"," >> %t/foo_inputs_map.json
28+
// RUN: echo "\"isFramework\": false" >> %t/foo_inputs_map.json
29+
// RUN: echo "}," >> %t/foo_inputs_map.json
30+
// RUN: echo "{" >> %t/foo_inputs_map.json
31+
// RUN: echo "\"moduleName\": \"_StringProcessing\"," >> %t/foo_inputs_map.json
32+
// RUN: echo "\"modulePath\": \"%/string_processing_module\"," >> %t/foo_inputs_map.json
33+
// RUN: echo "\"isFramework\": false" >> %t/foo_inputs_map.json
34+
// RUN: echo "}," >> %t/foo_inputs_map.json
35+
// RUN: echo "{" >> %t/foo_inputs_map.json
36+
// RUN: echo "\"moduleName\": \"SwiftShims\"," >> %t/foo_inputs_map.json
37+
// RUN: echo "\"isFramework\": false," >> %t/foo_inputs_map.json
38+
// RUN: echo "\"clangModuleMapPath\": \"%swift-lib-dir/swift/shims/module.modulemap\"," >> %t/foo_inputs_map.json
39+
// RUN: echo "\"clangModulePath\": \"%t/inputs/SwiftShims.pcm\"" >> %t/foo_inputs_map.json
40+
// RUN: echo "}," >> %t/foo_inputs_map.json
41+
// RUN: echo "{" >> %t/foo_inputs_map.json
42+
// RUN: echo "\"moduleName\": \"_SwiftConcurrencyShims\"," >> %t/foo_inputs_map.json
43+
// RUN: echo "\"isFramework\": false," >> %t/foo_inputs_map.json
44+
// RUN: echo "\"clangModuleMapPath\": \"%swift-lib-dir/swift/shims/module.modulemap\"," >> %t/foo_inputs_map.json
45+
// RUN: echo "\"clangModulePath\": \"%t/inputs/_SwiftConcurrencyShims.pcm\"" >> %t/foo_inputs_map.json
46+
// RUN: echo "}]" >> %t/foo_inputs_map.json
47+
48+
// - Build Foo module dependency, explicitly
49+
// RUN: %target-swift-frontend -emit-module -emit-module-path %t/SwiftModules/Foo.swiftmodule %t/foo.swift -module-name Foo -import-objc-header %t/PCH/foo.pch -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -explicit-swift-module-map-file %t/foo_inputs_map.json
50+
51+
// - Scan main module
52+
// RUN: %target-swift-frontend -scan-dependencies %s -I %t/SwiftModules 2>&1 | %FileCheck %s
53+
54+
//
55+
// CHECK: "swiftPrebuiltExternal": "Foo"
56+
// CHECK: "swiftPrebuiltExternal": "Foo"
57+
// CHECK: "headerDependencies": [
58+
// CHECK: "{{.*}}{{/|\\}}PCH{{/|\\}}foo.pch"
59+
// CHECK: ],
60+
61+
import Foo
62+
print(Profiler.count)

tools/libSwiftScan/libSwiftScan.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,12 @@ swiftscan_swift_binary_detail_get_module_source_info_path(
314314
return details->swift_binary_details.module_source_info_path;
315315
}
316316

317+
swiftscan_string_set_t *
318+
swiftscan_swift_binary_detail_get_header_dependencies(
319+
swiftscan_module_details_t details) {
320+
return details->swift_binary_details.header_dependencies;
321+
}
322+
317323
bool swiftscan_swift_binary_detail_get_is_framework(
318324
swiftscan_module_details_t details) {
319325
return details->swift_binary_details.is_framework;

tools/libSwiftScan/libSwiftScan.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ swiftscan_swift_textual_detail_get_swift_overlay_dependencies
1919
swiftscan_swift_binary_detail_get_compiled_module_path
2020
swiftscan_swift_binary_detail_get_module_doc_path
2121
swiftscan_swift_binary_detail_get_module_source_info_path
22+
swiftscan_swift_binary_detail_get_header_dependencies
2223
swiftscan_swift_binary_detail_get_is_framework
2324
swiftscan_swift_placeholder_detail_get_compiled_module_path
2425
swiftscan_swift_placeholder_detail_get_module_doc_path

0 commit comments

Comments
 (0)