Skip to content
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

Unify swift-bootstrap with swift-build and swift-test #8153

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ let package = Package(
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"Basics",
"Build",
"CoreCommands",
"PackageGraph",
"PackageLoading",
"PackageModel",
Expand Down
1 change: 0 additions & 1 deletion Sources/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ add_library(Commands
SwiftBuildCommand.swift
SwiftRunCommand.swift
SwiftTestCommand.swift
CommandWorkspaceDelegate.swift
Utilities/APIDigester.swift
Utilities/DependenciesSerializer.swift
Utilities/DescribedPackage.swift
Expand Down
6 changes: 0 additions & 6 deletions Sources/Commands/SwiftBuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,3 @@ public struct SwiftBuildCommand: AsyncSwiftCommand {

public init() {}
}

public extension _SwiftCommand {
func buildSystemProvider(_ swiftCommandState: SwiftCommandState) throws -> BuildSystemProvider {
swiftCommandState.defaultBuildSystemProvider
}
}
8 changes: 8 additions & 0 deletions Sources/Commands/Utilities/MultiRootSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,11 @@ public struct XcodeWorkspaceLoader: WorkspaceLoader {
}
}
}

public extension _SwiftCommand {
var workspaceLoaderProvider: WorkspaceLoaderProvider {
return {
XcodeWorkspaceLoader(fileSystem: $0, observabilityScope: $1)
}
}
}
1 change: 1 addition & 0 deletions Sources/CoreCommands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

add_library(CoreCommands
BuildSystemSupport.swift
CommandWorkspaceDelegate.swift
SwiftCommandState.swift
SwiftCommandObservabilityHandler.swift
Options.swift)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//===----------------------------------------------------------------------===//

import Basics
import CoreCommands
import Dispatch
import class Foundation.NSLock
import struct Foundation.URL
Expand Down Expand Up @@ -275,10 +274,4 @@ public extension _SwiftCommand {
)
}
}

var workspaceLoaderProvider: WorkspaceLoaderProvider {
return {
XcodeWorkspaceLoader(fileSystem: $0, observabilityScope: $1)
}
}
}
6 changes: 6 additions & 0 deletions Sources/CoreCommands/SwiftCommandState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1185,3 +1185,9 @@ extension Basics.Diagnostic {
.error(arguments.map { "'\($0)'" }.spm_localizedJoin(type: .conjunction) + " are mutually exclusive")
}
}

public extension _SwiftCommand {
func buildSystemProvider(_ swiftCommandState: SwiftCommandState) throws -> BuildSystemProvider {
swiftCommandState.defaultBuildSystemProvider
}
}
7 changes: 6 additions & 1 deletion Sources/swift-bootstrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_executable(swift-bootstrap
main.swift)
SwiftBootstrapCommand.swift)

target_compile_options(swift-bootstrap PRIVATE
-parse-as-library)

target_link_libraries(swift-bootstrap PRIVATE
ArgumentParser
Basics
Build
Commands
PackageGraph
PackageLoading
PackageModel
Expand Down
69 changes: 69 additions & 0 deletions Sources/swift-bootstrap/SwiftBootstrapCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import ArgumentParser
import Basics
import _Concurrency
import Build
import CoreCommands
import Dispatch

@_spi(SwiftPMInternal)
import DriverSupport

import Foundation
import OrderedCollections
import PackageGraph
import PackageLoading
import PackageModel
import SPMBuildCore
import XCBuildSupport

import struct TSCBasic.KeyedPair
import var TSCBasic.stdoutStream
import enum TSCBasic.GraphError
import struct TSCBasic.OrderedSet
import enum TSCUtility.Diagnostics
import struct TSCUtility.Version

@main
struct SwiftBootstrapCommand: AsyncSwiftCommand {
/// If the test should be built.
@Flag(help: "Build both source and test targets")
var buildTests: Bool = false

@OptionGroup(visibility: .hidden)
var globalOptions: GlobalOptions

var workspaceLoaderProvider: CoreCommands.WorkspaceLoaderProvider {
{ _, _ in EmptyWorkspaceLoader() }
}

static let configuration = CommandConfiguration(
commandName: "swift-bootstrap",
abstract: "Bootstrapping build tool, only use in the context of bootstrapping SwiftPM itself",
shouldDisplay: false
)

public init() {}

public func run(_ swiftCommandState: SwiftCommandState) async throws {
let buildSystem = try await swiftCommandState.createBuildSystem(traitConfiguration: .init())
try await buildSystem.build(subset: self.buildTests ? .allIncludingTests : .allExcludingTests)
}
}

private struct EmptyWorkspaceLoader: WorkspaceLoader {
func load(workspace: AbsolutePath) throws -> [AbsolutePath] {
[]
}
}
Loading