Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 15 additions & 4 deletions Sources/SWBTestSupport/SkippedTestSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,20 +206,29 @@ 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<String> = []
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))
}
}

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
}
}
Expand All @@ -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(?:[ ]+): (?<name>.+)$/#)

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

return apt && yum && freebsd && openbsd
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/SWBBuildSystemTests/BuildOperationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down