Skip to content

Commit aa76ff5

Browse files
requireSystemPackages: add OpenBSD support (#756)
1 parent d45edbe commit aa76ff5

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Sources/SWBTestSupport/SkippedTestSupport.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,29 @@ extension Trait where Self == Testing.ConditionTrait {
206206
}
207207
}
208208

209-
package static func requireSystemPackages(apt: String..., yum: String..., freebsd: String..., sourceLocation: SourceLocation = #_sourceLocation) -> Self {
209+
package static func requireSystemPackages(apt: String..., yum: String..., freebsd: String..., openbsd: String..., sourceLocation: SourceLocation = #_sourceLocation) -> Self {
210210
enabled("required system packages are not installed") {
211+
func installCommand(packageManagerPath: Path, packageNames: String) -> String {
212+
switch packageManagerPath.basenameWithoutSuffix {
213+
case "pkg_info":
214+
return "pkg_add \(packageNames)" // OpenBSD
215+
default:
216+
return "\(packageManagerPath.basenameWithoutSuffix) install \(packageNames)"
217+
}
218+
}
219+
211220
func checkInstalled(hostOS: OperatingSystem, packageManagerPath: Path, args: [String], packages: [String], regex: Regex<(Substring, name: Substring)>) async throws -> Bool {
212221
if try ProcessInfo.processInfo.hostOperatingSystem() == hostOS && localFS.exists(packageManagerPath) {
213222
var installedPackages: Set<String> = []
214-
for line in try await runProcess([packageManagerPath.str] + args + packages).split(separator: "\n") {
223+
for line in try await runProcess([packageManagerPath.str] + args + (packageManagerPath.basenameWithoutSuffix == "pkg_info" ? [] : packages)).split(separator: "\n") {
215224
if let packageName = try regex.firstMatch(in: line)?.output.name {
216225
installedPackages.insert(String(packageName))
217226
}
218227
}
219228

220229
let uninstalledPackages = Set(packages).subtracting(installedPackages)
221230
if !uninstalledPackages.isEmpty {
222-
Issue.record("system packages are missing. Install via `\(packageManagerPath.basenameWithoutSuffix) install \(uninstalledPackages.sorted().joined(separator: " "))`", sourceLocation: sourceLocation)
231+
Issue.record("system packages are missing. Install via `\(installCommand(packageManagerPath: packageManagerPath, packageNames: uninstalledPackages.sorted().joined(separator: " ")))`", sourceLocation: sourceLocation)
223232
return false
224233
}
225234
}
@@ -234,7 +243,9 @@ extension Trait where Self == Testing.ConditionTrait {
234243

235244
let freebsd = try await checkInstalled(hostOS: .freebsd, packageManagerPath: Path("/usr/sbin/pkg"), args: ["info"], packages: freebsd, regex: #/^Name(?:[ ]+): (?<name>.+)$/#)
236245

237-
return apt && yum && freebsd
246+
let openbsd = try await checkInstalled(hostOS: .openbsd, packageManagerPath: Path("/usr/sbin/pkg_info"), args: ["-A"], packages: openbsd, regex: #/^(?<name>.+)-.*/#)
247+
248+
return apt && yum && freebsd && openbsd
238249
}
239250
}
240251

Tests/SWBBuildSystemTests/BuildOperationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,7 @@ That command depends on command in Target 'agg2' (project \'aProject\'): script
24742474
}
24752475

24762476
/// Check non-UTF8 encoded shell scripts don't cause any unexpected issues.
2477-
@Test(.requireSDKs(.host), .skipHostOS(.windows), .requireSystemPackages(apt: "xxd", yum: "vim-common"))
2477+
@Test(.requireSDKs(.host), .skipHostOS(.windows), .requireSystemPackages(apt: "xxd", yum: "vim-common", freebsd: "xxd", openbsd: "vim"))
24782478
func nonUTF8ShellScript() async throws {
24792479
try await withTemporaryDirectory { tmpDir in
24802480
let testWorkspace = TestWorkspace(

Tests/SWBCoreTests/CommandLineToolSpecDiscoveredInfoTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ import SWBMacro
242242
}
243243
}
244244

245-
@Test(.skipHostOS(.windows), .requireSystemPackages(apt: "libtool", yum: "libtool", freebsd: "libtool"))
245+
@Test(.skipHostOS(.windows), .requireSystemPackages(apt: "libtool", yum: "libtool", freebsd: "libtool", openbsd: "libtool"))
246246
func discoveredLibtoolSpecInfo() async throws {
247247
try await withSpec(LibtoolLinkerSpec.self, .deferred) { (info: DiscoveredLibtoolLinkerToolSpecInfo) in
248248
#expect(info.toolPath.basename == "libtool")

0 commit comments

Comments
 (0)