@@ -100,7 +100,8 @@ public final class PIFBuilder {
100
100
func generatePIF(
101
101
prettyPrint: Bool = true ,
102
102
preservePIFModelStructure: Bool = false ,
103
- printPIFManifestGraphviz: Bool = false
103
+ printPIFManifestGraphviz: Bool = false ,
104
+ buildParameters: BuildParameters
104
105
) throws -> String {
105
106
#if canImport(SwiftBuild)
106
107
let encoder = prettyPrint ? JSONEncoder . makeWithDefaults ( ) : JSONEncoder ( )
@@ -109,7 +110,7 @@ public final class PIFBuilder {
109
110
encoder. userInfo [ . encodeForSwiftBuild] = true
110
111
}
111
112
112
- let topLevelObject = try self . construct ( )
113
+ let topLevelObject = try self . construct ( buildParameters : buildParameters )
113
114
114
115
// Sign the PIF objects before encoding it for Swift Build.
115
116
try PIF . sign ( workspace: topLevelObject. workspace)
@@ -138,7 +139,7 @@ public final class PIFBuilder {
138
139
private var cachedPIF : PIF . TopLevelObject ?
139
140
140
141
/// Constructs a `PIF.TopLevelObject` representing the package graph.
141
- private func construct( ) throws -> PIF . TopLevelObject {
142
+ private func construct( buildParameters : BuildParameters ) throws -> PIF . TopLevelObject {
142
143
try memoize ( to: & self . cachedPIF) {
143
144
guard let rootPackage = self . graph. rootPackages. only else {
144
145
if self . graph. rootPackages. isEmpty {
@@ -174,7 +175,9 @@ public final class PIFBuilder {
174
175
projects. append (
175
176
try buildAggregateProject (
176
177
packagesAndProjects: packagesAndProjects,
177
- observabilityScope: observabilityScope
178
+ observabilityScope: observabilityScope,
179
+ modulesGraph: graph,
180
+ buildParameters: buildParameters
178
181
)
179
182
)
180
183
@@ -197,7 +200,7 @@ public final class PIFBuilder {
197
200
packageGraph: ModulesGraph ,
198
201
fileSystem: FileSystem ,
199
202
observabilityScope: ObservabilityScope ,
200
- preservePIFModelStructure: Bool
203
+ preservePIFModelStructure: Bool ,
201
204
) throws -> String {
202
205
let parameters = PIFBuilderParameters ( buildParameters, supportedSwiftVersions: [ ] )
203
206
let builder = Self (
@@ -206,7 +209,7 @@ public final class PIFBuilder {
206
209
fileSystem: fileSystem,
207
210
observabilityScope: observabilityScope
208
211
)
209
- return try builder. generatePIF ( preservePIFModelStructure: preservePIFModelStructure)
212
+ return try builder. generatePIF ( preservePIFModelStructure: preservePIFModelStructure, buildParameters : buildParameters )
210
213
}
211
214
}
212
215
@@ -306,7 +309,9 @@ fileprivate final class PackagePIFBuilderDelegate: PackagePIFBuilder.BuildDelega
306
309
307
310
fileprivate func buildAggregateProject(
308
311
packagesAndProjects: [ ( package : ResolvedPackage , project: ProjectModel . Project ) ] ,
309
- observabilityScope: ObservabilityScope
312
+ observabilityScope: ObservabilityScope ,
313
+ modulesGraph: ModulesGraph ,
314
+ buildParameters: BuildParameters
310
315
) throws -> ProjectModel . Project {
311
316
precondition ( !packagesAndProjects. isEmpty)
312
317
@@ -367,6 +372,13 @@ fileprivate func buildAggregateProject(
367
372
// conflicts with those from "PACKAGE-TARGET:Foo-dynamic".
368
373
continue
369
374
}
375
+
376
+ if let resolvedModule = modulesGraph. module ( for: target. name) {
377
+ guard modulesGraph. isInRootPackages ( resolvedModule, satisfying: buildParameters. buildEnvironment) else {
378
+ // Disconnected target, possibly due to platform when condition that isn't satisfied
379
+ continue
380
+ }
381
+ }
370
382
371
383
aggregateProject [ keyPath: allIncludingTestsTargetKeyPath] . common. addDependency (
372
384
on: target. id,
0 commit comments