Skip to content

Revert "Avoid using temp_await on loadRootPackage" #7197

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

Closed
wants to merge 1 commit into from
Closed
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
10 changes: 0 additions & 10 deletions .swiftpm/xcode/xcshareddata/xcschemes/SwiftPM-Package.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -839,16 +839,6 @@
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SourceKitLSPAPITests"
BuildableName = "SourceKitLSPAPITests"
BlueprintName = "SourceKitLSPAPITests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
17 changes: 10 additions & 7 deletions Sources/Commands/PackageTools/Describe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import PackageModel
import struct TSCBasic.StringError

extension SwiftPackageTool {
struct Describe: AsyncSwiftCommand {
struct Describe: SwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Describe the current package")

Expand All @@ -29,18 +29,21 @@ extension SwiftPackageTool {
@Option(help: "json | text")
var type: DescribeMode = .text

func run(_ swiftTool: SwiftTool) async throws {
func run(_ swiftTool: SwiftTool) throws {
let workspace = try swiftTool.getActiveWorkspace()

guard let packagePath = try swiftTool.getWorkspaceRoot().packages.first else {
throw StringError("unknown package")
}

let package = try await workspace.loadRootPackage(
at: packagePath,
observabilityScope: swiftTool.observabilityScope
)

let package = try temp_await {
workspace.loadRootPackage(
at: packagePath,
observabilityScope: swiftTool.observabilityScope,
completion: $0
)
}

try self.describe(package, in: type)
}

Expand Down
15 changes: 9 additions & 6 deletions Sources/Commands/PackageTools/DumpCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,24 @@ enum ExtensionBlockSymbolBehavior: String, EnumerableFlag {
case omitExtensionBlockSymbols
}

struct DumpPackage: AsyncSwiftCommand {
struct DumpPackage: SwiftCommand {
static let configuration = CommandConfiguration(
abstract: "Print parsed Package.swift as JSON")

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

func run(_ swiftTool: SwiftTool) async throws {
func run(_ swiftTool: SwiftTool) throws {
let workspace = try swiftTool.getActiveWorkspace()
let root = try swiftTool.getWorkspaceRoot()

let rootManifests = try await workspace.loadRootManifests(
packages: root.packages,
observabilityScope: swiftTool.observabilityScope
)
let rootManifests = try temp_await {
workspace.loadRootManifests(
packages: root.packages,
observabilityScope: swiftTool.observabilityScope,
completion: $0
)
}
guard let rootManifest = rootManifests.values.first else {
throw StringError("invalid manifests at \(root.packages)")
}
Expand Down
18 changes: 10 additions & 8 deletions Sources/Commands/PackageTools/Format.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import enum TSCBasic.ProcessEnv
import enum TSCUtility.Diagnostics

extension SwiftPackageTool {
struct Format: AsyncSwiftCommand {
struct Format: SwiftCommand {
static let configuration = CommandConfiguration(
commandName: "_format", shouldDisplay: false)

Expand All @@ -32,7 +32,7 @@ extension SwiftPackageTool {
help: "Pass flag through to the swift-format tool")
var swiftFormatFlags: [String] = []

func run(_ swiftTool: SwiftTool) async throws {
func run(_ swiftTool: SwiftTool) throws {
// Look for swift-format binary.
// FIXME: This should be moved to user toolchain.
let swiftFormatInEnv = lookupExecutablePath(filename: ProcessEnv.vars["SWIFT_FORMAT"])
Expand All @@ -48,11 +48,13 @@ extension SwiftPackageTool {
throw StringError("unknown package")
}

let package = try await workspace.loadRootPackage(
at: packagePath,
observabilityScope: swiftTool.observabilityScope
)

let package = try temp_await {
workspace.loadRootPackage(
at: packagePath,
observabilityScope: swiftTool.observabilityScope,
completion: $0
)
}

// Use the user provided flags or default to formatting mode.
let formatOptions = swiftFormatFlags.isEmpty
Expand All @@ -69,7 +71,7 @@ extension SwiftPackageTool {
let args = [swiftFormat.pathString] + formatOptions + [packagePath.pathString] + paths
print("Running:", args.map{ $0.spm_shellEscaped() }.joined(separator: " "))

let result = try await TSCBasic.Process.popen(arguments: args)
let result = try TSCBasic.Process.popen(arguments: args)
let output = try (result.utf8Output() + result.utf8stderrOutput())

if result.exitStatus != .terminated(code: 0) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Commands/PackageTools/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import XCBuildSupport
import enum TSCUtility.Diagnostics

/// swift-package tool namespace
public struct SwiftPackageTool: AsyncParsableCommand {
public struct SwiftPackageTool: ParsableCommand {
public static var configuration = CommandConfiguration(
commandName: "package",
_superCommandName: "swift",
Expand Down
9 changes: 3 additions & 6 deletions Sources/SPMTestSupport/MockWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -510,16 +510,13 @@ public final class MockWorkspace {
public let diagnostics: [Basics.Diagnostic]
}

public func checkPrecomputeResolution() async throws -> ResolutionPrecomputationResult {
public func checkPrecomputeResolution(_ check: (ResolutionPrecomputationResult) -> Void) throws {
let observability = ObservabilitySystem.makeForTesting()
let workspace = try self.getOrCreateWorkspace()
let pinsStore = try workspace.pinsStore.load()

let rootInput = PackageGraphRootInput(packages: try rootPaths(for: roots.map { $0.name }), dependencies: [])
let rootManifests = try await workspace.loadRootManifests(
packages: rootInput.packages,
observabilityScope: observability.topScope
)
let rootManifests = try temp_await { workspace.loadRootManifests(packages: rootInput.packages, observabilityScope: observability.topScope, completion: $0) }
let root = PackageGraphRoot(input: rootInput, manifests: rootManifests, observabilityScope: observability.topScope)

let dependencyManifests = try workspace.loadDependencyManifests(root: root, observabilityScope: observability.topScope)
Expand All @@ -532,7 +529,7 @@ public final class MockWorkspace {
observabilityScope: observability.topScope
)

return ResolutionPrecomputationResult(result: result, diagnostics: observability.diagnostics)
check(ResolutionPrecomputationResult(result: result, diagnostics: observability.diagnostics))
}

public func set(
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-package-manager/SwiftPM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct SwiftPM {
static func main() async {
switch execName {
case "swift-package":
await SwiftPackageTool.main()
SwiftPackageTool.main()
case "swift-build":
SwiftBuildTool.main()
case "swift-experimental-sdk":
Expand Down
5 changes: 1 addition & 4 deletions Sources/swift-package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

add_executable(swift-package
Entrypoint.swift)
main.swift)
target_link_libraries(swift-package PRIVATE
Commands
TSCBasic)

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

install(TARGETS swift-package
RUNTIME DESTINATION bin)
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,4 @@

import Commands

@main
struct Entrypoint {
static func main() async {
await SwiftPackageTool.main()
}
}
SwiftPackageTool.main()
Loading