Support jammy and amazonlinux2 for toolchain install (#397)

* Support Ubuntu 22.04 for toolchain download

* Support amazonlinux2 for toolchain install
This commit is contained in:
Yuta Saito 2023-05-05 00:30:34 +09:00 committed by GitHub
parent fc64e872de
commit 44b7dbd2ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 16 deletions

View File

@ -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(
@ -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.
*/