From bc7cc413c9e6bc6b471a5363ea771b2794daf7ba Mon Sep 17 00:00:00 2001 From: Cole Leavitt Date: Sun, 19 Oct 2025 14:58:00 -0700 Subject: [PATCH] feat: add support for Gentoo Linux in HTTP client and package management --- Sources/LinuxPlatform/Linux.swift | 28 ++++++++++++++++++++++++++++ Sources/SwiftlyCore/HTTPClient.swift | 2 +- Sources/SwiftlyCore/Platform.swift | 3 +++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/Sources/LinuxPlatform/Linux.swift b/Sources/LinuxPlatform/Linux.swift index 386e69db..2ae87487 100644 --- a/Sources/LinuxPlatform/Linux.swift +++ b/Sources/LinuxPlatform/Linux.swift @@ -18,6 +18,7 @@ public struct Linux: Platform { .rhel9, .amazonlinux2, .debian12, + .gentoo, ] public init() {} @@ -227,6 +228,25 @@ public struct Linux: Platform { "gcc", "libstdc++-12-dev", ] + case "gentoo": + [ + "dev-vcs/git", + "app-arch/unzip", + "app-crypt/gnupg", + "net-misc/curl", + "dev-libs/libxml2", + "sys-libs/readline", + "dev-db/sqlite", + "sys-devel/binutils", + "sys-devel/gcc", + "sys-libs/glibc", + "dev-lang/python", + "sys-apps/util-linux", + "sys-libs/zlib", + "sys-libs/ncurses", + "dev-libs/icu", + "dev-util/pkgconf", + ] default: [] } @@ -250,6 +270,8 @@ public struct Linux: Platform { "yum" case "debian12": "apt-get" + case "gentoo": + "emerge" default: nil } @@ -323,6 +345,10 @@ public struct Linux: Platform { case "yum": try self.runProgram("yum", "list", "installed", package, quiet: true) return true + case "emerge": + // Use portage's qlist to check if package is installed + try self.runProgram("qlist", "-I", package, quiet: true) + return true default: return true } @@ -586,6 +612,8 @@ public struct Linux: Platform { } return .rhel9 + } else if id == "gentoo" || (idlike ?? "").contains("gentoo") { + return .gentoo } else if let pd = [ PlatformDefinition.ubuntu1804, .ubuntu2004, .ubuntu2204, .ubuntu2404, .debian12, .fedora39, ].first(where: { $0.name == id + versionID }) { diff --git a/Sources/SwiftlyCore/HTTPClient.swift b/Sources/SwiftlyCore/HTTPClient.swift index 556d1b24..7fb6c0d5 100644 --- a/Sources/SwiftlyCore/HTTPClient.swift +++ b/Sources/SwiftlyCore/HTTPClient.swift @@ -550,7 +550,7 @@ public struct SwiftlyHTTPClient: Sendable { { // These are new platforms that aren't yet in the list of known platforms in the OpenAPI schema case PlatformDefinition.ubuntu2404.name, PlatformDefinition.debian12.name, - PlatformDefinition.fedora39.name: + PlatformDefinition.fedora39.name, PlatformDefinition.gentoo.name: .init(platform.name) case PlatformDefinition.ubuntu2204.name: diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index e4782fc3..eb6fdf91 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -46,6 +46,9 @@ public struct PlatformDefinition: Codable, Equatable, Sendable { public static let debian12 = PlatformDefinition( name: "debian12", nameFull: "debian12", namePretty: "Debian GNU/Linux 12" ) + public static let gentoo = PlatformDefinition( + name: "gentoo", nameFull: "gentoo", namePretty: "Gentoo Linux" + ) } public struct RunProgramError: Swift.Error {