Skip to content

Work around swift-bootstrap inability to handle plugins #7750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions Sources/PackageGraph/ModulesGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ extension ModulesGraph {
customXCTestMinimumDeploymentTargets: [PackageModel.Platform: PlatformVersion]? = .none,
testEntryPointPath: AbsolutePath? = nil,
fileSystem: FileSystem,
observabilityScope: ObservabilityScope
observabilityScope: ObservabilityScope,
productsFilter: ((Product) -> Bool)? = nil,
modulesFilter: ((Module) -> Bool)? = nil
) throws -> ModulesGraph {
try Self.load(
root: root,
Expand All @@ -52,7 +54,9 @@ extension ModulesGraph {
customXCTestMinimumDeploymentTargets: customXCTestMinimumDeploymentTargets,
testEntryPointPath: testEntryPointPath,
fileSystem: fileSystem,
observabilityScope: observabilityScope
observabilityScope: observabilityScope,
productsFilter: productsFilter,
modulesFilter: modulesFilter
)
}

Expand All @@ -72,7 +76,9 @@ extension ModulesGraph {
customXCTestMinimumDeploymentTargets: [PackageModel.Platform: PlatformVersion]? = .none,
testEntryPointPath: AbsolutePath? = nil,
fileSystem: FileSystem,
observabilityScope: ObservabilityScope
observabilityScope: ObservabilityScope,
productsFilter: ((Product) -> Bool)? = nil,
modulesFilter: ((Module) -> Bool)? = nil
) throws -> ModulesGraph {
let observabilityScope = observabilityScope.makeChildScope(description: "Loading Package Graph")

Expand Down Expand Up @@ -243,7 +249,9 @@ extension ModulesGraph {
platformRegistry: customPlatformsRegistry ?? .default,
platformVersionProvider: platformVersionProvider,
fileSystem: fileSystem,
observabilityScope: observabilityScope
observabilityScope: observabilityScope,
productsFilter: productsFilter,
modulesFilter: modulesFilter
)

let rootPackages = resolvedPackages.filter { root.manifests.values.contains($0.manifest) }
Expand Down Expand Up @@ -372,7 +380,9 @@ private func createResolvedPackages(
platformRegistry: PlatformRegistry,
platformVersionProvider: PlatformVersionProvider,
fileSystem: FileSystem,
observabilityScope: ObservabilityScope
observabilityScope: ObservabilityScope,
productsFilter: ((Product) -> Bool)?,
modulesFilter: ((Module) -> Bool)?
) throws -> IdentifiableSet<ResolvedPackage> {

// Create package builder objects from the input manifests.
Expand Down Expand Up @@ -503,7 +513,13 @@ private func createResolvedPackages(
)

// Create module builders for each module in the package.
let moduleBuilders = package.modules.map {
let modules: [Module]
if let modulesFilter {
modules = package.modules.filter(modulesFilter)
} else {
modules = package.modules
}
let moduleBuilders = modules.map {
ResolvedModuleBuilder(
packageIdentity: package.identity,
module: $0,
Expand Down Expand Up @@ -533,8 +549,15 @@ private func createResolvedPackages(
}

// Create product builders for each product in the package. A product can only contain a module present in the same package.
packageBuilder.products = try package.products.map{
try ResolvedProductBuilder(product: $0, packageBuilder: packageBuilder, moduleBuilders: $0.modules.map {
let products: [Product]
if let productsFilter {
products = package.products.filter(productsFilter)
} else {
products = package.products
}

packageBuilder.products = try products.map { product in
try ResolvedProductBuilder(product: product, packageBuilder: packageBuilder, moduleBuilders: product.modules.map {
guard let module = modulesMap[$0] else {
throw InternalError("unknown target \($0)")
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/PackageGraph/ModulesGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,8 @@ public func loadModulesGraph(
createREPLProduct: createREPLProduct,
customXCTestMinimumDeploymentTargets: customXCTestMinimumDeploymentTargets,
fileSystem: fileSystem,
observabilityScope: observabilityScope
observabilityScope: observabilityScope,
productsFilter: nil,
modulesFilter: nil
)
}
10 changes: 8 additions & 2 deletions Sources/swift-bootstrap/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
shouldDisableLocalRpath: Bool,
logLevel: Basics.Diagnostic.Severity
) throws -> BuildSystem {

var buildFlags = buildFlags
buildFlags.swiftCompilerFlags += Self.additionalSwiftBuildFlags

Expand Down Expand Up @@ -395,7 +394,14 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
},
binaryArtifacts: [:],
fileSystem: fileSystem,
observabilityScope: observabilityScope
observabilityScope: observabilityScope,
// Plugins can't be used in bootstrap builds, exclude those.
productsFilter: {
$0.type != .plugin
},
modulesFilter: {
$0.type != .plugin
}
)
}

Expand Down