Skip to content
Merged
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 @@ -54,6 +54,7 @@ if(FIND_PM_DEPS)
find_package(ArgumentParser CONFIG REQUIRED)
find_package(SwiftCrypto CONFIG REQUIRED)
find_package(SwiftDriver CONFIG REQUIRED)
find_package(SwiftCollections CONFIG REQUIRED)
endif()

find_package(dispatch QUIET)
Expand Down
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,21 @@ Clone the following repositories beside the SwiftPM directory:
$> git clone https://github.com/apple/swift-crypto --branch 1.1.6
```

76. [swift-system] and check out tag with the [latest version](https://github.com/apple/swift-system/tags).
7. [swift-system] and check out tag with the [latest version](https://github.com/apple/swift-system/tags).

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

8. [swift-collections] and check out tag with the [latest version](https://github.com/apple/swift-collections/tags).

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

[swift-argument-parser]: https://github.com/apple/swift-argument-parser
[swift-collections]: https://github.com/apple/swift-collections
[swift-crypto]: https://github.com/apple/swift-crypto
[swift-driver]: https://github.com/apple/swift-driver
[swift-llbuild]: https://github.com/apple/swift-llbuild
Expand Down
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ let package = Package(
.target(
name: "Basics",
dependencies: [
.product(name: "OrderedCollections", package: "swift-collections"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
.product(name: "SystemPackage", package: "swift-system"),
],
Expand Down Expand Up @@ -259,7 +260,7 @@ let package = Package(
],
exclude: ["CMakeLists.txt"]
),

.target(
name: "PackageFingerprint",
dependencies: [
Expand Down Expand Up @@ -576,6 +577,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(url: "https://github.com/apple/swift-driver.git", .branch(relatedDependenciesBranch)),
.package(url: "https://github.com/apple/swift-crypto.git", .upToNextMinor(from: minimumCryptoVersion)),
.package(url: "https://github.com/apple/swift-system.git", .upToNextMinor(from: "1.1.1")),
.package(url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.0.1")),
]
} else {
package.dependencies += [
Expand All @@ -584,5 +586,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(path: "../swift-driver"),
.package(path: "../swift-crypto"),
.package(path: "../swift-system"),
.package(path: "../swift-collections"),
]
}
1 change: 1 addition & 0 deletions Sources/Basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ add_library(Basics
SQLiteBackedCache.swift
Version+Extensions.swift)
target_link_libraries(Basics PUBLIC
SwiftCollections::OrderedCollections
SwiftSystem::SystemPackage
TSCBasic
TSCUtility)
Expand Down
3 changes: 2 additions & 1 deletion Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Basics
import Foundation
import LLBuildManifest
import OrderedCollections
import PackageGraph
import PackageLoading
import PackageModel
Expand Down Expand Up @@ -2058,7 +2059,7 @@ public class BuildPlan {
}

// Build cache
var cflagsCache: OrderedSet<String> = []
var cflagsCache: OrderedCollections.OrderedSet<String> = []
var libsCache: [String] = []
for tuple in ret {
for cFlag in tuple.cFlags {
Expand Down
9 changes: 5 additions & 4 deletions 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 TSCBasic
Expand All @@ -20,7 +21,7 @@ extension PackageGraph {
root: PackageGraphRoot,
identityResolver: IdentityResolver,
additionalFileRules: [FileRuleDescription] = [],
externalManifests: OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>,
externalManifests: OrderedCollections.OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>,
requiredDependencies: Set<PackageReference> = [],
unsafeAllowedPackages: Set<PackageReference> = [],
binaryArtifacts: [BinaryArtifact] = [],
Expand Down Expand Up @@ -247,7 +248,7 @@ private func createResolvedPackages(
metadata: package.diagnosticsMetadata
)

var dependencies = OrderedDictionary<PackageIdentity, ResolvedPackageBuilder>()
var dependencies = OrderedCollections.OrderedDictionary<PackageIdentity, ResolvedPackageBuilder>()
var dependenciesByNameForTargetDependencyResolution = [String: ResolvedPackageBuilder]()

// Establish the manifest-declared package dependencies.
Expand Down Expand Up @@ -647,7 +648,7 @@ fileprivate func findCycle(
successors: (GraphLoadingNode) throws -> [GraphLoadingNode]
) rethrows -> (path: [Manifest], cycle: [Manifest])? {
// Ordered set to hold the current traversed path.
var path = OrderedSet<Manifest>()
var path = OrderedCollections.OrderedSet<Manifest>()

// Function to visit nodes recursively.
// FIXME: Convert to stack.
Expand All @@ -656,7 +657,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
13 changes: 7 additions & 6 deletions Sources/PackageGraph/Pubgrub/Incompatibility.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,28 @@
*/

import Basics
import OrderedCollections
import TSCBasic
import PackageModel

/// 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
/// from version requirements and when running into unresolvable situations.
public struct Incompatibility: Equatable, Hashable {
public let terms: OrderedSet<Term>
public let terms: OrderedCollections.OrderedSet<Term>
public let cause: Cause

public init(terms: OrderedSet<Term>, cause: Cause) {
public init(terms: OrderedCollections.OrderedSet<Term>, cause: Cause) {
self.terms = terms
self.cause = cause
}

public init(_ terms: Term..., root: DependencyResolutionNode, cause: Cause = .root) throws {
let termSet = OrderedSet(terms)
let termSet = OrderedCollections.OrderedSet(terms)
try self.init(termSet, root: root, cause: cause)
}

public init(_ terms: OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
public init(_ terms: OrderedCollections.OrderedSet<Term>, root: DependencyResolutionNode, cause: Cause) throws {
if terms.isEmpty {
self.init(terms: terms, cause: cause)
return
Expand All @@ -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 Expand Up @@ -134,7 +135,7 @@ extension Incompatibility {
/// requirements to a^1.5.0.
fileprivate func normalize(terms: [Term]) throws -> [Term] {

let dict = try terms.reduce(into: OrderedDictionary<DependencyResolutionNode, (req: VersionSetSpecifier, polarity: Bool)>()) {
let dict = try terms.reduce(into: OrderedCollections.OrderedDictionary<DependencyResolutionNode, (req: VersionSetSpecifier, polarity: Bool)>()) {
res, term in
// Don't try to intersect if this is the first time we're seeing this package.
guard let previous = res[term.node] else {
Expand Down
3 changes: 2 additions & 1 deletion Sources/PackageGraph/Pubgrub/PartialSolution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import Basics
import OrderedCollections
import TSCBasic
import struct TSCUtility.Version

Expand All @@ -25,7 +26,7 @@ public struct PartialSolution {

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

/// Union of all negative assignments for a package.
///
Expand Down
11 changes: 6 additions & 5 deletions Sources/PackageGraph/Pubgrub/PubgrubDependencyResolver.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 @@ -264,7 +265,7 @@ public struct PubgrubDependencyResolver {
// The list of constraints that we'll be working with. We start with the input constraints
// and process them in two phases. The first phase finds all unversioned constraints and
// the second phase discovers all branch-based constraints.
var constraints = OrderedSet(constraints)
var constraints = OrderedCollections.OrderedSet(constraints)

// The list of packages that are overridden in the graph. A local package reference will
// always override any other kind of package reference and branch-based reference will override
Expand All @@ -274,7 +275,7 @@ public struct PubgrubDependencyResolver {
// The list of version-based references reachable via local and branch-based references.
// These are added as top-level incompatibilities since they always need to be satisfied.
// Some of these might be overridden as we discover local and branch-based references.
var versionBasedDependencies = OrderedDictionary<DependencyResolutionNode, [VersionBasedConstraint]>()
var versionBasedDependencies = OrderedCollections.OrderedDictionary<DependencyResolutionNode, [VersionBasedConstraint]>()

// Process unversioned constraints in first phase. We go through all of the unversioned packages
// and collect them and their dependencies. This gives us the complete list of unversioned
Expand Down Expand Up @@ -452,7 +453,7 @@ public struct PubgrubDependencyResolver {
/// If a conflict is found, the conflicting incompatibility is returned to
/// resolve the conflict on.
internal func propagate(state: State, node: DependencyResolutionNode) throws {
var changed: OrderedSet<DependencyResolutionNode> = [node]
var changed: OrderedCollections.OrderedSet<DependencyResolutionNode> = [node]

while !changed.isEmpty {
let package = changed.removeFirst()
Expand Down Expand Up @@ -577,7 +578,7 @@ public struct PubgrubDependencyResolver {
}

incompatibility = try Incompatibility(
OrderedSet(newTerms),
OrderedCollections.OrderedSet(newTerms),
root: state.root,
cause: .conflict(cause: .init(conflict: incompatibility, other: priorCause))
)
Expand Down Expand Up @@ -1211,7 +1212,7 @@ internal final class PubGrubPackageContainer {
return nil
}

var terms: OrderedSet<Term> = []
var terms: OrderedCollections.OrderedSet<Term> = []
// the package version requirement
terms.append(Term(node, .exact(version)))
// the dependency's version requirement
Expand Down
5 changes: 3 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

Expand Down Expand Up @@ -1156,11 +1157,11 @@ public final class PackageBuilder {

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

/// Helper method to append to products array.
func append(_ product: Product) {
let inserted = products.append(KeyedPair(product, key: product.name))
let inserted = products.append(KeyedPair(product, key: product.name)).inserted
if !inserted {
self.observabilityScope.emit(.duplicateProduct(product: product))
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SPMTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import Basics
import OrderedCollections
import PackageGraph
import PackageLoading
import PackageModel
Expand Down Expand Up @@ -229,7 +230,7 @@ public func loadPackageGraph(
observabilityScope: ObservabilityScope
) throws -> PackageGraph {
let rootManifests = manifests.filter { $0.packageKind.isRoot }.spm_createDictionary{ ($0.path, $0) }
let externalManifests = try manifests.filter { !$0.packageKind.isRoot }.reduce(into: OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>()) { partial, item in
let externalManifests = try manifests.filter { !$0.packageKind.isRoot }.reduce(into: OrderedCollections.OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>()) { partial, item in
partial[try identityResolver.resolveIdentity(for: item.packageKind)] = (item, fs)
}

Expand Down
9 changes: 5 additions & 4 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
*/

import Basics
import TSCBasic
import TSCUtility
import Foundation
import OrderedCollections
import PackageLoading
import PackageModel
import PackageFingerprint
import PackageGraph
import PackageRegistry
import SourceControl
import TSCBasic
import TSCUtility

public typealias Diagnostic = TSCBasic.Diagnostic

Expand Down Expand Up @@ -1709,8 +1710,8 @@ extension Workspace {
}

/// Returns all manifests contained in DependencyManifests.
public func allDependencyManifests() -> OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)> {
return self.dependencies.reduce(into: OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>()) { partial, item in
public func allDependencyManifests() -> OrderedCollections.OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)> {
return self.dependencies.reduce(into: OrderedCollections.OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>()) { partial, item in
partial[item.dependency.packageRef.identity] = (item.manifest, item.fileSystem)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import Basics
import OrderedCollections
import PackageGraph
import PackageLoading
import PackageModel
Expand All @@ -25,7 +26,7 @@ class PackageGraphPerfTests: XCTestCasePerf {
let fs = InMemoryFileSystem(emptyFiles: files)

let identityResolver = DefaultIdentityResolver()
var externalManifests = OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>()
var externalManifests = OrderedCollections.OrderedDictionary<PackageIdentity, (manifest: Manifest, fs: FileSystem)>()
var rootManifest: Manifest!
for pkg in 1...N {
let name = "Foo\(pkg)"
Expand Down
13 changes: 7 additions & 6 deletions Tests/PackageGraphTests/PubgrubTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

import Basics
import OrderedCollections
@testable import PackageGraph
import PackageLoading
@testable import PackageModel
Expand Down Expand Up @@ -2800,17 +2801,17 @@ class DependencyGraphBuilder {
}

func create(
dependencies: OrderedDictionary<String, (PackageRequirement, ProductFilter)>
dependencies: OrderedCollections.OrderedDictionary<String, (PackageRequirement, ProductFilter)>
) -> [PackageContainerConstraint] {
var refDependencies = OrderedDictionary<PackageReference, (PackageRequirement, ProductFilter)>()
var refDependencies = OrderedCollections.OrderedDictionary<PackageReference, (PackageRequirement, ProductFilter)>()
for dependency in dependencies {
refDependencies[reference(for: dependency.key)] = dependency.value
}
return self.create(dependencies: refDependencies)
}

func create(
dependencies: OrderedDictionary<PackageReference, (PackageRequirement, ProductFilter)>
dependencies: OrderedCollections.OrderedDictionary<PackageReference, (PackageRequirement, ProductFilter)>
) -> [PackageContainerConstraint] {
return dependencies.map {
PackageContainerConstraint(package: $0, requirement: $1.0, products: $1.1)
Expand All @@ -2821,7 +2822,7 @@ class DependencyGraphBuilder {
_ package: String,
at version: Version,
toolsVersion: ToolsVersion? = nil,
with dependencies: KeyValuePairs<String, OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
with dependencies: KeyValuePairs<String, OrderedCollections.OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
) {
self.serve(package, at: .version(version), toolsVersion: toolsVersion, with: dependencies)
}
Expand All @@ -2830,7 +2831,7 @@ class DependencyGraphBuilder {
_ package: String,
at version: BoundVersion,
toolsVersion: ToolsVersion? = nil,
with dependencies: KeyValuePairs<String, OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
with dependencies: KeyValuePairs<String, OrderedCollections.OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
) {
let packageReference = reference(for: package)
self.serve(
Expand All @@ -2845,7 +2846,7 @@ class DependencyGraphBuilder {
_ packageReference: PackageReference,
at version: BoundVersion,
toolsVersion: ToolsVersion? = nil,
with dependencies: KeyValuePairs<String, OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
with dependencies: KeyValuePairs<String, OrderedCollections.OrderedDictionary<String, (PackageRequirement, ProductFilter)>> = [:]
) {
let container = self.containers[packageReference.identity.description] ?? MockContainer(package: packageReference)

Expand Down
Loading