Skip to content

Commit ca2a194

Browse files
authored
Work around swift-bootstrap inability to handle plugins (#7750)
`swift-bootstrap` currently can't handle dependencies with plugins, which prevents us from bumping Swift Argument Parser to a newer version, which did add a dependency on a plugin. The easiest workaround is to exclude plugins from the modules graph only when building with `swift-bootstrap`.
1 parent 123fa36 commit ca2a194

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

Sources/PackageGraph/ModulesGraph+Loading.swift

+31-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ extension ModulesGraph {
3535
customXCTestMinimumDeploymentTargets: [PackageModel.Platform: PlatformVersion]? = .none,
3636
testEntryPointPath: AbsolutePath? = nil,
3737
fileSystem: FileSystem,
38-
observabilityScope: ObservabilityScope
38+
observabilityScope: ObservabilityScope,
39+
productsFilter: ((Product) -> Bool)? = nil,
40+
modulesFilter: ((Module) -> Bool)? = nil
3941
) throws -> ModulesGraph {
4042
try Self.load(
4143
root: root,
@@ -52,7 +54,9 @@ extension ModulesGraph {
5254
customXCTestMinimumDeploymentTargets: customXCTestMinimumDeploymentTargets,
5355
testEntryPointPath: testEntryPointPath,
5456
fileSystem: fileSystem,
55-
observabilityScope: observabilityScope
57+
observabilityScope: observabilityScope,
58+
productsFilter: productsFilter,
59+
modulesFilter: modulesFilter
5660
)
5761
}
5862

@@ -72,7 +76,9 @@ extension ModulesGraph {
7276
customXCTestMinimumDeploymentTargets: [PackageModel.Platform: PlatformVersion]? = .none,
7377
testEntryPointPath: AbsolutePath? = nil,
7478
fileSystem: FileSystem,
75-
observabilityScope: ObservabilityScope
79+
observabilityScope: ObservabilityScope,
80+
productsFilter: ((Product) -> Bool)? = nil,
81+
modulesFilter: ((Module) -> Bool)? = nil
7682
) throws -> ModulesGraph {
7783
let observabilityScope = observabilityScope.makeChildScope(description: "Loading Package Graph")
7884

@@ -243,7 +249,9 @@ extension ModulesGraph {
243249
platformRegistry: customPlatformsRegistry ?? .default,
244250
platformVersionProvider: platformVersionProvider,
245251
fileSystem: fileSystem,
246-
observabilityScope: observabilityScope
252+
observabilityScope: observabilityScope,
253+
productsFilter: productsFilter,
254+
modulesFilter: modulesFilter
247255
)
248256

249257
let rootPackages = resolvedPackages.filter { root.manifests.values.contains($0.manifest) }
@@ -372,7 +380,9 @@ private func createResolvedPackages(
372380
platformRegistry: PlatformRegistry,
373381
platformVersionProvider: PlatformVersionProvider,
374382
fileSystem: FileSystem,
375-
observabilityScope: ObservabilityScope
383+
observabilityScope: ObservabilityScope,
384+
productsFilter: ((Product) -> Bool)?,
385+
modulesFilter: ((Module) -> Bool)?
376386
) throws -> IdentifiableSet<ResolvedPackage> {
377387

378388
// Create package builder objects from the input manifests.
@@ -503,7 +513,13 @@ private func createResolvedPackages(
503513
)
504514

505515
// Create module builders for each module in the package.
506-
let moduleBuilders = package.modules.map {
516+
let modules: [Module]
517+
if let modulesFilter {
518+
modules = package.modules.filter(modulesFilter)
519+
} else {
520+
modules = package.modules
521+
}
522+
let moduleBuilders = modules.map {
507523
ResolvedModuleBuilder(
508524
packageIdentity: package.identity,
509525
module: $0,
@@ -533,8 +549,15 @@ private func createResolvedPackages(
533549
}
534550

535551
// Create product builders for each product in the package. A product can only contain a module present in the same package.
536-
packageBuilder.products = try package.products.map{
537-
try ResolvedProductBuilder(product: $0, packageBuilder: packageBuilder, moduleBuilders: $0.modules.map {
552+
let products: [Product]
553+
if let productsFilter {
554+
products = package.products.filter(productsFilter)
555+
} else {
556+
products = package.products
557+
}
558+
559+
packageBuilder.products = try products.map { product in
560+
try ResolvedProductBuilder(product: product, packageBuilder: packageBuilder, moduleBuilders: product.modules.map {
538561
guard let module = modulesMap[$0] else {
539562
throw InternalError("unknown target \($0)")
540563
}

Sources/PackageGraph/ModulesGraph.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ public func loadModulesGraph(
554554
createREPLProduct: createREPLProduct,
555555
customXCTestMinimumDeploymentTargets: customXCTestMinimumDeploymentTargets,
556556
fileSystem: fileSystem,
557-
observabilityScope: observabilityScope
557+
observabilityScope: observabilityScope,
558+
productsFilter: nil,
559+
modulesFilter: nil
558560
)
559561
}

Sources/swift-bootstrap/main.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
276276
shouldDisableLocalRpath: Bool,
277277
logLevel: Basics.Diagnostic.Severity
278278
) throws -> BuildSystem {
279-
280279
var buildFlags = buildFlags
281280
buildFlags.swiftCompilerFlags += Self.additionalSwiftBuildFlags
282281

@@ -395,7 +394,14 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
395394
},
396395
binaryArtifacts: [:],
397396
fileSystem: fileSystem,
398-
observabilityScope: observabilityScope
397+
observabilityScope: observabilityScope,
398+
// Plugins can't be used in bootstrap builds, exclude those.
399+
productsFilter: {
400+
$0.type != .plugin
401+
},
402+
modulesFilter: {
403+
$0.type != .plugin
404+
}
399405
)
400406
}
401407

0 commit comments

Comments
 (0)