@@ -27,6 +27,7 @@ import struct PackageGraph.ResolvedProduct
2727import struct PackageGraph. ResolvedModule
2828
2929import struct PackageModel. Sources
30+ import enum PackageModel. BuildSettings
3031import class PackageModel. SwiftModule
3132import class PackageModel. Module
3233import struct SPMBuildCore. BuildParameters
@@ -80,18 +81,30 @@ extension BuildPlan {
8081 let discoveryMainFile = discoveryDerivedDir. appending ( component: TestDiscoveryTool . mainFileName)
8182
8283 var discoveryPaths : [ AbsolutePath ] = [ ]
84+ var discoveryBuildSettings : BuildSettings . AssignmentTable = . init( )
8385 discoveryPaths. append ( discoveryMainFile)
8486 for testTarget in testProduct. modules {
8587 let path = discoveryDerivedDir. appending ( components: testTarget. name + " .swift " )
8688 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+ }
8798 }
8899
89100 let discoveryTarget = SwiftModule (
90101 name: discoveryTargetName,
91102 dependencies: testProduct. underlying. modules. map { . module( $0, conditions: [ ] ) } ,
92103 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
94106 )
107+
95108 let discoveryResolvedModule = ResolvedModule (
96109 packageIdentity: testProduct. packageIdentity,
97110 underlying: discoveryTarget,
@@ -127,12 +140,26 @@ extension BuildPlan {
127140 let entryPointMainFile = entryPointDerivedDir. appending ( component: entryPointMainFileName)
128141 let entryPointSources = Sources ( paths: [ entryPointMainFile] , root: entryPointDerivedDir)
129142
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+
130156 let entryPointTarget = SwiftModule (
131157 name: testProduct. name,
132158 type: . library,
133159 dependencies: testProduct. underlying. modules. map { . module( $0, conditions: [ ] ) } + swiftTargetDependencies,
134160 packageAccess: true , // test target is allowed access to package decls
135- testEntryPointSources: entryPointSources
161+ testEntryPointSources: entryPointSources,
162+ buildSettings: entryPointBuildSettings
136163 )
137164 let entryPointResolvedTarget = ResolvedModule (
138165 packageIdentity: testProduct. packageIdentity,
@@ -249,7 +276,8 @@ private extension PackageModel.SwiftModule {
249276 type: PackageModel . Module . Kind ? = nil ,
250277 dependencies: [ PackageModel . Module . Dependency ] ,
251278 packageAccess: Bool ,
252- testEntryPointSources sources: Sources
279+ testEntryPointSources sources: Sources ,
280+ buildSettings: BuildSettings . AssignmentTable = . init( )
253281 ) {
254282 self . init (
255283 name: name,
@@ -258,6 +286,7 @@ private extension PackageModel.SwiftModule {
258286 sources: sources,
259287 dependencies: dependencies,
260288 packageAccess: packageAccess,
289+ buildSettings: buildSettings,
261290 usesUnsafeFlags: false
262291 )
263292 }
0 commit comments