Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt Swift Collections' OrderedSet and OrderedDictionary #3533

Closed
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ if(FIND_PM_DEPS)
endif()

find_package(ArgumentParser CONFIG REQUIRED)
find_package(swift-collections CONFIG REQUIRED)
find_package(SwiftCrypto CONFIG REQUIRED)
find_package(SwiftDriver CONFIG REQUIRED)
endif()
Expand Down
60 changes: 33 additions & 27 deletions Documentation/Contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,39 +129,45 @@ The bootstrap script requires having [CMake](https://cmake.org/) and [Ninja](htt
Please refer to the [_Get Started_ guide](https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md#installing-dependencies) on the Swift project repository for installation instructions.

1. Clone [llbuild](https://github.com/apple/swift-llbuild) beside the SwiftPM directory.

```bash
$> git clone https://github.com/apple/swift-llbuild llbuild
```

Note: Make sure the directory for llbuild is called "llbuild" and not
"swift-llbuild".

```bash
$> git clone https://github.com/apple/swift-llbuild llbuild
```

> **Note**: Make sure the directory for llbuild is called "llbuild" and not "swift-llbuild".

2. Clone [Yams](https://github.com/jpsim/yams) beside the SwiftPM directory.

```bash
$> git clone https://github.com/jpsim/yams
```
```bash
$> git clone https://github.com/jpsim/yams
```

3. Clone [swift-driver](https://github.com/apple/swift-driver) beside the SwiftPM directory.

```bash
$> git clone https://github.com/apple/swift-driver
```
```bash
$> git clone https://github.com/apple/swift-driver
```

4. Clone [swift-argument-parser](https://github.com/apple/swift-argument-parser) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-argument-parser/tags).

For example, if the latest tag is 0.3.1:
```bash
$> git clone https://github.com/apple/swift-argument-parser --branch 0.3.1
```

5. Clone [swift-crypto](https://github.com/apple/swift-crypto) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags).

For example, if the latest tag is 1.1.3:
```bash
$> git clone https://github.com/apple/swift-crypto --branch 1.1.3
```

For example, if the latest tag is 0.4.3:
```sh
$> git clone https://github.com/apple/swift-argument-parser --branch 0.4.3
```

5. Clone [swift-collections](https://github.com/apple/swift-collections) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-collections/tags).

For example, if the latest tag is 0.0.3:
```sh
$> git clone https://github.com/apple/swift-collections --branch 0.0.3
```

6. Clone [swift-crypto](https://github.com/apple/swift-crypto) beside the SwiftPM directory and check out tag with the [latest version](https://github.com/apple/swift-crypto/tags).

For example, if the latest tag is 1.1.4:
```sh
$> git clone https://github.com/apple/swift-crypto --branch 1.1.4
```

#### Building

Expand Down
37 changes: 32 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,29 @@ let package = Package(
.target(
/** Package model conventions and loading support */
name: "PackageLoading",
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageModel", "SourceControl"]),
dependencies: [
"SwiftToolsSupport-auto",
"Basics",
"OrderedCollections",
"PackageModel",
"SourceControl",
]
),

// MARK: Package Dependency Resolution

.target(
/** Data structures and support for complete package graphs */
name: "PackageGraph",
dependencies: ["SwiftToolsSupport-auto", "Basics", "PackageLoading", "PackageModel", "SourceControl"]),
dependencies: [
"SwiftToolsSupport-auto",
"Basics",
"OrderedCollections",
"PackageLoading",
"PackageModel",
"SourceControl",
]
),

// MARK: Package Collections

Expand Down Expand Up @@ -199,7 +214,17 @@ let package = Package(
.target(
/** Builds Modules and Products */
name: "Build",
dependencies: ["SwiftToolsSupport-auto", "Basics", "SPMBuildCore", "PackageGraph", "LLBuildManifest", "SwiftDriver", "SPMLLBuild"]),
dependencies: [
"SwiftToolsSupport-auto",
"Basics",
"OrderedCollections",
"SPMBuildCore",
"PackageGraph",
"LLBuildManifest",
"SwiftDriver",
"SPMLLBuild",
]
),
.target(
/** Support for building using Xcode's build system */
name: "XCBuildSupport",
Expand Down Expand Up @@ -360,14 +385,16 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
// used by 'swift-driver' and 'sourcekit-lsp'. Please coordinate
// dependency version changes here with those projects.
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.4.3")),
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
.package(url: "https://github.com/apple/swift-collections.git", .exact("0.0.3")),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: "1.1.4")),
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
]
} else {
package.dependencies += [
.package(path: "../swift-tools-support-core"),
.package(path: "../swift-argument-parser"),
.package(path: "../swift-driver"),
.package(path: "../swift-collections"),
.package(path: "../swift-crypto"),
.package(path: "../swift-driver"),
]
}
7 changes: 4 additions & 3 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/

import Basics
import TSCBasic
import TSCUtility
import Foundation
import OrderedCollections
import PackageModel
import PackageGraph
import PackageLoading
import Foundation
import SPMBuildCore
@_implementationOnly import SwiftDriver
import TSCBasic
import TSCUtility

extension String {
fileprivate var asSwiftStringLiteralConstant: String {
Expand Down
1 change: 1 addition & 0 deletions Sources/Build/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ add_library(Build
target_link_libraries(Build PUBLIC
TSCBasic
Basics
OrderedCollections
PackageGraph
LLBuildManifest
SPMBuildCore
Expand Down
1 change: 1 addition & 0 deletions Sources/PackageGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_library(PackageGraph
target_link_libraries(PackageGraph PUBLIC
TSCBasic
Basics
OrderedCollections
PackageLoading
PackageModel
SourceControl
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageGraph/PackageGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import Basics
import OrderedCollections
import PackageLoading
import PackageModel
import SourceControl
Expand Down Expand Up @@ -612,7 +613,7 @@ fileprivate func findCycle(
_ successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
// If this node is already in the current path then we have found a cycle.
if !path.append(node.manifest) {
if !path.append(node.manifest).inserted {
let index = path.firstIndex(of: node.manifest)! // forced unwrap safe
return (Array(path[path.startIndex..<index]), Array(path[index..<path.endIndex]))
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/PackageGraph/Pubgrub/Incompatibility.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2019 Apple Inc. and the Swift project authors
Copyright (c) 2019 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Basics
import TSCBasic
import OrderedCollections
import PackageModel
import TSCBasic

/// A set of terms that are incompatible with each other and can therefore not
/// all be true at the same time. In dependency resolution, these are derived
Expand Down Expand Up @@ -43,7 +44,7 @@ public struct Incompatibility: Equatable, Hashable {
terms = OrderedSet(terms.filter { !$0.isPositive || $0.node != root })
}

let normalizedTerms = try normalize(terms: terms.contents)
let normalizedTerms = try normalize(terms: terms.elements)
assert(normalizedTerms.count > 0,
"An incompatibility must contain at least one term after normalization.")
self.init(terms: OrderedSet(normalizedTerms), cause: cause)
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageGraph/Pubgrub/PartialSolution.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2019 Apple Inc. and the Swift project authors
Copyright (c) 2019 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import Basics
import OrderedCollections
import TSCBasic
import struct TSCUtility.Version

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2019 Apple Inc. and the Swift project authors
Copyright (c) 2019 - 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
Expand All @@ -10,6 +10,7 @@

import Basics
import Dispatch
import OrderedCollections
import PackageModel
import TSCBasic
import TSCUtility
Expand Down
1 change: 1 addition & 0 deletions Sources/PackageLoading/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_library(PackageLoading
target_link_libraries(PackageLoading PUBLIC
TSCBasic
Basics
OrderedCollections
PackageModel
SourceControl
TSCUtility)
Expand Down
4 changes: 2 additions & 2 deletions Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import Basics
import Dispatch
import OrderedCollections
import PackageModel
import TSCBasic
import TSCUtility
Expand Down Expand Up @@ -1192,8 +1193,7 @@ public final class PackageBuilder {

/// Helper method to append to products array.
func append(_ product: Product) {
let inserted = products.append(KeyedPair(product, key: product.name))
if !inserted {
if !products.append(KeyedPair(product, key: product.name)).inserted {
diagnostics.emit(
.duplicateProduct(product: product),
location: self.diagnosticLocation
Expand Down
1 change: 1 addition & 0 deletions Tests/PackageGraphTests/PubgrubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import XCTest

import TSCBasic
import OrderedCollections
import PackageLoading
@testable import PackageModel
@testable import PackageGraph
Expand Down
Loading