@@ -206,20 +206,29 @@ extension Trait where Self == Testing.ConditionTrait {
206
206
}
207
207
}
208
208
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 {
210
210
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
+
211
220
func checkInstalled( hostOS: OperatingSystem , packageManagerPath: Path , args: [ String ] , packages: [ String ] , regex: Regex < ( Substring , name: Substring ) > ) async throws -> Bool {
212
221
if try ProcessInfo . processInfo. hostOperatingSystem ( ) == hostOS && localFS. exists ( packageManagerPath) {
213
222
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 " ) {
215
224
if let packageName = try regex. firstMatch ( in: line) ? . output. name {
216
225
installedPackages. insert ( String ( packageName) )
217
226
}
218
227
}
219
228
220
229
let uninstalledPackages = Set ( packages) . subtracting ( installedPackages)
221
230
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)
223
232
return false
224
233
}
225
234
}
@@ -234,7 +243,9 @@ extension Trait where Self == Testing.ConditionTrait {
234
243
235
244
let freebsd = try await checkInstalled ( hostOS: . freebsd, packageManagerPath: Path ( " /usr/sbin/pkg " ) , args: [ " info " ] , packages: freebsd, regex: #/^Name(?:[ ]+): (?<name>.+)$/# )
236
245
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
238
249
}
239
250
}
240
251
0 commit comments