From 5da3598b93541463526966c1ac3e19715884f9a8 Mon Sep 17 00:00:00 2001 From: Jake Petroules Date: Thu, 28 Aug 2025 17:03:05 -0700 Subject: [PATCH] requireSystemPackages: add OpenBSD support --- .../SWBTestSupport/SkippedTestSupport.swift | 19 +++++++++++++++---- .../BuildOperationTests.swift | 2 +- ...mmandLineToolSpecDiscoveredInfoTests.swift | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Sources/SWBTestSupport/SkippedTestSupport.swift b/Sources/SWBTestSupport/SkippedTestSupport.swift index b526492d..8bab2de5 100644 --- a/Sources/SWBTestSupport/SkippedTestSupport.swift +++ b/Sources/SWBTestSupport/SkippedTestSupport.swift @@ -206,12 +206,21 @@ extension Trait where Self == Testing.ConditionTrait { } } - package static func requireSystemPackages(apt: String..., yum: String..., freebsd: String..., sourceLocation: SourceLocation = #_sourceLocation) -> Self { + package static func requireSystemPackages(apt: String..., yum: String..., freebsd: String..., openbsd: String..., sourceLocation: SourceLocation = #_sourceLocation) -> Self { enabled("required system packages are not installed") { + func installCommand(packageManagerPath: Path, packageNames: String) -> String { + switch packageManagerPath.basenameWithoutSuffix { + case "pkg_info": + return "pkg_add \(packageNames)" // OpenBSD + default: + return "\(packageManagerPath.basenameWithoutSuffix) install \(packageNames)" + } + } + func checkInstalled(hostOS: OperatingSystem, packageManagerPath: Path, args: [String], packages: [String], regex: Regex<(Substring, name: Substring)>) async throws -> Bool { if try ProcessInfo.processInfo.hostOperatingSystem() == hostOS && localFS.exists(packageManagerPath) { var installedPackages: Set = [] - for line in try await runProcess([packageManagerPath.str] + args + packages).split(separator: "\n") { + for line in try await runProcess([packageManagerPath.str] + args + (packageManagerPath.basenameWithoutSuffix == "pkg_info" ? [] : packages)).split(separator: "\n") { if let packageName = try regex.firstMatch(in: line)?.output.name { installedPackages.insert(String(packageName)) } @@ -219,7 +228,7 @@ extension Trait where Self == Testing.ConditionTrait { let uninstalledPackages = Set(packages).subtracting(installedPackages) if !uninstalledPackages.isEmpty { - Issue.record("system packages are missing. Install via `\(packageManagerPath.basenameWithoutSuffix) install \(uninstalledPackages.sorted().joined(separator: " "))`", sourceLocation: sourceLocation) + Issue.record("system packages are missing. Install via `\(installCommand(packageManagerPath: packageManagerPath, packageNames: uninstalledPackages.sorted().joined(separator: " ")))`", sourceLocation: sourceLocation) return false } } @@ -234,7 +243,9 @@ extension Trait where Self == Testing.ConditionTrait { let freebsd = try await checkInstalled(hostOS: .freebsd, packageManagerPath: Path("/usr/sbin/pkg"), args: ["info"], packages: freebsd, regex: #/^Name(?:[ ]+): (?.+)$/#) - return apt && yum && freebsd + let openbsd = try await checkInstalled(hostOS: .openbsd, packageManagerPath: Path("/usr/sbin/pkg_info"), args: ["-A"], packages: openbsd, regex: #/^(?.+)-.*/#) + + return apt && yum && freebsd && openbsd } } diff --git a/Tests/SWBBuildSystemTests/BuildOperationTests.swift b/Tests/SWBBuildSystemTests/BuildOperationTests.swift index 3798b5bd..820558d1 100644 --- a/Tests/SWBBuildSystemTests/BuildOperationTests.swift +++ b/Tests/SWBBuildSystemTests/BuildOperationTests.swift @@ -2474,7 +2474,7 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script } /// Check non-UTF8 encoded shell scripts don't cause any unexpected issues. - @Test(.requireSDKs(.host), .skipHostOS(.windows), .requireSystemPackages(apt: "xxd", yum: "vim-common")) + @Test(.requireSDKs(.host), .skipHostOS(.windows), .requireSystemPackages(apt: "xxd", yum: "vim-common", freebsd: "xxd", openbsd: "vim")) func nonUTF8ShellScript() async throws { try await withTemporaryDirectory { tmpDir in let testWorkspace = TestWorkspace( diff --git a/Tests/SWBCoreTests/CommandLineToolSpecDiscoveredInfoTests.swift b/Tests/SWBCoreTests/CommandLineToolSpecDiscoveredInfoTests.swift index 1b541d75..78129048 100644 --- a/Tests/SWBCoreTests/CommandLineToolSpecDiscoveredInfoTests.swift +++ b/Tests/SWBCoreTests/CommandLineToolSpecDiscoveredInfoTests.swift @@ -242,7 +242,7 @@ import SWBMacro } } - @Test(.skipHostOS(.windows), .requireSystemPackages(apt: "libtool", yum: "libtool", freebsd: "libtool")) + @Test(.skipHostOS(.windows), .requireSystemPackages(apt: "libtool", yum: "libtool", freebsd: "libtool", openbsd: "libtool")) func discoveredLibtoolSpecInfo() async throws { try await withSpec(LibtoolLinkerSpec.self, .deferred) { (info: DiscoveredLibtoolLinkerToolSpecInfo) in #expect(info.toolPath.basename == "libtool")