|
| 1 | +// REQUIRES: objc_interop |
| 2 | +// RUN: %empty-directory(%t) |
| 3 | +// RUN: %empty-directory(%t/FooInputs) |
| 4 | +// RUN: %empty-directory(%t/BridgingHeaderDir) |
| 5 | +// RUN: %empty-directory(%t/TestCHeaders) |
| 6 | +// RUN: %empty-directory(%t/TestSwiftInterfaces) |
| 7 | +// RUN: %empty-directory(%t/FooModuleDir) |
| 8 | +// RUN: split-file %s %t |
| 9 | + |
| 10 | +// - Fixup the input module file map |
| 11 | +// RUN: sed -e "s|INPUTSDIR|%/t/FooInputs|g" %t/map.json.template > %t/map.json.template1 |
| 12 | +// RUN: sed -e "s|STDLIBMOD|%/stdlib_module|g" %t/map.json.template1 > %t/map.json.template2 |
| 13 | +// RUN: sed -e "s|ONONEMOD|%/ononesupport_module|g" %t/map.json.template2 > %t/map.json.template3 |
| 14 | +// RUN: sed -e "s|SWIFTLIBDIR|%swift-lib-dir|g" %t/map.json.template3 > %t/map.json |
| 15 | + |
| 16 | +// - Set up explicit dependencies for Foo |
| 17 | +// RUN: %target-swift-emit-pcm -module-name SwiftShims %swift-lib-dir/swift/shims/module.modulemap -o %t/FooInputs/SwiftShims.pcm |
| 18 | +// - Build Foo module dependency, explicitly, non-resiliently |
| 19 | +// RUN: %target-swift-frontend -emit-module -emit-module-path %t/FooModuleDir/Foo.swiftmodule %t/foo.swift -module-name Foo -import-objc-header %t/BridgingHeaderDir/foo.h -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -disable-implicit-swift-modules -explicit-swift-module-map-file %t/map.json -I %S/Inputs/CHeaders |
| 20 | + |
| 21 | +// - Scan main module and ensure that the "FooClient" recipe includes the modulemap for Foo's briding header's module dependencies |
| 22 | +// but not other dependencies |
| 23 | +// RUN: %target-swift-frontend -scan-dependencies %t/bridging_header_dep_module_map.swift -I %t/FooModuleDir -I %t/TestSwiftInterfaces -I %t/TestCHeaders -I %S/Inputs/CHeaders -o %t/deps.json |
| 24 | +// RUN: %validate-json %t/deps.json | %FileCheck %s |
| 25 | + |
| 26 | +// Given the following dependency graph: |
| 27 | +// |
| 28 | +// main |
| 29 | +// | |
| 30 | +// FooClient (.swiftinterface) |
| 31 | +// | \ |
| 32 | +// Foo(.swiftmodule) Dart (.pcm) |
| 33 | +// |
| 34 | +// Given that 'Foo.swiftmodule' is built with a bridging header which imports 'X.h' ('X' clang module) |
| 35 | +// We expect that 'Foo' will have a dependency on module 'X', and the scanner will ensure that 'FooClient' is built |
| 36 | +// with the modulemap file for 'X' as an explicit input. 'Dart' Clang module however, must not result in an |
| 37 | +// explicitly-specified modulemap file because no headers of this module will be ingested into the Swift |
| 38 | +// compiler. |
| 39 | + |
| 40 | +// Dependency of the main module |
| 41 | +// CHECK: "swift": "FooClient" |
| 42 | + |
| 43 | +// Definition of 'FooClient' in the dependency graph |
| 44 | +// CHECK: "swift": "FooClient" |
| 45 | +// CHECK: "modulePath": "{{.*}}FooClient-{{.*}}.swiftmodule", |
| 46 | +// CHECK: "directDependencies": [ |
| 47 | +// CHECK-DAG: "swiftPrebuiltExternal": "Foo" |
| 48 | +// CHECK-DAG: "swift": "SwiftOnoneSupport" |
| 49 | +// CHECK-DAG: "clang": "Dart" |
| 50 | +// CHECK: ], |
| 51 | +// CHECK: "commandLine": [ |
| 52 | +// CHECK: "-fmodule-map-file={{.*}}{{/|\\}}CHeaders{{/|\\}}module.modulemap" |
| 53 | +// CHECK-NOT: "-fmodule-map-file={{.*}}{{/|\\}}TestCHeaders{{/|\\}}module.modulemap" |
| 54 | +// CHECK: ] |
| 55 | + |
| 56 | +// Definition of 'Foo' in the dependency graph |
| 57 | +// CHECK: "swiftPrebuiltExternal": "Foo" |
| 58 | +// CHECK: "modulePath": "{{.*}}Foo.swiftmodule", |
| 59 | +// CHECK-NEXT: "directDependencies": [ |
| 60 | +// CHECK-DAG: "swift": "Swift" |
| 61 | +// CHECK-DAG: "swift": "SwiftOnoneSupport" |
| 62 | +// CHECK-DAG: "clang": "X" |
| 63 | +// CHECK: ], |
| 64 | +// CHECK: "headerDependency": "{{.*}}{{/|\\}}BridgingHeaderDir{{/|\\}}foo.h" |
| 65 | +// CHECK: "headerModuleDependencies": [ |
| 66 | +// CHECK-NEXT: "X" |
| 67 | +// CHECK-NEXT: ], |
| 68 | +// CHECK: "headerDependenciesSourceFiles": [ |
| 69 | +// CHECK-NEXT: "{{.*}}{{/|\\}}BridgingHeaderDir{{/|\\}}foo.h" |
| 70 | +// CHECK-NEXT: ], |
| 71 | + |
| 72 | +//--- foo.swift |
| 73 | +extension Profiler { |
| 74 | + public static let count: Int = 42 |
| 75 | +} |
| 76 | + |
| 77 | +//--- BridgingHeaderDir/foo.h |
| 78 | +#include "X.h" |
| 79 | +struct Profiler { void* ptr; }; |
| 80 | + |
| 81 | +//--- TestCHeaders/Dart.h |
| 82 | +struct Dart { void* ptr; }; |
| 83 | +//--- TestCHeaders/module.modulemap |
| 84 | +module Dart { |
| 85 | + header "Dart.h" |
| 86 | + export * |
| 87 | +} |
| 88 | + |
| 89 | +//--- TestSwiftInterfaces/FooClient.swiftinterface |
| 90 | +// swift-interface-format-version: 1.0 |
| 91 | +// swift-module-flags: -module-name FooClient |
| 92 | +import Foo |
| 93 | +import Dart |
| 94 | + |
| 95 | +//--- map.json.template |
| 96 | +[ |
| 97 | + { |
| 98 | + "moduleName": "Swift", |
| 99 | + "modulePath": "STDLIBMOD", |
| 100 | + "isFramework": false |
| 101 | + }, |
| 102 | + { |
| 103 | + "moduleName": "SwiftOnoneSupport", |
| 104 | + "modulePath": "ONONEMOD", |
| 105 | + "isFramework": false |
| 106 | + }, |
| 107 | + { |
| 108 | + "moduleName": "SwiftShims", |
| 109 | + "isFramework": false, |
| 110 | + "clangModuleMapPath": "SWIFTLIBDIR/swift/shims/module.modulemap", |
| 111 | + "clangModulePath": "INPUTSDIR/SwiftShims.pcm" |
| 112 | +}] |
| 113 | + |
| 114 | +//--- bridging_header_dep_module_map.swift |
| 115 | +import FooClient |
0 commit comments