Skip to content

Commit cf6b2ee

Browse files
committed
Roll back to arrays and reduce the diff
1 parent a988ac3 commit cf6b2ee

File tree

9 files changed

+24
-35
lines changed

9 files changed

+24
-35
lines changed

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,10 +862,10 @@ private final class ResolvedTargetBuilder: ResolvedBuilder<ResolvedTarget> {
862862
enum Dependency {
863863

864864
/// Dependency to another target, with conditions.
865-
case target(_ target: ResolvedTargetBuilder, conditions: Set<PackageCondition>)
865+
case target(_ target: ResolvedTargetBuilder, conditions: [PackageCondition])
866866

867867
/// Dependency to a product, with conditions.
868-
case product(_ product: ResolvedProductBuilder, conditions: Set<PackageCondition>)
868+
case product(_ product: ResolvedProductBuilder, conditions: [PackageCondition])
869869
}
870870

871871
/// The target reference.

Sources/PackageGraph/Resolution/ResolvedTarget.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ public final class ResolvedTarget {
1919
/// Represents dependency of a resolved target.
2020
public enum Dependency: Hashable {
2121
/// Direct dependency of the target. This target is in the same package and should be statically linked.
22-
case target(_ target: ResolvedTarget, conditions: Set<PackageCondition>)
22+
case target(_ target: ResolvedTarget, conditions: [PackageCondition])
2323

2424
/// The target depends on this product.
25-
case product(_ product: ResolvedProduct, conditions: Set<PackageCondition>)
25+
case product(_ product: ResolvedProduct, conditions: [PackageCondition])
2626

2727
public var target: ResolvedTarget? {
2828
switch self {
@@ -38,7 +38,7 @@ public final class ResolvedTarget {
3838
}
3939
}
4040

41-
public var conditions: Set<PackageCondition> {
41+
public var conditions: [PackageCondition] {
4242
switch self {
4343
case .target(_, let conditions): return conditions
4444
case .product(_, let conditions): return conditions

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ public final class PackageBuilder {
11361136
// Create an assignment for this setting.
11371137
var assignment = BuildSettings.Assignment()
11381138
assignment.values = values
1139-
assignment.uniqueConditions = self.buildConditions(from: setting.condition)
1139+
assignment.conditions = self.buildConditions(from: setting.condition)
11401140

11411141
// Finally, add the assignment to the assignment table.
11421142
table.add(assignment, for: decl)
@@ -1145,12 +1145,12 @@ public final class PackageBuilder {
11451145
return table
11461146
}
11471147

1148-
func buildConditions(from condition: PackageConditionDescription?) -> Set<PackageCondition> {
1149-
var conditions: Set<PackageCondition> = []
1148+
func buildConditions(from condition: PackageConditionDescription?) -> [PackageCondition] {
1149+
var conditions = [PackageCondition]()
11501150

11511151
if let config = condition?.config.flatMap({ BuildConfiguration(rawValue: $0) }) {
11521152
let condition = ConfigurationCondition(configuration: config)
1153-
conditions.insert(.configuration(condition))
1153+
conditions.append(.configuration(condition))
11541154
}
11551155

11561156
if let platforms = condition?.platformNames.map({
@@ -1163,7 +1163,7 @@ public final class PackageBuilder {
11631163
!platforms.isEmpty
11641164
{
11651165
let condition = PlatformsCondition(platforms: platforms)
1166-
conditions.insert(.platforms(condition))
1166+
conditions.append(.platforms(condition))
11671167
}
11681168

11691169
return conditions

Sources/PackageModel/BuildSettings.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,9 @@ public enum BuildSettings {
4444
public var values: [String]
4545

4646
/// The condition associated with this assignment.
47-
@available(*, deprecated, renamed: "uniqueConditions")
48-
public var conditions: [PackageConditionProtocol] {
47+
public var conditions: [PackageCondition] {
4948
get {
50-
return _conditions.map{ $0.condition }
51-
}
52-
set {
53-
_conditions = newValue.map{ PackageConditionWrapper($0) }
54-
}
55-
}
56-
57-
/// A set of unique conditions associated with this assignment.
58-
public var uniqueConditions: Set<PackageCondition> {
59-
get {
60-
return Set(_conditions.map(\.underlying))
49+
return _conditions.map { $0.underlying }
6150
}
6251
set {
6352
_conditions = newValue.map { PackageConditionWrapper($0) }
@@ -111,7 +100,7 @@ public enum BuildSettings {
111100
// Add values from each assignment if it satisfies the build environment.
112101
let values = assignments
113102
.lazy
114-
.filter { $0.uniqueConditions.allSatisfy { $0.satisfies(self.environment) } }
103+
.filter { $0.conditions.allSatisfy { $0.satisfies(self.environment) } }
115104
.flatMap { $0.values }
116105

117106
return Array(values)

Sources/PackageModel/Target/Target.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public class Target: PolymorphicCodableProtocol {
7979
/// A target dependency to a target or product.
8080
public enum Dependency {
8181
/// A dependency referencing another target, with conditions.
82-
case target(_ target: Target, conditions: Set<PackageCondition>)
82+
case target(_ target: Target, conditions: [PackageCondition])
8383

8484
/// A dependency referencing a product, with conditions.
85-
case product(_ product: ProductReference, conditions: Set<PackageCondition>)
85+
case product(_ product: ProductReference, conditions: [PackageCondition])
8686

8787
/// The target if the dependency is a target dependency.
8888
public var target: Target? {
@@ -103,7 +103,7 @@ public class Target: PolymorphicCodableProtocol {
103103
}
104104

105105
/// The dependency conditions.
106-
public var conditions: Set<PackageCondition> {
106+
public var conditions: [PackageCondition] {
107107
switch self {
108108
case .target(_, let conditions):
109109
return conditions

Sources/SPMBuildCore/Plugins/PluginInvocation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public extension PluginTarget {
584584
}
585585

586586
fileprivate extension Target.Dependency {
587-
var conditions: Set<PackageCondition> {
587+
var conditions: [PackageCondition] {
588588
switch self {
589589
case .target(_, let conditions): return conditions
590590
case .product(_, let conditions): return conditions

Sources/XCBuildSupport/PIF.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ public enum PIF {
10021002
}
10031003

10041004
public var conditions: [String] {
1005-
let filters = Set([.init(platforms: [packageModelPlatform])])
1005+
let filters = [.init(platforms: [packageModelPlatform])]
10061006
.toPlatformFilters().map { (filter: PIF.PlatformFilter) -> String in
10071007
if filter.environment.isEmpty {
10081008
return filter.platform

Sources/XCBuildSupport/PIFBuilder.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
781781
private func addDependency(
782782
to target: ResolvedTarget,
783783
in pifTarget: PIFTargetBuilder,
784-
conditions: Set<PackageCondition>,
784+
conditions: [PackageCondition],
785785
linkProduct: Bool
786786
) {
787787
// Only add the binary target as a library when we want to link against the product.
@@ -803,7 +803,7 @@ final class PackagePIFProjectBuilder: PIFProjectBuilder {
803803
private func addDependency(
804804
to product: ResolvedProduct,
805805
in pifTarget: PIFTargetBuilder,
806-
conditions: Set<PackageCondition>,
806+
conditions: [PackageCondition],
807807
linkProduct: Bool
808808
) {
809809
pifTarget.addDependency(
@@ -1498,15 +1498,15 @@ private extension BuildSettings.AssignmentTable {
14981498

14991499
private extension BuildSettings.Assignment {
15001500
var configurations: [BuildConfiguration] {
1501-
if let configurationCondition = uniqueConditions.lazy.compactMap(\.configurationCondition).first {
1501+
if let configurationCondition = conditions.lazy.compactMap(\.configurationCondition).first {
15021502
return [configurationCondition.configuration]
15031503
} else {
15041504
return BuildConfiguration.allCases
15051505
}
15061506
}
15071507

15081508
var pifPlatforms: [PIF.BuildSettings.Platform]? {
1509-
if let platformsCondition = uniqueConditions.lazy.compactMap(\.platformsCondition).first {
1509+
if let platformsCondition = conditions.lazy.compactMap(\.platformsCondition).first {
15101510
return platformsCondition.platforms.compactMap { PIF.BuildSettings.Platform(rawValue: $0.name) }
15111511
} else {
15121512
return nil
@@ -1537,7 +1537,7 @@ public struct DelayedImmutable<Value> {
15371537
}
15381538
}
15391539

1540-
extension Set<PackageCondition> {
1540+
extension [PackageCondition] {
15411541
func toPlatformFilters() -> [PIF.PlatformFilter] {
15421542
var result: [PIF.PlatformFilter] = []
15431543
let platformConditions = self.compactMap(\.platformsCondition).flatMap { $0.platforms }

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ class PackageBuilderTests: XCTestCase {
29902990

29912991
var assignment = BuildSettings.Assignment()
29922992
assignment.values = ["YOLO"]
2993-
assignment.uniqueConditions = Set([.init(platforms: [PackageModel.Platform.custom(name: "bestOS", oldestSupportedVersion: .unknown)])])
2993+
assignment.conditions = [.init(platforms: [PackageModel.Platform.custom(name: "bestOS", oldestSupportedVersion: .unknown)])]
29942994

29952995
var settings = BuildSettings.AssignmentTable()
29962996
settings.add(assignment, for: .SWIFT_ACTIVE_COMPILATION_CONDITIONS)

0 commit comments

Comments
 (0)