@@ -27,6 +27,7 @@ import struct PackageGraph.ResolvedProduct
27
27
import struct PackageGraph. ResolvedModule
28
28
29
29
import struct PackageModel. Sources
30
+ import enum PackageModel. BuildSettings
30
31
import class PackageModel. SwiftModule
31
32
import class PackageModel. Module
32
33
import struct SPMBuildCore. BuildParameters
@@ -80,18 +81,30 @@ extension BuildPlan {
80
81
let discoveryMainFile = discoveryDerivedDir. appending ( component: TestDiscoveryTool . mainFileName)
81
82
82
83
var discoveryPaths : [ AbsolutePath ] = [ ]
84
+ var discoveryBuildSettings : BuildSettings . AssignmentTable = . init( )
83
85
discoveryPaths. append ( discoveryMainFile)
84
86
for testTarget in testProduct. modules {
85
87
let path = discoveryDerivedDir. appending ( components: testTarget. name + " .swift " )
86
88
discoveryPaths. append ( path)
89
+ // Add in the include path from the test targets to ensure this module builds
90
+ if let flags = testTarget. underlying. buildSettings. assignments [ . OTHER_SWIFT_FLAGS] {
91
+ for assignment in flags {
92
+ let values = assignment. values. filter ( { $0. hasPrefix ( " -I " ) } )
93
+ if !values. isEmpty {
94
+ discoveryBuildSettings. add ( . init( values: values, conditions: [ ] ) , for: . OTHER_SWIFT_FLAGS)
95
+ }
96
+ }
97
+ }
87
98
}
88
99
89
100
let discoveryTarget = SwiftModule (
90
101
name: discoveryTargetName,
91
102
dependencies: testProduct. underlying. modules. map { . module( $0, conditions: [ ] ) } ,
92
103
packageAccess: true , // test target is allowed access to package decls by default
93
- testDiscoverySrc: Sources ( paths: discoveryPaths, root: discoveryDerivedDir)
104
+ testDiscoverySrc: Sources ( paths: discoveryPaths, root: discoveryDerivedDir) ,
105
+ buildSettings: discoveryBuildSettings
94
106
)
107
+
95
108
let discoveryResolvedModule = ResolvedModule (
96
109
packageIdentity: testProduct. packageIdentity,
97
110
underlying: discoveryTarget,
@@ -127,12 +140,26 @@ extension BuildPlan {
127
140
let entryPointMainFile = entryPointDerivedDir. appending ( component: entryPointMainFileName)
128
141
let entryPointSources = Sources ( paths: [ entryPointMainFile] , root: entryPointDerivedDir)
129
142
143
+ var entryPointBuildSettings : BuildSettings . AssignmentTable = . init( )
144
+ for testTarget in testProduct. modules {
145
+ // Add in the include path from the test targets to ensure this module builds
146
+ if let flags = testTarget. underlying. buildSettings. assignments [ . OTHER_SWIFT_FLAGS] {
147
+ for assignment in flags {
148
+ let values = assignment. values. filter ( { $0. hasPrefix ( " -I " ) } )
149
+ if !values. isEmpty {
150
+ entryPointBuildSettings. add ( . init( values: values, conditions: [ ] ) , for: . OTHER_SWIFT_FLAGS)
151
+ }
152
+ }
153
+ }
154
+ }
155
+
130
156
let entryPointTarget = SwiftModule (
131
157
name: testProduct. name,
132
158
type: . library,
133
159
dependencies: testProduct. underlying. modules. map { . module( $0, conditions: [ ] ) } + swiftTargetDependencies,
134
160
packageAccess: true , // test target is allowed access to package decls
135
- testEntryPointSources: entryPointSources
161
+ testEntryPointSources: entryPointSources,
162
+ buildSettings: entryPointBuildSettings
136
163
)
137
164
let entryPointResolvedTarget = ResolvedModule (
138
165
packageIdentity: testProduct. packageIdentity,
@@ -249,7 +276,8 @@ private extension PackageModel.SwiftModule {
249
276
type: PackageModel . Module . Kind ? = nil ,
250
277
dependencies: [ PackageModel . Module . Dependency ] ,
251
278
packageAccess: Bool ,
252
- testEntryPointSources sources: Sources
279
+ testEntryPointSources sources: Sources ,
280
+ buildSettings: BuildSettings . AssignmentTable = . init( )
253
281
) {
254
282
self . init (
255
283
name: name,
@@ -258,6 +286,7 @@ private extension PackageModel.SwiftModule {
258
286
sources: sources,
259
287
dependencies: dependencies,
260
288
packageAccess: packageAccess,
289
+ buildSettings: buildSettings,
261
290
usesUnsafeFlags: false
262
291
)
263
292
}
0 commit comments