Skip to content

Replace hardcoded config fallback version with dynamic constant #381

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 5 additions & 8 deletions Sources/Swiftly/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ public struct Config: Codable, Equatable, Sendable {
public var inUse: ToolchainVersion?
public var installedToolchains: Set<ToolchainVersion>
public var platform: PlatformDefinition
public var version: SwiftlyVersion?
public var version: SwiftlyVersion

init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition) {
init(inUse: ToolchainVersion?, installedToolchains: Set<ToolchainVersion>, platform: PlatformDefinition, version: SwiftlyVersion) {
self.inUse = inUse
self.installedToolchains = installedToolchains
self.platform = platform
self.version = version
}

private static func makeEncoder() -> JSONEncoder {
Expand All @@ -28,12 +29,8 @@ public struct Config: Codable, Equatable, Sendable {
do {
let configFile = Swiftly.currentPlatform.swiftlyConfigFile(ctx)
let data = try await fs.cat(atPath: configFile)
var config = try JSONDecoder().decode(Config.self, from: data)
if config.version == nil {
// Assume that the version of swiftly is 0.3.0 because that is the last
// unversioned release.
config.version = try? SwiftlyVersion(parsing: "0.3.0")
}
let config = try JSONDecoder().decode(Config.self, from: data)

return config
} catch {
let msg = """
Expand Down
7 changes: 3 additions & 4 deletions Sources/Swiftly/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Init: SwiftlyCommand {
(
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0, suffix: "dev") ||
config.version == SwiftlyVersion(major: 0, minor: 4, patch: 0) ||
(config.version?.major == 1 && config.version?.minor == 0)
(config.version.major == 1 && config.version.minor == 0)
)
{
// This is a simple upgrade from the 0.4.0 pre-releases, or 1.x
Expand Down Expand Up @@ -178,9 +178,8 @@ struct Init: SwiftlyCommand {
// Force the configuration to be present. Generate it if it doesn't already exist or overwrite is set
if overwrite || config == nil {
let pd = try await Swiftly.currentPlatform.detectPlatform(ctx, disableConfirmation: assumeYes, platform: platform)
var c = Config(inUse: nil, installedToolchains: [], platform: pd)
// Stamp the current version of swiftly on this config
c.version = SwiftlyCore.version
let c = Config(inUse: nil, installedToolchains: [], platform: pd, version: SwiftlyCore.version)

try c.save(ctx)
config = c
}
Expand Down