Skip to content

Commit fc7beea

Browse files
committed
Remove unnecessary duplicate imports of System and SystemPackage
1 parent 2c4b130 commit fc7beea

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

Sources/MacOSPlatform/MacOS.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Foundation
22
import Subprocess
33
import SwiftlyCore
4-
import System
54
import SystemPackage
65

76
typealias sys = SwiftlyCore.SystemCommand
@@ -19,21 +18,21 @@ public struct SwiftPkgInfo: Codable {
1918
public struct MacOS: Platform {
2019
public init() {}
2120

22-
public var defaultSwiftlyHomeDir: SystemPackage.FilePath {
21+
public var defaultSwiftlyHomeDir: FilePath {
2322
fs.home / ".swiftly"
2423
}
2524

26-
public var defaultToolchainsDirectory: SystemPackage.FilePath {
25+
public var defaultToolchainsDirectory: FilePath {
2726
fs.home / "Library/Developer/Toolchains"
2827
}
2928

30-
public func swiftlyBinDir(_ ctx: SwiftlyCoreContext) -> SystemPackage.FilePath {
29+
public func swiftlyBinDir(_ ctx: SwiftlyCoreContext) -> FilePath {
3130
ctx.mockedHomeDir.map { $0 / "bin" }
3231
?? ProcessInfo.processInfo.environment["SWIFTLY_BIN_DIR"].map { FilePath($0) }
3332
?? fs.home / ".swiftly/bin"
3433
}
3534

36-
public func swiftlyToolchainsDir(_ ctx: SwiftlyCoreContext) -> SystemPackage.FilePath {
35+
public func swiftlyToolchainsDir(_ ctx: SwiftlyCoreContext) -> FilePath {
3736
ctx.mockedHomeDir.map { $0 / "Toolchains" }
3837
?? ProcessInfo.processInfo.environment["SWIFTLY_TOOLCHAINS_DIR"].map { FilePath($0) }
3938
// This is where the installer will put the toolchains, and where Xcode can find them
@@ -57,7 +56,7 @@ public struct MacOS: Platform {
5756
}
5857

5958
public func install(
60-
_ ctx: SwiftlyCoreContext, from tmpFile: SystemPackage.FilePath, version: ToolchainVersion, verbose: Bool
59+
_ ctx: SwiftlyCoreContext, from tmpFile: FilePath, version: ToolchainVersion, verbose: Bool
6160
) async throws {
6261
guard try await fs.exists(atPath: tmpFile) else {
6362
throw SwiftlyError(message: "\(tmpFile) doesn't exist")
@@ -110,7 +109,7 @@ public struct MacOS: Platform {
110109
}
111110
}
112111

113-
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: SystemPackage.FilePath) async throws {
112+
public func extractSwiftlyAndInstall(_ ctx: SwiftlyCoreContext, from archive: FilePath) async throws {
114113
guard try await fs.exists(atPath: archive) else {
115114
throw SwiftlyError(message: "\(archive) doesn't exist")
116115
}
@@ -144,7 +143,13 @@ public struct MacOS: Platform {
144143
try await sys.tar(.directory(installDir)).extract(.verbose, .archive(payload)).run(quiet: false)
145144
}
146145

147-
_ = try await run(.path(System.FilePath((userHomeDir / ".swiftly/bin/swiftly").string)), arguments: ["init"], input: .standardInput, output: .standardOutput, error: .standardError)
146+
let config = Configuration(
147+
.path(FilePath((userHomeDir / ".swiftly/bin/swiftly").string)), arguments: ["init"]
148+
)
149+
let result = try await run(config, input: .standardInput, output: .standardOutput, error: .standardError)
150+
if !result.terminationStatus.isSuccess {
151+
throw RunProgramError(terminationStatus: result.terminationStatus, config: config)
152+
}
148153
}
149154

150155
public func uninstall(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion, verbose: Bool)
@@ -174,14 +179,14 @@ public struct MacOS: Platform {
174179
}
175180

176181
public func verifyToolchainSignature(
177-
_: SwiftlyCoreContext, toolchainFile _: ToolchainFile, archive _: SystemPackage.FilePath, verbose _: Bool
182+
_: SwiftlyCoreContext, toolchainFile _: ToolchainFile, archive _: FilePath, verbose _: Bool
178183
) async throws {
179184
// No signature verification is required on macOS since the pkg files have their own signing
180185
// mechanism and the swift.org downloadables are trusted by stock macOS installations.
181186
}
182187

183188
public func verifySwiftlySignature(
184-
_: SwiftlyCoreContext, archiveDownloadURL _: URL, archive _: SystemPackage.FilePath, verbose _: Bool
189+
_: SwiftlyCoreContext, archiveDownloadURL _: URL, archive _: FilePath, verbose _: Bool
185190
) async throws {
186191
// No signature verification is required on macOS since the pkg files have their own signing
187192
// mechanism and the swift.org downloadables are trusted by stock macOS installations.
@@ -203,11 +208,11 @@ public struct MacOS: Platform {
203208
return "/bin/zsh"
204209
}
205210

206-
public func findToolchainLocation(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion) async throws -> SystemPackage.FilePath
211+
public func findToolchainLocation(_ ctx: SwiftlyCoreContext, _ toolchain: ToolchainVersion) async throws -> FilePath
207212
{
208213
if toolchain == .xcodeVersion {
209214
// Print the toolchain location with the help of xcrun
210-
if let xcrunLocation = try? await run(.path(SystemPackage.FilePath("/usr/bin/xcrun")), arguments: ["-f", "swift"], output: .string(limit: 1024 * 10)).standardOutput {
215+
if let xcrunLocation = try? await run(.path(FilePath("/usr/bin/xcrun")), arguments: ["-f", "swift"], output: .string(limit: 1024 * 10)).standardOutput {
211216
return FilePath(xcrunLocation.replacingOccurrences(of: "\n", with: "")).removingLastComponent().removingLastComponent().removingLastComponent()
212217
}
213218
}

Sources/TestSwiftly/TestSwiftly.swift

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ import Subprocess
44
import SwiftlyCore
55
import SystemPackage
66

7-
#if os(macOS)
8-
import System
9-
#endif
10-
117
#if os(Linux)
128
import LinuxPlatform
139
#elseif os(macOS)
@@ -97,7 +93,7 @@ struct TestSwiftly: AsyncParsableCommand {
9793
Foundation.exit(2)
9894
}
9995

100-
guard case let swiftlyArchive = SystemPackage.FilePath(swiftlyArchive) else { fatalError("") }
96+
guard case let swiftlyArchive = FilePath(swiftlyArchive) else { fatalError("") }
10197

10298
print("Extracting swiftly release")
10399
#if os(Linux)
@@ -107,14 +103,14 @@ struct TestSwiftly: AsyncParsableCommand {
107103
#endif
108104

109105
#if os(Linux)
110-
let extractedSwiftly = SystemPackage.FilePath("./swiftly")
106+
let extractedSwiftly = FilePath("./swiftly")
111107
#elseif os(macOS)
112-
let extractedSwiftly = System.FilePath((fs.home / ".swiftly/bin/swiftly").string)
108+
let extractedSwiftly = FilePath((fs.home / ".swiftly/bin/swiftly").string)
113109
#endif
114110

115111
var env: Environment = .inherit
116-
let shell = SystemPackage.FilePath(try await currentPlatform.getShell())
117-
var customLoc: SystemPackage.FilePath?
112+
let shell = FilePath(try await currentPlatform.getShell())
113+
var customLoc: FilePath?
118114

119115
if self.customLocation {
120116
customLoc = fs.mktemp()
@@ -184,7 +180,7 @@ struct TestSwiftly: AsyncParsableCommand {
184180
try await self.testSelfUninstall(customLoc: customLoc, shell: shell, env: env)
185181
}
186182

187-
private func testSelfUninstall(customLoc: SystemPackage.FilePath?, shell: SystemPackage.FilePath, env: Environment) async throws {
183+
private func testSelfUninstall(customLoc: FilePath?, shell: FilePath, env: Environment) async throws {
188184
if let customLoc = customLoc {
189185
// Test self-uninstall for custom location
190186
try await sh(executable: .path(shell), .login, .command(". \"\(customLoc / "env.sh")\" && swiftly self-uninstall --assume-yes")).run(environment: env)
@@ -200,7 +196,7 @@ struct TestSwiftly: AsyncParsableCommand {
200196
}
201197
}
202198

203-
private func verifyCustomLocationCleanup(customLoc: SystemPackage.FilePath) async throws {
199+
private func verifyCustomLocationCleanup(customLoc: FilePath) async throws {
204200
print("Verifying cleanup for custom location at \(customLoc)")
205201

206202
// Check that swiftly binary is removed
@@ -228,7 +224,7 @@ struct TestSwiftly: AsyncParsableCommand {
228224
print("✓ Custom location cleanup verification passed")
229225
}
230226

231-
private func verifyDefaultLocationCleanup(shell: SystemPackage.FilePath, env: Environment) async throws {
227+
private func verifyDefaultLocationCleanup(shell: FilePath, env: Environment) async throws {
232228
print("Verifying cleanup for default location")
233229

234230
let swiftlyHome = fs.home / ".swiftly"
@@ -273,7 +269,7 @@ struct TestSwiftly: AsyncParsableCommand {
273269
private func verifyProfileCleanup() async throws {
274270
print("Verifying shell profile cleanup")
275271

276-
let profilePaths: [SystemPackage.FilePath] = [
272+
let profilePaths: [FilePath] = [
277273
fs.home / ".zprofile",
278274
fs.home / ".bash_profile",
279275
fs.home / ".bash_login",

0 commit comments

Comments
 (0)