Skip to content
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

Support jammy and amazonlinux2 for toolchain install #397

Merged
merged 2 commits into from
May 4, 2023
Merged
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
39 changes: 23 additions & 16 deletions Sources/SwiftToolchain/ToolchainManagement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,7 @@ public class ToolchainSystem {
#if os(macOS)
let platformSuffixes = ["osx", "catalina", "macos"]
#elseif os(Linux)
let releaseFile = AbsolutePath("/etc").appending(component: "lsb-release")
guard fileSystem.isFile(releaseFile) else {
throw ToolchainError.unsupportedOperatingSystem
}

let releaseData = try fileSystem.readFileContents(releaseFile).description
let ubuntuSuffix: String
if releaseData.contains("DISTRIB_RELEASE=18.04") {
ubuntuSuffix = "ubuntu18.04"
} else if releaseData.contains("DISTRIB_RELEASE=20.04") {
ubuntuSuffix = "ubuntu20.04"
} else {
throw ToolchainError.unsupportedOperatingSystem
}

let platformSuffixes = ["linux", ubuntuSuffix]
let platformSuffixes = ["linux", try self.inferLinuxDistributionSuffix()]
#endif

terminal.logLookup(
Expand All @@ -212,6 +197,28 @@ public class ToolchainSystem {
}.first
}

private func inferLinuxDistributionSuffix() throws -> String {
guard let releaseFile = [
AbsolutePath.root.appending(components: "etc", "lsb-release"),
AbsolutePath.root.appending(components: "etc", "os-release"),
].first(where: fileSystem.isFile) else {
throw ToolchainError.unsupportedOperatingSystem
}

let releaseData = try fileSystem.readFileContents(releaseFile).description
if releaseData.contains("DISTRIB_RELEASE=18.04") {
return "ubuntu18.04"
} else if releaseData.contains("DISTRIB_RELEASE=20.04") {
return "ubuntu20.04"
} else if releaseData.contains("DISTRIB_RELEASE=22.04") {
return "ubuntu22.04"
} else if releaseData.contains(#"PRETTY_NAME="Amazon Linux 2""#) {
return "amazonlinux2"
} else {
throw ToolchainError.unsupportedOperatingSystem
}
}

/** Infer `swift` binary path matching a given version if any is present, or infer the
version from the `.swift-version` file. If neither version is installed, download it.
*/
Expand Down