Skip to content

Commit bce8ab6

Browse files
committed
Quiet the macOS installer messages behind the verbose flag
Provide more verbose untarring messages in Linux behind the verbose flag
1 parent c43fba2 commit bce8ab6

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public struct Linux: Platform {
350350
}
351351
}
352352

353-
public func install(from tmpFile: URL, version: ToolchainVersion) throws {
353+
public func install(from tmpFile: URL, version: ToolchainVersion, verbose: Bool) throws {
354354
guard tmpFile.fileExists() else {
355355
throw Error(message: "\(tmpFile) doesn't exist")
356356
}
@@ -371,7 +371,14 @@ public struct Linux: Platform {
371371
let relativePath = name.drop { c in c != "/" }.dropFirst()
372372

373373
// prepend /path/to/swiftlyHomeDir/toolchains/<toolchain> to each file name
374-
return toolchainDir.appendingPathComponent(String(relativePath))
374+
let destination = toolchainDir.appendingPathComponent(String(relativePath))
375+
376+
if verbose {
377+
SwiftlyCore.print("\(destination.path)")
378+
}
379+
380+
// prepend /path/to/swiftlyHomeDir/toolchains/<toolchain> to each file name
381+
return destination
375382
}
376383
}
377384

Sources/MacOSPlatform/MacOS.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public struct MacOS: Platform {
4949
nil
5050
}
5151

52-
public func install(from tmpFile: URL, version: ToolchainVersion) throws {
52+
public func install(from tmpFile: URL, version: ToolchainVersion, verbose: Bool) throws {
5353
guard tmpFile.fileExists() else {
5454
throw Error(message: "\(tmpFile) doesn't exist")
5555
}
@@ -60,23 +60,26 @@ public struct MacOS: Platform {
6060

6161
if SwiftlyCore.mockedHomeDir == nil {
6262
SwiftlyCore.print("Installing package in user home directory...")
63-
try runProgram("installer", "-pkg", tmpFile.path, "-target", "CurrentUserHomeDirectory")
63+
try runProgram("installer", "-verbose", "-pkg", tmpFile.path, "-target", "CurrentUserHomeDirectory", quiet: !verbose)
6464
} else {
6565
// In the case of a mock for testing purposes we won't use the installer, perferring a manual process because
6666
// the installer will not install to an arbitrary path, only a volume or user home directory.
67+
SwiftlyCore.print("Expanding pkg...")
6768
let tmpDir = self.getTempFilePath()
6869
let toolchainDir = self.swiftlyToolchainsDir.appendingPathComponent("\(version.identifier).xctoolchain", isDirectory: true)
6970
if !toolchainDir.fileExists() {
7071
try FileManager.default.createDirectory(at: toolchainDir, withIntermediateDirectories: false)
7172
}
72-
try runProgram("pkgutil", "--expand", tmpFile.path, tmpDir.path)
73+
try runProgram("pkgutil", "--verbose", "--expand", tmpFile.path, tmpDir.path)
7374
// There's a slight difference in the location of the special Payload file between official swift packages
7475
// and the ones that are mocked here in the test framework.
7576
var payload = tmpDir.appendingPathComponent("Payload")
7677
if !payload.fileExists() {
7778
payload = tmpDir.appendingPathComponent("\(version.identifier)-osx-package.pkg/Payload")
7879
}
79-
try runProgram("tar", "-C", toolchainDir.path, "-xf", payload.path)
80+
81+
SwiftlyCore.print("Untarring pkg Payload...")
82+
try runProgram("tar", "-C", toolchainDir.path, "-xvf", payload.path, quiet: !verbose)
8083
}
8184
}
8285

Sources/Swiftly/Install.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ struct Install: SwiftlyCommand {
227227
)
228228
}
229229

230-
try Swiftly.currentPlatform.install(from: tmpFile, version: version)
230+
try Swiftly.currentPlatform.install(from: tmpFile, version: version, verbose: verbose)
231231

232232
config.installedToolchains.insert(version)
233233

Sources/SwiftlyCore/Platform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public protocol Platform {
6565

6666
/// Installs a toolchain from a file on disk pointed to by the given URL.
6767
/// After this completes, a user can “use” the toolchain.
68-
func install(from: URL, version: ToolchainVersion) throws
68+
func install(from: URL, version: ToolchainVersion, verbose: Bool) throws
6969

7070
/// Extract swiftly from the provided downloaded archive and install
7171
/// ourselves from that.

Tests/SwiftlyTests/PlatformTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ final class PlatformTests: SwiftlyTests {
2222
// GIVEN: a toolchain has been downloaded
2323
var (mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.7.1")
2424
// WHEN: the platform installs the toolchain
25-
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version)
25+
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version, verbose: true)
2626
// THEN: the toolchain is extracted in the toolchains directory
2727
var toolchains = try FileManager.default.contentsOfDirectory(at: Swiftly.currentPlatform.swiftlyToolchainsDir, includingPropertiesForKeys: nil)
2828
XCTAssertEqual(1, toolchains.count)
2929

3030
// GIVEN: a second toolchain has been downloaded
3131
(mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.8.0")
3232
// WHEN: the platform installs the toolchain
33-
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version)
33+
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version, verbose: true)
3434
// THEN: the toolchain is added to the toolchains directory
3535
toolchains = try FileManager.default.contentsOfDirectory(at: Swiftly.currentPlatform.swiftlyToolchainsDir, includingPropertiesForKeys: nil)
3636
XCTAssertEqual(2, toolchains.count)
3737

3838
// GIVEN: an identical toolchain has been downloaded
3939
(mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.8.0")
4040
// WHEN: the platform installs the toolchain
41-
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version)
41+
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version, verbose: true)
4242
// THEN: the toolchains directory remains the same
4343
toolchains = try FileManager.default.contentsOfDirectory(at: Swiftly.currentPlatform.swiftlyToolchainsDir, includingPropertiesForKeys: nil)
4444
XCTAssertEqual(2, toolchains.count)
@@ -49,9 +49,9 @@ final class PlatformTests: SwiftlyTests {
4949
try await self.rollbackLocalChanges {
5050
// GIVEN: toolchains have been downloaded, and installed
5151
var (mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.8.0")
52-
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version)
52+
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version, verbose: true)
5353
(mockedToolchainFile, version) = try await self.mockToolchainDownload(version: "5.6.3")
54-
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version)
54+
try Swiftly.currentPlatform.install(from: mockedToolchainFile, version: version, verbose: true)
5555
// WHEN: one of the toolchains is uninstalled
5656
try Swiftly.currentPlatform.uninstall(version)
5757
// THEN: there is only one remaining toolchain installed

0 commit comments

Comments
 (0)