Skip to content

Commit 86cd751

Browse files
committed
Merge branch 'main' of https://github.com/swiftlang/swiftly into xcode_selector
2 parents 5fba3ae + 7772f32 commit 86cd751

File tree

5 files changed

+23
-24
lines changed

5 files changed

+23
-24
lines changed

Sources/Swiftly/Config.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ public struct Config: Codable, Equatable, Sendable {
99
public var inUse: ToolchainVersion?
1010
public var installedToolchains: Set<ToolchainVersion>
1111
public var platform: PlatformDefinition
12-
public var version: SwiftlyVersion?
12+
public var version: SwiftlyVersion
1313

14-
init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition) {
14+
init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition, version: SwiftlyVersion) {
1515
self.inUse = inUse
1616
self.installedToolchains = installedToolchains
1717
self.platform = platform
18+
self.version = version
1819
}
1920

2021
private static func makeEncoder() -> JSONEncoder {
@@ -28,12 +29,8 @@ public struct Config: Codable, Equatable, Sendable {
2829
do {
2930
let configFile = Swiftly.currentPlatform.swiftlyConfigFile(ctx)
3031
let data = try await fs.cat(atPath: configFile)
31-
var config = try JSONDecoder().decode(Config.self, from: data)
32-
if config.version == nil {
33-
// Assume that the version of swiftly is 0.3.0 because that is the last
34-
// unversioned release.
35-
config.version = try? SwiftlyVersion(parsing: "0.3.0")
36-
}
32+
let config = try JSONDecoder().decode(Config.self, from: data)
33+
3734
return config
3835
} catch {
3936
let msg = """

Sources/Swiftly/Init.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ struct Init: SwiftlyCommand {
4848
(
4949
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0, suffix: "dev") ||
5050
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0) ||
51-
(config.version?.major == 1 && config.version?.minor == 0)
51+
(config.version.major == 1 && config.version.minor == 0)
5252
)
5353
{
5454
// This is a simple upgrade from the 0.4.0 pre-releases, or 1.x
@@ -178,9 +178,8 @@ struct Init: SwiftlyCommand {
178178
// Force the configuration to be present. Generate it if it doesn't already exist or overwrite is set
179179
if overwrite || config == nil {
180180
let pd = try await Swiftly.currentPlatform.detectPlatform(ctx, disableConfirmation: assumeYes, platform: platform)
181-
var c = Config(inUse: nil, installedToolchains: [], platform: pd)
182-
// Stamp the current version of swiftly on this config
183-
c.version = SwiftlyCore.version
181+
let c = Config(inUse: nil, installedToolchains: [], platform: pd, version: SwiftlyCore.version)
182+
184183
try c.save(ctx)
185184
config = c
186185
}

Tests/SwiftlyTests/CommandLineTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public struct CommandLineTests {
9595
// AND a simple history
9696
try "Some text".write(to: tmp / "foo.txt", atomically: true)
9797
try await Swiftly.currentPlatform.runProgram("git", "-C", "\(tmp)", "add", "foo.txt")
98-
try await Swiftly.currentPlatform.runProgram("git", "-C", "\(tmp)", "config", "user.email", "[email protected]")
98+
try await Swiftly.currentPlatform.runProgram("git", "-C", "\(tmp)", "config", "--local", "user.email", "[email protected]")
99+
try await Swiftly.currentPlatform.runProgram("git", "-C", "\(tmp)", "config", "--local", "commit.gpgsign", "false")
99100
try await sys.git(.workingDir(tmp)).commit(.message("Initial commit")).run(Swiftly.currentPlatform)
100101
try await sys.git(.workingDir(tmp)).diffindex(.quiet, tree_ish: "HEAD").run(Swiftly.currentPlatform)
101102

Tests/SwiftlyTests/InstallTests.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,17 @@ import Testing
327327
try? FileManager.default.removeItem(atPath: pipePath)
328328
}
329329

330-
var receivedMessages: [ProgressInfo] = []
331330
let decoder = JSONDecoder()
332-
var installCompleted = false
333331

334332
let readerTask = Task {
335-
guard let fileHandle = FileHandle(forReadingAtPath: pipePath) else { return }
333+
var receivedMessages: [ProgressInfo] = []
334+
335+
guard let fileHandle = FileHandle(forReadingAtPath: pipePath) else { throw SwiftlyError(message: "Unable to open file handle at \(pipePath)") }
336336
defer { fileHandle.closeFile() }
337337

338338
var buffer = Data()
339339

340-
while !installCompleted {
340+
while true {
341341
let data = fileHandle.availableData
342342
if data.isEmpty {
343343
try await Task.sleep(nanoseconds: 100_000_000)
@@ -354,13 +354,14 @@ import Testing
354354
if let progress = try? decoder.decode(ProgressInfo.self, from: lineData) {
355355
receivedMessages.append(progress)
356356
if case .complete = progress {
357-
installCompleted = true
358-
return
357+
return receivedMessages
359358
}
360359
}
361360
}
362361
}
363362
}
363+
364+
return receivedMessages
364365
}
365366

366367
let installTask = Task {
@@ -371,10 +372,10 @@ import Testing
371372
])
372373
}
373374

374-
await withTaskGroup(of: Void.self) { group in
375-
group.addTask { try? await readerTask.value }
376-
group.addTask { try? await installTask.value }
377-
}
375+
let readerResult = await readerTask.result
376+
try await installTask.value
377+
378+
let receivedMessages = try readerResult.get()
378379

379380
#expect(!receivedMessages.isEmpty, "Named pipe should receive progress entries")
380381

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ public enum SwiftlyTests {
220220
return Config(
221221
inUse: nil,
222222
installedToolchains: [],
223-
platform: pd
223+
platform: pd,
224+
version: SwiftlyCore.version
224225
)
225226
}
226227

0 commit comments

Comments
 (0)