Skip to content
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
2 changes: 1 addition & 1 deletion Examples/package-info/Sources/package-info/example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Example {

let observability = ObservabilitySystem({ print("\($0): \($1)") })

let workspace = try Workspace(forRootPackage: packagePath)
let workspace = try await Workspace.create(forRootPackage: packagePath)

let manifest = try await workspace.loadRootManifest(at: packagePath, observabilityScope: observability.topScope)

Expand Down
17 changes: 11 additions & 6 deletions Sources/Commands/PackageCommands/APIDiff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ struct APIDiff: AsyncSwiftCommand {
let repository = GitRepository(path: packageRoot)
let baselineRevision = try repository.resolveRevision(identifier: treeish)

let baselineDir = try overrideBaselineDir?.appending(component: baselineRevision.identifier) ?? swiftCommandState.productsBuildParameters.apiDiff.appending(component: "\(baselineRevision.identifier)-baselines")
let baselineDir: Basics.AbsolutePath
if let overrideBaselineDir {
baselineDir = overrideBaselineDir.appending(component: baselineRevision.identifier)
} else {
baselineDir = try await swiftCommandState.productsBuildParameters.apiDiff.appending(component: "\(baselineRevision.identifier)-baselines")
}
let packageGraph = try await swiftCommandState.loadPackageGraph()
let modulesToDiff = try Self.determineModulesToDiff(
packageGraph: packageGraph,
Expand Down Expand Up @@ -115,7 +120,7 @@ struct APIDiff: AsyncSwiftCommand {
}

private func runWithSwiftPMCoordinatedDiffing(_ swiftCommandState: SwiftCommandState, buildSystem: any BuildSystem, baselineRevision: Revision, modulesToDiff: Set<String>) async throws {
let apiDigesterPath = try swiftCommandState.getTargetToolchain().getSwiftAPIDigester()
let apiDigesterPath = try await swiftCommandState.getTargetToolchain().getSwiftAPIDigester()
let apiDigesterTool = SwiftAPIDigester(fileSystem: swiftCommandState.fileSystem, tool: apiDigesterPath)

// Build the current package.
Expand Down Expand Up @@ -198,7 +203,7 @@ struct APIDiff: AsyncSwiftCommand {
let modulesWithBaselines = try await generateAPIBaselineUsingIntegratedAPIDigesterSupport(swiftCommandState, baselineRevision: baselineRevision, baselineDir: baselineDir, modulesNeedingBaselines: modulesToDiff)

// Build the package and run a comparison agains the baselines.
var productsBuildParameters = try swiftCommandState.productsBuildParameters
var productsBuildParameters = try await swiftCommandState.productsBuildParameters
productsBuildParameters.apiDigesterMode = .compareToBaselines(
baselinesDirectory: baselineDir,
modulesToCompare: modulesWithBaselines,
Expand Down Expand Up @@ -258,7 +263,7 @@ struct APIDiff: AsyncSwiftCommand {

private func generateAPIBaselineUsingIntegratedAPIDigesterSupport(_ swiftCommandState: SwiftCommandState, baselineRevision: Revision, baselineDir: Basics.AbsolutePath, modulesNeedingBaselines: Set<String>) async throws -> Set<String> {
// Setup a temporary directory where we can checkout and build the baseline treeish.
let baselinePackageRoot = try swiftCommandState.productsBuildParameters.apiDiff.appending("\(baselineRevision.identifier)-checkout")
let baselinePackageRoot = try await swiftCommandState.productsBuildParameters.apiDiff.appending("\(baselineRevision.identifier)-checkout")
if swiftCommandState.fileSystem.exists(baselinePackageRoot) {
try swiftCommandState.fileSystem.removeFileTree(baselinePackageRoot)
}
Expand All @@ -279,7 +284,7 @@ struct APIDiff: AsyncSwiftCommand {
try workingCopy.checkout(revision: baselineRevision)

// Create the workspace for this package.
let workspace = try Workspace(
let workspace = try await Workspace.create(
forRootPackage: baselinePackageRoot,
cancellator: swiftCommandState.cancellator
)
Expand Down Expand Up @@ -307,7 +312,7 @@ struct APIDiff: AsyncSwiftCommand {
}

// Update the data path input build parameters so it's built in the sandbox.
var productsBuildParameters = try swiftCommandState.productsBuildParameters
var productsBuildParameters = try await swiftCommandState.productsBuildParameters
productsBuildParameters.dataPath = workspace.location.scratchDirectory
productsBuildParameters.apiDigesterMode = .generateBaselines(baselinesDirectory: baselineDir, modulesRequestingBaselines: modulesNeedingBaselines)

Expand Down
6 changes: 3 additions & 3 deletions Sources/Commands/PackageCommands/AddDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Workspace
import class PackageModel.Manifest

extension SwiftPackageCommand {
struct AddDependency: SwiftCommand {
struct AddDependency: AsyncSwiftCommand {
package static let configuration = CommandConfiguration(
abstract: "Add a package dependency to the manifest."
)
Expand Down Expand Up @@ -63,8 +63,8 @@ extension SwiftPackageCommand {
case registry
}

func run(_ swiftCommandState: SwiftCommandState) throws {
let workspace = try swiftCommandState.getActiveWorkspace()
func run(_ swiftCommandState: SwiftCommandState) async throws {
let workspace = try await swiftCommandState.getActiveWorkspace()
guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Commands/PackageCommands/AddProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import TSCUtility
import Workspace

extension SwiftPackageCommand {
struct AddProduct: SwiftCommand {
struct AddProduct: AsyncSwiftCommand {
/// The package product type used for the command-line. This is a
/// subset of `ProductType` that expands out the library types.
enum CommandProductType: String, Codable, ExpressibleByArgument, CaseIterable {
Expand Down Expand Up @@ -52,8 +52,8 @@ extension SwiftPackageCommand {
)
var targets: [String] = []

func run(_ swiftCommandState: SwiftCommandState) throws {
let workspace = try swiftCommandState.getActiveWorkspace()
func run(_ swiftCommandState: SwiftCommandState) async throws {
let workspace = try await swiftCommandState.getActiveWorkspace()

guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
Expand Down
10 changes: 5 additions & 5 deletions Sources/Commands/PackageCommands/AddSetting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import TSCUtility
import Workspace

extension SwiftPackageCommand {
struct AddSetting: SwiftCommand {
struct AddSetting: AsyncSwiftCommand {
/// The Swift language setting that can be specified on the command line.
enum SwiftSetting: String, Codable, ExpressibleByArgument, CaseIterable {
case experimentalFeature
Expand Down Expand Up @@ -68,9 +68,9 @@ extension SwiftPackageCommand {
}
}

func run(_ swiftCommandState: SwiftCommandState) throws {
func run(_ swiftCommandState: SwiftCommandState) async throws {
if !self._swiftSettings.isEmpty {
try Self.editSwiftSettings(
try await Self.editSwiftSettings(
of: self.target,
using: swiftCommandState,
self.swiftSettings,
Expand All @@ -84,8 +84,8 @@ extension SwiftPackageCommand {
using swiftCommandState: SwiftCommandState,
_ settings: [(SwiftSetting, String)],
verbose: Bool = false
) throws {
let workspace = try swiftCommandState.getActiveWorkspace()
) async throws {
let workspace = try await swiftCommandState.getActiveWorkspace()
guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageCommands/AddTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ extension SwiftPackageCommand {
var testingLibrary: AddPackageTarget.TestHarness = .default

func run(_ swiftCommandState: SwiftCommandState) async throws {
let workspace = try swiftCommandState.getActiveWorkspace()
let workspace = try await swiftCommandState.getActiveWorkspace()

guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
Expand Down
6 changes: 3 additions & 3 deletions Sources/Commands/PackageCommands/AddTargetDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import TSCUtility
import Workspace

extension SwiftPackageCommand {
struct AddTargetDependency: SwiftCommand {
struct AddTargetDependency: AsyncSwiftCommand {
package static let configuration = CommandConfiguration(
abstract: "Add a new target dependency to the manifest.")

Expand All @@ -40,8 +40,8 @@ extension SwiftPackageCommand {
@Option(help: "The package in which the dependency resides.")
var package: String?

func run(_ swiftCommandState: SwiftCommandState) throws {
let workspace = try swiftCommandState.getActiveWorkspace()
func run(_ swiftCommandState: SwiftCommandState) async throws {
let workspace = try await swiftCommandState.getActiveWorkspace()

guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AuditBinaryArtifact: AsyncSwiftCommand {
var path: AbsolutePath

func run(_ swiftCommandState: SwiftCommandState) async throws {
let hostToolchain = try swiftCommandState.getHostToolchain()
let hostToolchain = try await swiftCommandState.getHostToolchain()
let clang = try hostToolchain.getClangCompiler()
let objdump = try hostToolchain.getLLVMObjdump()
let hostTriple = try Triple.getVersionedHostTriple(
Expand Down
22 changes: 11 additions & 11 deletions Sources/Commands/PackageCommands/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension SwiftPackageCommand {
}

extension SwiftPackageCommand.Config {
struct SetMirror: SwiftCommand {
struct SetMirror: AsyncSwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Set a mirror for a dependency."
)
Expand All @@ -51,8 +51,8 @@ extension SwiftPackageCommand.Config {
@Option(help: "The mirror url or identity.")
var mirror: String?

func run(_ swiftCommandState: SwiftCommandState) throws {
let config = try getMirrorsConfig(swiftCommandState)
func run(_ swiftCommandState: SwiftCommandState) async throws {
let config = try await getMirrorsConfig(swiftCommandState)

if self._deprecate_packageURL != nil {
swiftCommandState.observabilityScope.emit(
Expand Down Expand Up @@ -86,7 +86,7 @@ extension SwiftPackageCommand.Config {
}
}

struct UnsetMirror: SwiftCommand {
struct UnsetMirror: AsyncSwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Remove an existing mirror."
)
Expand All @@ -109,8 +109,8 @@ extension SwiftPackageCommand.Config {
@Option(help: "The mirror url or identity.")
var mirror: String?

func run(_ swiftCommandState: SwiftCommandState) throws {
let config = try getMirrorsConfig(swiftCommandState)
func run(_ swiftCommandState: SwiftCommandState) async throws {
let config = try await getMirrorsConfig(swiftCommandState)

if self._deprecate_packageURL != nil {
swiftCommandState.observabilityScope.emit(
Expand Down Expand Up @@ -141,7 +141,7 @@ extension SwiftPackageCommand.Config {
}
}

struct GetMirror: SwiftCommand {
struct GetMirror: AsyncSwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Print mirror configuration for the given package dependency."
)
Expand All @@ -157,8 +157,8 @@ extension SwiftPackageCommand.Config {
@Option(help: "The original url or identity.")
var original: String?

func run(_ swiftCommandState: SwiftCommandState) throws {
let config = try getMirrorsConfig(swiftCommandState)
func run(_ swiftCommandState: SwiftCommandState) async throws {
let config = try await getMirrorsConfig(swiftCommandState)

if self._deprecate_packageURL != nil {
swiftCommandState.observabilityScope.emit(
Expand Down Expand Up @@ -186,8 +186,8 @@ extension SwiftPackageCommand.Config {
}
}

static func getMirrorsConfig(_ swiftCommandState: SwiftCommandState) throws -> Workspace.Configuration.Mirrors {
let workspace = try swiftCommandState.getActiveWorkspace()
static func getMirrorsConfig(_ swiftCommandState: SwiftCommandState) async throws -> Workspace.Configuration.Mirrors {
let workspace = try await swiftCommandState.getActiveWorkspace()
return try .init(
fileSystem: swiftCommandState.fileSystem,
localMirrorsFile: workspace.location.localMirrorsConfigurationFile,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageCommands/Describe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension SwiftPackageCommand {
var type: DescribeMode = .text

func run(_ swiftCommandState: SwiftCommandState) async throws {
let workspace = try swiftCommandState.getActiveWorkspace()
let workspace = try await swiftCommandState.getActiveWorkspace()

guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
Expand Down
12 changes: 6 additions & 6 deletions Sources/Commands/PackageCommands/DumpCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct DumpSymbolGraph: AsyncSwiftCommand {
)
), .buildPlan])

let symbolGraphDirectory = try swiftCommandState.productsBuildParameters.dataPath.appending("symbolgraph")
let symbolGraphDirectory = try await swiftCommandState.productsBuildParameters.dataPath.appending("symbolgraph")

let fs = swiftCommandState.fileSystem

Expand All @@ -76,12 +76,12 @@ struct DumpSymbolGraph: AsyncSwiftCommand {

if let symbolGraph = buildResult.symbolGraph {
// The build system produced symbol graphs for us, one for each target.
let buildPath = try swiftCommandState.productsBuildParameters.buildPath
let buildPath = try await swiftCommandState.productsBuildParameters.buildPath

// Copy the symbol graphs from the target-specific locations to the single output directory
for rootPackage in try await buildSystem.getPackageGraph().rootPackages {
for module in rootPackage.modules {
let sgDir = symbolGraph.outputLocationForTarget(module.name, try swiftCommandState.productsBuildParameters)
let sgDir = symbolGraph.outputLocationForTarget(module.name, try await swiftCommandState.productsBuildParameters)

if case let sgDir = buildPath.appending(components: sgDir), fs.exists(sgDir) {
for sgFile in try fs.getDirectoryContents(sgDir) {
Expand All @@ -92,9 +92,9 @@ struct DumpSymbolGraph: AsyncSwiftCommand {
}
} else if let buildPlan = buildResult.buildPlan {
// Otherwise, with a build plan we can run the symbol graph extractor tool on the built targets.
let symbolGraphExtractor = try SymbolGraphExtract(
let symbolGraphExtractor = try await SymbolGraphExtract(
fileSystem: swiftCommandState.fileSystem,
tool: swiftCommandState.getTargetToolchain().getSymbolGraphExtract(),
tool: await swiftCommandState.getTargetToolchain().getSymbolGraphExtract(),
observabilityScope: swiftCommandState.observabilityScope,
skipSynthesizedMembers: skipSynthesizedMembers,
minimumAccessLevel: minimumAccessLevel,
Expand Down Expand Up @@ -152,7 +152,7 @@ struct DumpPackage: AsyncSwiftCommand {
var globalOptions: GlobalOptions

func run(_ swiftCommandState: SwiftCommandState) async throws {
let workspace = try swiftCommandState.getActiveWorkspace()
let workspace = try await swiftCommandState.getActiveWorkspace()
let root = try swiftCommandState.getWorkspaceRoot()

let rootManifests = try await workspace.loadRootManifests(
Expand Down
4 changes: 2 additions & 2 deletions Sources/Commands/PackageCommands/EditCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension SwiftPackageCommand {

func run(_ swiftCommandState: SwiftCommandState) async throws {
try await swiftCommandState.resolve()
let workspace = try swiftCommandState.getActiveWorkspace()
let workspace = try await swiftCommandState.getActiveWorkspace()

// Put the dependency in edit mode.
await workspace.edit(
Expand Down Expand Up @@ -67,7 +67,7 @@ extension SwiftPackageCommand {

func run(_ swiftCommandState: SwiftCommandState) async throws {
try await swiftCommandState.resolve()
let workspace = try swiftCommandState.getActiveWorkspace()
let workspace = try await swiftCommandState.getActiveWorkspace()

try await workspace.unedit(
packageIdentity: packageIdentity,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageCommands/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ extension SwiftPackageCommand {
}

// Get the root package.
let workspace = try swiftCommandState.getActiveWorkspace()
let workspace = try await swiftCommandState.getActiveWorkspace()

guard let packagePath = try swiftCommandState.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
Expand Down
20 changes: 13 additions & 7 deletions Sources/Commands/PackageCommands/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Workspace
import SPMBuildCore

extension SwiftPackageCommand {
struct Init: SwiftCommand {
struct Init: AsyncSwiftCommand {
public static let configuration = CommandConfiguration(
abstract: "Initialize a new package.")

Expand Down Expand Up @@ -53,7 +53,7 @@ extension SwiftPackageCommand {
// This command should support creating the supplied --package-path if it isn't created.
var createPackagePath = true

func run(_ swiftCommandState: SwiftCommandState) throws {
func run(_ swiftCommandState: SwiftCommandState) async throws {
guard let cwd = swiftCommandState.fileSystem.currentWorkingDirectory else {
throw InternalError("Could not find the current working directory")
}
Expand All @@ -64,21 +64,27 @@ extension SwiftPackageCommand {
// For macros this is reversed, since we don't support testing
// macros with Swift Testing yet.
var supportedTestingLibraries = Set<TestingLibrary>()
if testLibraryOptions.isExplicitlyEnabled(.xctest, swiftCommandState: swiftCommandState) ||
(initMode == .macro && testLibraryOptions.isEnabled(.xctest, swiftCommandState: swiftCommandState)) {
if await testLibraryOptions.isExplicitlyEnabled(.xctest, swiftCommandState: swiftCommandState) {
supportedTestingLibraries.insert(.xctest)
} else if initMode == .macro {
if await testLibraryOptions.isEnabled(.xctest, swiftCommandState: swiftCommandState) {
supportedTestingLibraries.insert(.xctest)
}
}
if testLibraryOptions.isExplicitlyEnabled(.swiftTesting, swiftCommandState: swiftCommandState) ||
(initMode != .macro && testLibraryOptions.isEnabled(.swiftTesting, swiftCommandState: swiftCommandState)) {
if await testLibraryOptions.isExplicitlyEnabled(.swiftTesting, swiftCommandState: swiftCommandState) {
supportedTestingLibraries.insert(.swiftTesting)
} else if initMode != .macro {
if await testLibraryOptions.isEnabled(.swiftTesting, swiftCommandState: swiftCommandState) {
supportedTestingLibraries.insert(.swiftTesting)
}
}

let initPackage = try InitPackage(
name: packageName,
packageType: initMode,
supportedTestingLibraries: supportedTestingLibraries,
destinationPath: cwd,
installedSwiftPMConfiguration: swiftCommandState.getHostToolchain().installedSwiftPMConfiguration,
installedSwiftPMConfiguration: await swiftCommandState.getHostToolchain().installedSwiftPMConfiguration,
fileSystem: swiftCommandState.fileSystem
)
initPackage.progressReporter = { message in
Expand Down
Loading