Skip to content

Commit 80c3fa4

Browse files
committed
Add yum provider support
1 parent 6422633 commit 80c3fa4

File tree

10 files changed

+55
-2
lines changed

10 files changed

+55
-2
lines changed

Sources/PackageDescription/PackageDescription.swift

+22
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,11 @@ public enum SystemPackageProvider {
426426
#if PACKAGE_DESCRIPTION_4
427427
case brewItem([String])
428428
case aptItem([String])
429+
case yumItem([String])
429430
#else
430431
case _brewItem([String])
431432
case _aptItem([String])
433+
case _yumItem([String])
432434
#endif
433435

434436
/// Declare the list of installable packages using the homebrew package
@@ -456,6 +458,19 @@ public enum SystemPackageProvider {
456458
return ._aptItem(packages)
457459
#endif
458460
}
461+
462+
/// Declare the list of installable packages using the yum package
463+
/// manager on RHEL/CentOS to create a system package provider instance.
464+
///
465+
/// - Parameters:
466+
/// - packages: The list of package names.
467+
public static func yum(_ packages: [String]) -> SystemPackageProvider {
468+
#if PACKAGE_DESCRIPTION_4
469+
return .yumItem(packages)
470+
#else
471+
return ._yumItem(packages)
472+
#endif
473+
}
459474
}
460475

461476
// MARK: Package JSON serialization
@@ -513,6 +528,7 @@ extension SystemPackageProvider: Encodable {
513528
private enum Name: String, Encodable {
514529
case brew
515530
case apt
531+
case yum
516532
}
517533

518534
public func encode(to encoder: Encoder) throws {
@@ -525,6 +541,9 @@ extension SystemPackageProvider: Encodable {
525541
case .aptItem(let packages):
526542
try container.encode(Name.apt, forKey: .name)
527543
try container.encode(packages, forKey: .values)
544+
case .yumItem(let packages):
545+
try container.encode(Name.yum, forKey: .name)
546+
try container.encode(packages, forKey: .values)
528547
}
529548
#else
530549
switch self {
@@ -534,6 +553,9 @@ extension SystemPackageProvider: Encodable {
534553
case ._aptItem(let packages):
535554
try container.encode(Name.apt, forKey: .name)
536555
try container.encode(packages, forKey: .values)
556+
case ._yumItem(let packages):
557+
try container.encode(Name.yum, forKey: .name)
558+
try container.encode(packages, forKey: .values)
537559
}
538560
#endif
539561
}

Sources/PackageLoading/PackageDescription4Loader.swift

+2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ extension SystemPackageProviderDescription {
219219
self = .brew(value)
220220
case "apt":
221221
self = .apt(value)
222+
case "yum":
223+
self = .yum(value)
222224
default:
223225
fatalError()
224226
}

Sources/PackageLoading/Target+PkgConfig.swift

+8
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ extension SystemPackageProviderDescription {
103103
return " brew install \(packages.joined(separator: " "))\n"
104104
case .apt(let packages):
105105
return " apt-get install \(packages.joined(separator: " "))\n"
106+
case .yum(let packages):
107+
return " yum install \(packages.joined(separator: " "))\n"
106108
}
107109
}
108110

@@ -121,6 +123,10 @@ extension SystemPackageProviderDescription {
121123
if case .android = platform {
122124
return true
123125
}
126+
case .yum:
127+
if case .linux(.fedora) = platform {
128+
return true
129+
}
124130
}
125131
return false
126132
}
@@ -149,6 +155,8 @@ extension SystemPackageProviderDescription {
149155
return packages.map({ AbsolutePath(brewPrefix).appending(components: "opt", $0, "lib", "pkgconfig") })
150156
case .apt:
151157
return []
158+
case .yum:
159+
return []
152160
}
153161
}
154162

Sources/PackageModel/Manifest.swift

+1
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ public struct ProductDescription: Equatable, Codable {
485485
public enum SystemPackageProviderDescription: Equatable {
486486
case brew([String])
487487
case apt([String])
488+
case yum([String])
488489
}
489490

490491
/// Represents a package dependency.

Sources/PackageModel/PackageModel+Codable.swift

+8-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension ProductType: Codable {
4949

5050
extension SystemPackageProviderDescription: Codable {
5151
private enum CodingKeys: String, CodingKey {
52-
case brew, apt
52+
case brew, apt, yum
5353
}
5454

5555
public func encode(to encoder: Encoder) throws {
@@ -61,6 +61,9 @@ extension SystemPackageProviderDescription: Codable {
6161
case let .apt(a1):
6262
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .apt)
6363
try unkeyedContainer.encode(a1)
64+
case let .yum(a1):
65+
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .yum)
66+
try unkeyedContainer.encode(a1)
6467
}
6568
}
6669

@@ -78,6 +81,10 @@ extension SystemPackageProviderDescription: Codable {
7881
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
7982
let a1 = try unkeyedValues.decode([String].self)
8083
self = .apt(a1)
84+
case .yum:
85+
var unkeyedValues = try values.nestedUnkeyedContainer(forKey: key)
86+
let a1 = try unkeyedValues.decode([String].self)
87+
self = .yum(a1)
8188
}
8289
}
8390
}

Tests/BuildTests/BuildPlanTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,7 @@ final class BuildPlanTests: XCTestCase {
14121412
providers: [
14131413
.brew(["BTarget"]),
14141414
.apt(["BTarget"]),
1415+
.yum(["BTarget"]),
14151416
]
14161417
)
14171418
]),

Tests/PackageLoadingTests/PD4LoadingTests.swift

+2
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class PackageDescription4LoadingTests: PackageDescriptionLoadingTests {
202202
providers: [
203203
.brew(["openssl"]),
204204
.apt(["openssl", "libssl-dev"]),
205+
.yum(["openssl", "libssl-devel"]),
205206
]
206207
)
207208
"""
@@ -211,6 +212,7 @@ class PackageDescription4LoadingTests: PackageDescriptionLoadingTests {
211212
XCTAssertEqual(manifest.providers, [
212213
.brew(["openssl"]),
213214
.apt(["openssl", "libssl-dev"]),
215+
.yum(["openssl", "libssl-devel"]),
214216
])
215217
}
216218
}

Tests/PackageLoadingTests/PD4_2LoadingTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
299299
providers: [
300300
.brew(["libgit"]),
301301
.apt(["a", "b"]),
302+
.yum(["c", "d"]),
302303
]),
303304
]
304305
)
@@ -314,7 +315,7 @@ class PackageDescription4_2LoadingTests: PackageDescriptionLoadingTests {
314315
XCTAssertEqual(bar.name, "bar")
315316
XCTAssertEqual(bar.type, .system)
316317
XCTAssertEqual(bar.pkgConfig, "libbar")
317-
XCTAssertEqual(bar.providers, [.brew(["libgit"]), .apt(["a", "b"])])
318+
XCTAssertEqual(bar.providers, [.brew(["libgit"]), .apt(["a", "b"]), .yum(["c", "d"])])
318319
}
319320
}
320321

Tests/PackageLoadingTests/PkgConfigTests.swift

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class PkgConfigTests: XCTestCase {
4545
providers: [
4646
.brew(["libFoo"]),
4747
.apt(["libFoo-dev"]),
48+
.yum(["libFoo-devel"])
4849
]
4950
)
5051
let result = pkgConfigArgs(for: target, diagnostics: diagnostics)!
@@ -56,6 +57,8 @@ class PkgConfigTests: XCTestCase {
5657
XCTAssertEqual(names, ["libFoo"])
5758
case .apt(let names)?:
5859
XCTAssertEqual(names, ["libFoo-dev"])
60+
case .yum(let names)?:
61+
XCTAssertEqual(names, ["libFoo-devel"])
5962
case nil:
6063
XCTFail("Expected a provider here")
6164
}

swift-tools-support-core/Sources/TSCUtility/Platform.swift

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public enum Platform {
2020
/// Recognized flavors of linux.
2121
public enum LinuxFlavor {
2222
case debian
23+
case fedora
2324
}
2425

2526
/// Lazily checked current platform.
@@ -38,6 +39,11 @@ public enum Platform {
3839
localFileSystem.isFile(AbsolutePath("/system/bin/toybox")) {
3940
return .android
4041
}
42+
if localFileSystem.isFile(AbsolutePath("/etc/redhat-release")) ||
43+
localFileSystem.isFile(AbsolutePath("/etc/centos-release")) ||
44+
localFileSystem.isFile(AbsolutePath("/etc/fedora-release")) {
45+
return .linux(.fedora)
46+
}
4147
default:
4248
return nil
4349
}

0 commit comments

Comments
 (0)