Skip to content

Commit 80da18d

Browse files
committed
Revert "Revert "adopt swift-collections (#3632)" (#3677)"
This reverts commit a468072.
1 parent 79dbcff commit 80da18d

13 files changed

+67
-35
lines changed

CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ string(COMPARE EQUAL ${CMAKE_SYSTEM_NAME} Windows CMAKE_INSTALL_DEFAULT)
3737
option(USE_CMAKE_INSTALL
3838
"Install build products using cmake's install() instead of the bootstrap script's install()"
3939
${CMAKE_INSTALL_DEFAULT})
40-
40+
4141
if(BUILD_SHARED_LIBS)
4242
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
4343
endif()
@@ -53,6 +53,7 @@ if(FIND_PM_DEPS)
5353
find_package(ArgumentParser CONFIG REQUIRED)
5454
find_package(SwiftCrypto CONFIG REQUIRED)
5555
find_package(SwiftDriver CONFIG REQUIRED)
56+
find_package(SwiftCollections CONFIG REQUIRED)
5657
endif()
5758

5859
find_package(dispatch QUIET)

CONTRIBUTING.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Please refer to the [_Get Started_ guide](https://github.com/apple/swift/blob/ma
132132
Clone the following repositories beside the SwiftPM directory:
133133

134134
1. [swift-argument-parser] and check out tag with the [latest version](https://github.com/apple/swift-argument-parser/tags).
135-
135+
136136
For example, if the latest tag is 0.4.3:
137137
```sh
138138
$> git clone https://github.com/apple/swift-argument-parser --branch 0.4.3
@@ -150,7 +150,7 @@ Clone the following repositories beside the SwiftPM directory:
150150
```
151151

152152
4. [Yams] and checkout tag with the [latest version](https://github.com/jpsim/Yams.git/tags) before 5.0.0.
153-
153+
154154
For example, if the latest tag is 4.0.6:
155155
```sh
156156
$> git clone https://github.com/jpsim/yams --branch 4.0.6
@@ -162,13 +162,21 @@ Clone the following repositories beside the SwiftPM directory:
162162
```
163163

164164
6. [swift-crypto] and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags).
165-
165+
166166
For example, if the latest tag is 1.1.6:
167167
```sh
168168
$> git clone https://github.com/apple/swift-crypto --branch 1.1.6
169169
```
170170

171+
7. [swift-collections] and check out tag with the [latest version](https://github.com/apple/swift-collections/tags).
172+
173+
For example, if the latest tag is 0.0.5:
174+
```sh
175+
$> git clone https://github.com/apple/swift-collections --branch 0.0.5
176+
```
177+
171178
[swift-argument-parser]: https://github.com/apple/swift-argument-parser
179+
[swift-collections]: https://github.com/apple/swift-collections
172180
[swift-crypto]: https://github.com/apple/swift-crypto
173181
[swift-driver]: https://github.com/apple/swift-driver
174182
[swift-llbuild]: https://github.com/apple/swift-llbuild
@@ -385,4 +393,3 @@ $> swift package update
385393
```
386394
Alternatively, if you are using Xcode, you can update to the latest version of all packages:
387395
**Xcode App** > *File* > *Swift Packages* > *Update to Latest Package Versions*
388-

Package.swift

+6-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ let package = Package(
133133

134134
.target(
135135
name: "Basics",
136-
dependencies: ["SwiftToolsSupport-auto"]),
136+
dependencies: [
137+
.product(name: "OrderedCollections", package: "swift-collections"),
138+
"SwiftToolsSupport-auto"
139+
]),
137140

138141
.target(
139142
/** The llbuild manifest model */
@@ -378,12 +381,14 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
378381
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
379382
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
380383
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: minimumCryptoVersion)),
384+
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.0.1")),
381385
]
382386
} else {
383387
package.dependencies += [
384388
.package(path: "../swift-tools-support-core"),
385389
.package(path: "../swift-argument-parser"),
386390
.package(path: "../swift-driver"),
387391
.package(path: "../swift-crypto"),
392+
.package(path: "../swift-collections"),
388393
]
389394
}

Sources/Basics/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ add_library(Basics
1414
DispatchTimeInterval+Extensions.swift
1515
EnvironmentVariables.swift
1616
Errors.swift
17+
Exports.swift
1718
FileSystem+Extensions.swift
1819
HTPClient+URLSession.swift
1920
HTTPClient.swift
@@ -25,6 +26,7 @@ add_library(Basics
2526
SQLiteBackedCache.swift
2627
Version+Extensions.swift)
2728
target_link_libraries(Basics PUBLIC
29+
SwiftCollections::OrderedCollections
2830
TSCBasic
2931
TSCUtility)
3032
target_link_libraries(Basics PRIVATE

Sources/Basics/Exports.swift

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import OrderedCollections
12+
13+
public typealias OrderedDictionary = OrderedCollections.OrderedDictionary
14+
public typealias OrderedSet = OrderedCollections.OrderedSet

Sources/Build/BuildPlan.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ public class BuildPlan {
19921992
}
19931993

19941994
// Build cache
1995-
var cflagsCache: OrderedSet<String> = []
1995+
var cflagsCache: Basics.OrderedSet<String> = []
19961996
var libsCache: [String] = []
19971997
for tuple in ret {
19981998
for cFlag in tuple.cFlags {

Sources/PackageGraph/PackageGraph+Loading.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ fileprivate func findCycle(
636636
successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
637637
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
638638
// Ordered set to hold the current traversed path.
639-
var path = OrderedSet<Manifest>()
639+
var path = Basics.OrderedSet<Manifest>()
640640

641641
// Function to visit nodes recursively.
642642
// FIXME: Convert to stack.
@@ -645,7 +645,7 @@ fileprivate func findCycle(
645645
_ successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
646646
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
647647
// If this node is already in the current path then we have found a cycle.
648-
if !path.append(node.manifest) {
648+
if !path.append(node.manifest).inserted {
649649
let index = path.firstIndex(of: node.manifest)! // forced unwrap safe
650650
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
651651
}

Sources/PackageGraph/Pubgrub/Incompatibility.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ import PackageModel
1616
/// all be true at the same time. In dependency resolution, these are derived
1717
/// from version requirements and when running into unresolvable situations.
1818
public struct Incompatibility: Equatable, Hashable {
19-
public let terms: OrderedSet<Term>
19+
public let terms: Basics.OrderedSet<Term>
2020
public let cause: Cause
2121

22-
public init(terms: OrderedSet<Term>, cause: Cause) {
22+
public init(terms: Basics.OrderedSet<Term>, cause: Cause) {
2323
self.terms = terms
2424
self.cause = cause
2525
}
2626

2727
public init(_ terms: Term..., root: DependencyResolutionNode, cause: Cause = .root) throws {
28-
let termSet = OrderedSet(terms)
28+
let termSet = Basics.OrderedSet(terms)
2929
try self.init(termSet, root: root, cause: cause)
3030
}
3131

32-
public init(_ terms: OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
32+
public init(_ terms: Basics.OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
3333
if terms.isEmpty {
3434
self.init(terms: terms, cause: cause)
3535
return
@@ -43,7 +43,7 @@ public struct Incompatibility: Equatable, Hashable {
4343
terms = OrderedSet(terms.filter { !$0.isPositive || $0.node != root })
4444
}
4545

46-
let normalizedTerms = try normalize(terms: terms.contents)
46+
let normalizedTerms = try normalize(terms: terms.elements)
4747
assert(normalizedTerms.count > 0,
4848
"An incompatibility must contain at least one term after normalization.")
4949
self.init(terms: OrderedSet(normalizedTerms), cause: cause)
@@ -134,7 +134,7 @@ extension Incompatibility {
134134
/// requirements to a^1.5.0.
135135
fileprivate func normalize(terms: [Term]) throws -> [Term] {
136136

137-
let dict = try terms.reduce(into: OrderedDictionary<DependencyResolutionNode, (req: VersionSetSpecifier, polarity: Bool)>()) {
137+
let dict = try terms.reduce(into: Basics.OrderedDictionary<DependencyResolutionNode, (req: VersionSetSpecifier, polarity: Bool)>()) {
138138
res, term in
139139
// Don't try to intersect if this is the first time we're seeing this package.
140140
guard let previous = res[term.node] else {

Sources/PackageGraph/Pubgrub/PartialSolution.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct PartialSolution {
2525

2626
/// The intersection of all positive assignments for each package, minus any
2727
/// negative assignments that refer to that package.
28-
public private(set) var _positive: OrderedDictionary<DependencyResolutionNode, Term> = [:]
28+
public private(set) var _positive: Basics.OrderedDictionary<DependencyResolutionNode, Term> = [:]
2929

3030
/// Union of all negative assignments for a package.
3131
///

Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public struct PubgrubDependencyResolver {
443443
/// If a conflict is found, the conflicting incompatibility is returned to
444444
/// resolve the conflict on.
445445
internal func propagate(state: State, node: DependencyResolutionNode) throws {
446-
var changed: OrderedSet<DependencyResolutionNode> = [node]
446+
var changed: Basics.OrderedSet<DependencyResolutionNode> = [node]
447447

448448
while !changed.isEmpty {
449449
let package = changed.removeFirst()
@@ -1212,7 +1212,7 @@ private final class PubGrubPackageContainer {
12121212
throw InternalError("Unexpected unversioned requirement: \(constraint)")
12131213
}
12141214
return try constraint.nodes().map { dependencyNode in
1215-
var terms: OrderedSet<Term> = []
1215+
var terms: Basics.OrderedSet<Term> = []
12161216
terms.append(Term(node, .exact(version)))
12171217
terms.append(Term(not: dependencyNode, vs))
12181218
return try Incompatibility(terms, root: root, cause: .dependency(node: node))
@@ -1226,7 +1226,7 @@ private final class PubGrubPackageContainer {
12261226
products: node.productFilter)
12271227

12281228
return try constraints.map { constraint in
1229-
var terms: OrderedSet<Term> = []
1229+
var terms: Basics.OrderedSet<Term> = []
12301230
let lowerBound = lowerBounds[constraint.package] ?? "0.0.0"
12311231
let upperBound = upperBounds[constraint.package] ?? Version(version.major + 1, 0, 0)
12321232
assert(lowerBound < upperBound)

Sources/PackageLoading/PackageBuilder.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1160,11 +1160,11 @@ public final class PackageBuilder {
11601160

11611161
/// Collects the products defined by a package.
11621162
private func constructProducts(_ targets: [Target]) throws -> [Product] {
1163-
var products = OrderedSet<KeyedPair<Product, String>>()
1163+
var products = Basics.OrderedSet<KeyedPair<Product, String>>()
11641164

11651165
/// Helper method to append to products array.
11661166
func append(_ product: Product) {
1167-
let inserted = products.append(KeyedPair(product, key: product.name))
1167+
let inserted = products.append(KeyedPair(product, key: product.name)).inserted
11681168
if !inserted {
11691169
self.observabilityScope.emit(.duplicateProduct(product: product))
11701170
}

Tests/PackageGraphTests/PubgrubTests.swift

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import XCTest
12-
13-
import TSCBasic
11+
import Basics
12+
@testable import PackageGraph
1413
import PackageLoading
1514
@testable import PackageModel
16-
@testable import PackageGraph
1715
import SourceControl
1816
import SPMTestSupport
19-
20-
17+
import TSCBasic
18+
import XCTest
2119

2220
// There's some useful helper utilities defined below for easier testing:
2321
//
@@ -2156,7 +2154,7 @@ class DependencyGraphBuilder {
21562154
}
21572155

21582156
func create(
2159-
dependencies: OrderedDictionary<String, (PackageRequirement, ProductFilter)>
2157+
dependencies: Basics.OrderedDictionary<String, (PackageRequirement, ProductFilter)>
21602158
) -> [PackageContainerConstraint] {
21612159
return dependencies.map {
21622160
PackageContainerConstraint(package: reference(for: $0), requirement: $1.0, products: $1.1)
@@ -2167,7 +2165,7 @@ class DependencyGraphBuilder {
21672165
_ package: String,
21682166
at version: Version,
21692167
toolsVersion: ToolsVersion? = nil,
2170-
with dependencies: KeyValuePairs<String, OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
2168+
with dependencies: KeyValuePairs<String, Basics.OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
21712169
) {
21722170
serve(package, at: .version(version), toolsVersion: toolsVersion, with: dependencies)
21732171
}
@@ -2176,7 +2174,7 @@ class DependencyGraphBuilder {
21762174
_ package: String,
21772175
at version: BoundVersion,
21782176
toolsVersion: ToolsVersion? = nil,
2179-
with dependencies: KeyValuePairs<String, OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
2177+
with dependencies: KeyValuePairs<String, Basics.OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
21802178
) {
21812179
let packageReference = reference(for: package)
21822180
let container = self.containers[package] ?? MockContainer(package: packageReference)

Utilities/bootstrap

+10-5
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ def parse_global_args(args):
185185
args.source_dirs["swift-argument-parser"] = os.path.join(args.project_root, "..", "swift-argument-parser")
186186
args.source_dirs["swift-driver"] = os.path.join(args.project_root, "..", "swift-driver")
187187
args.source_dirs["swift-crypto"] = os.path.join(args.project_root, "..", "swift-crypto")
188+
args.source_dirs["swift-collections"] = os.path.join(args.project_root, "..", "swift-collections")
188189
args.source_root = os.path.join(args.project_root, "Sources")
189190

190191
if platform.system() == 'Darwin':
@@ -341,6 +342,7 @@ def build(args):
341342
]
342343
build_dependency(args, "swift-driver", swift_driver_cmake_flags)
343344
build_dependency(args, "swift-crypto")
345+
build_dependency(args, "swift-collections")
344346
build_swiftpm_with_cmake(args)
345347

346348
build_swiftpm_with_swiftpm(args,integrated_swift_driver=False)
@@ -553,11 +555,12 @@ def build_swiftpm_with_cmake(args):
553555

554556
cmake_flags = [
555557
get_llbuild_cmake_arg(args),
556-
"-DTSC_DIR=" + os.path.join(args.build_dirs["tsc"], "cmake/modules"),
557-
"-DYams_DIR=" + os.path.join(args.build_dirs["yams"], "cmake/modules"),
558-
"-DArgumentParser_DIR=" + os.path.join(args.build_dirs["swift-argument-parser"], "cmake/modules"),
559-
"-DSwiftDriver_DIR=" + os.path.join(args.build_dirs["swift-driver"], "cmake/modules"),
560-
"-DSwiftCrypto_DIR=" + os.path.join(args.build_dirs["swift-crypto"], "cmake/modules"),
558+
"-DTSC_DIR=" + os.path.join(args.build_dirs["tsc"], "cmake/modules"),
559+
"-DYams_DIR=" + os.path.join(args.build_dirs["yams"], "cmake/modules"),
560+
"-DArgumentParser_DIR=" + os.path.join(args.build_dirs["swift-argument-parser"], "cmake/modules"),
561+
"-DSwiftDriver_DIR=" + os.path.join(args.build_dirs["swift-driver"], "cmake/modules"),
562+
"-DSwiftCrypto_DIR=" + os.path.join(args.build_dirs["swift-crypto"], "cmake/modules"),
563+
"-DSwiftCollections_DIR=" + os.path.join(args.build_dirs["swift-collections"], "cmake/modules"),
561564
]
562565

563566
if platform.system() == 'Darwin':
@@ -574,6 +577,7 @@ def build_swiftpm_with_cmake(args):
574577
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-argument-parser"], "lib"))
575578
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-driver"], "lib"))
576579
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-crypto"], "lib"))
580+
add_rpath_for_cmake_build(args, os.path.join(args.build_dirs["swift-collections"], "lib"))
577581

578582
def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
579583
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
@@ -678,6 +682,7 @@ def get_swiftpm_env_cmd(args):
678682
os.path.join(args.build_dirs["swift-argument-parser"], "lib"),
679683
os.path.join(args.build_dirs["swift-driver"], "lib"),
680684
os.path.join(args.build_dirs["swift-crypto"], "lib"),
685+
os.path.join(args.build_dirs["swift-collections"], "lib"),
681686
] + args.target_info["paths"]["runtimeLibraryPaths"])
682687

683688
if platform.system() == 'Darwin':

0 commit comments

Comments
 (0)