Skip to content

Commit 7186f09

Browse files
committed
Remove unnecessary system imports for MacOS and redundant qualifications of FilePath
1 parent fc7beea commit 7186f09

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

Sources/Swiftly/Proxy.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,22 @@ public enum Proxy {
7171

7272
let env = try await Swiftly.currentPlatform.proxyEnvironment(ctx, env: .inherit, toolchain: toolchain)
7373

74-
_ = try await Subprocess.run(
74+
let cmdConfig = Configuration(
7575
.name(binName),
7676
arguments: Arguments(Array(CommandLine.arguments[1...])),
77-
environment: env.updating(["SWIFTLY_PROXY_IN_PROGRESS": "1"]),
77+
environment: env.updating(["SWIFTLY_PROXY_IN_PROGRESS": "1"])
78+
)
79+
80+
let cmdResult = try await Subprocess.run(
81+
cmdConfig,
7882
input: .standardInput,
7983
output: .standardOutput,
8084
error: .standardError
8185
)
86+
87+
if !cmdResult.terminationStatus.isSuccess {
88+
throw RunProgramError(terminationStatus: cmdResult.terminationStatus, config: cmdConfig)
89+
}
8290
} catch let terminated as RunProgramError {
8391
switch terminated.terminationStatus {
8492
case let .exited(code):

Sources/TestSwiftly/TestSwiftly.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ struct TestSwiftly: AsyncParsableCommand {
9393
Foundation.exit(2)
9494
}
9595

96-
guard case let swiftlyArchive = FilePath(swiftlyArchive) else { fatalError("") }
96+
let swiftlyArchiveFile = FilePath(swiftlyArchive)
9797

9898
print("Extracting swiftly release")
9999
#if os(Linux)
100-
try await sys.tar().extract(.verbose, .compressed, .archive(swiftlyArchive)).run()
100+
try await sys.tar().extract(.verbose, .compressed, .archive(swiftlyArchiveFile)).run()
101101
#elseif os(macOS)
102-
try await sys.installer(.verbose, .pkg(swiftlyArchive), .target("CurrentUserHomeDirectory")).run()
102+
try await sys.installer(.verbose, .pkg(swiftlyArchiveFile), .target("CurrentUserHomeDirectory")).run()
103103
#endif
104104

105105
#if os(Linux)
@@ -160,7 +160,11 @@ struct TestSwiftly: AsyncParsableCommand {
160160

161161
if NSUserName() == "root" {
162162
if try await fs.exists(atPath: "./post-install.sh") {
163-
_ = try await Subprocess.run(.path(shell), arguments: ["./post-install.sh"], input: .standardInput, output: .standardOutput, error: .standardError)
163+
let config = Configuration(.path(shell), arguments: ["./post-install.sh"])
164+
let result = try await Subprocess.run(config, input: .standardInput, output: .standardOutput, error: .standardError)
165+
if !result.terminationStatus.isSuccess {
166+
throw RunProgramError(terminationStatus: result.terminationStatus, config: config)
167+
}
164168
}
165169
swiftReady = true
166170
} else if try await fs.exists(atPath: "./post-install.sh") {

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import Testing
1010

1111
#if os(macOS)
1212
import MacOSPlatform
13-
import System
1413
#endif
1514

1615
import AsyncHTTPClient
@@ -73,7 +72,7 @@ extension Config {
7372

7473
extension SwiftlyCoreContext {
7574
public init(
76-
mockedHomeDir: SystemPackage.FilePath?,
75+
mockedHomeDir: FilePath?,
7776
httpRequestExecutor: HTTPRequestExecutor,
7877
outputHandler: (any OutputHandler)?,
7978
inputProvider: (any InputProvider)?,
@@ -284,7 +283,7 @@ public enum SwiftlyTests {
284283
return await handler.lines
285284
}
286285

287-
static func getTestHomePath(name: String) -> SystemPackage.FilePath {
286+
static func getTestHomePath(name: String) -> FilePath {
288287
fs.tmp / "swiftly-tests-\(name)-\(UUID())"
289288
}
290289

@@ -461,7 +460,7 @@ public enum SwiftlyTests {
461460
}
462461

463462
/// Get the toolchain version of a mocked executable installed via `installMockedToolchain` at the given FilePath.
464-
static func getMockedToolchainVersion(at path: SystemPackage.FilePath) throws -> ToolchainVersion {
463+
static func getMockedToolchainVersion(at path: FilePath) throws -> ToolchainVersion {
465464
let process = Process()
466465
process.executableURL = URL(fileURLWithPath: path.string)
467466

@@ -512,7 +511,7 @@ public actor TestInputProvider: SwiftlyCore.InputProvider {
512511

513512
/// Wrapper around a `swift` executable used to execute swift commands.
514513
public struct SwiftExecutable {
515-
public let path: SystemPackage.FilePath
514+
public let path: FilePath
516515

517516
private static func stableRegex() -> Regex<(Substring, Substring)> {
518517
try! Regex("swift-([^-]+)-RELEASE")

0 commit comments

Comments
 (0)