Skip to content

[NFC] Vendor AsyncProcess, make more tests async #7679

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 17 commits into from
Jun 22, 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
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ let package = Package(
"SPMBuildCore",
],
exclude: ["CMakeLists.txt"],
swiftSettings: [.enableExperimentalFeature("AccessLevelOnImport")]
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
]
),

// MARK: SwiftPM specific support libraries
Expand All @@ -196,6 +198,7 @@ let package = Package(
exclude: ["CMakeLists.txt", "Vendor/README.md"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.enableExperimentalFeature("AccessLevelOnImport"),
]
),

Expand Down
9 changes: 4 additions & 5 deletions Sources/Basics/Archiver/TarArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import class Dispatch.DispatchQueue
import struct Dispatch.DispatchTime
import struct TSCBasic.FileSystemError
import class TSCBasic.Process

/// An `Archiver` that handles Tar archives using the command-line `tar` tool.
public struct TarArchiver: Archiver {
Expand Down Expand Up @@ -58,7 +57,7 @@ public struct TarArchiver: Archiver {
throw FileSystemError(.notDirectory, destinationPath.underlying)
}

let process = TSCBasic.Process(
let process = AsyncProcess(
arguments: [self.tarCommand, "zxf", archivePath.pathString, "-C", destinationPath.pathString]
)

Expand Down Expand Up @@ -91,10 +90,10 @@ public struct TarArchiver: Archiver {
throw FileSystemError(.notDirectory, directory.underlying)
}

let process = TSCBasic.Process(
let process = AsyncProcess(
arguments: [self.tarCommand, "acf", destinationPath.pathString, directory.basename],
environment: .current,
workingDirectory: directory.parentDirectory.underlying
workingDirectory: directory.parentDirectory
)

guard let registrationKey = self.cancellator.register(process) else {
Expand Down Expand Up @@ -122,7 +121,7 @@ public struct TarArchiver: Archiver {
throw FileSystemError(.noEntry, path.underlying)
}

let process = TSCBasic.Process(arguments: [self.tarCommand, "tf", path.pathString])
let process = AsyncProcess(arguments: [self.tarCommand, "tf", path.pathString])
guard let registrationKey = self.cancellator.register(process) else {
throw CancellationError.failedToRegisterProcess(process)
}
Expand Down
17 changes: 7 additions & 10 deletions Sources/Basics/Archiver/ZipArchiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import Dispatch
import struct TSCBasic.FileSystemError
import class TSCBasic.Process

/// An `Archiver` that handles ZIP archives using the command-line `zip` and `unzip` tools.
public struct ZipArchiver: Archiver, Cancellable {
Expand Down Expand Up @@ -49,11 +48,9 @@ public struct ZipArchiver: Archiver, Cancellable {
}

#if os(Windows)
let process = TSCBasic
.Process(arguments: ["tar.exe", "xf", archivePath.pathString, "-C", destinationPath.pathString])
let process = AsyncProcess(arguments: ["tar.exe", "xf", archivePath.pathString, "-C", destinationPath.pathString])
#else
let process = TSCBasic
.Process(arguments: ["unzip", archivePath.pathString, "-d", destinationPath.pathString])
let process = AsyncProcess(arguments: ["unzip", archivePath.pathString, "-d", destinationPath.pathString])
#endif
guard let registrationKey = self.cancellator.register(process) else {
throw CancellationError.failedToRegisterProcess(process)
Expand Down Expand Up @@ -85,10 +82,10 @@ public struct ZipArchiver: Archiver, Cancellable {
}

#if os(Windows)
let process = TSCBasic.Process(
let process = AsyncProcess(
// FIXME: are these the right arguments?
arguments: ["tar.exe", "-a", "-c", "-f", destinationPath.pathString, directory.basename],
workingDirectory: directory.parentDirectory.underlying
workingDirectory: directory.parentDirectory
)
#else
// This is to work around `swift package-registry publish` tool failing on
Expand All @@ -97,7 +94,7 @@ public struct ZipArchiver: Archiver, Cancellable {
// Instead of passing `workingDirectory` param to TSC.Process, which will trigger
// SPM_posix_spawn_file_actions_addchdir_np_supported check, we shell out and
// do `cd` explicitly before `zip`.
let process = TSCBasic.Process(
let process = AsyncProcess(
arguments: [
"/bin/sh",
"-c",
Expand Down Expand Up @@ -132,9 +129,9 @@ public struct ZipArchiver: Archiver, Cancellable {
}

#if os(Windows)
let process = TSCBasic.Process(arguments: ["tar.exe", "tf", path.pathString])
let process = AsyncProcess(arguments: ["tar.exe", "tf", path.pathString])
#else
let process = TSCBasic.Process(arguments: ["unzip", "-t", path.pathString])
let process = AsyncProcess(arguments: ["unzip", "-t", path.pathString])
#endif
guard let registrationKey = self.cancellator.register(process) else {
throw CancellationError.failedToRegisterProcess(process)
Expand Down
Loading