Skip to content

Commit e26d07b

Browse files
authored
refactor workspace repository handling (#3766)
motivation: make supporting registry depedencies easier changes: * rename LocalPackageContainer to FileSystemPackageContainer and move it to workspace module as internal struct * rename RepositoryPackageContainer to SourceControlPackageContainer and move it to the workspace module as internal class * remove RepositoryPackageContainerProvider and move its logic to workspace itself, including the logic to switch over dependecy type (local/remote) and providing the correct container type * conform workspace to PackageContainerProvider and change getContiner call-sites to use it * reorgnize repository related methods in a consistent manner so its easier to read the code that deals with repositories * adjust call sites and tests rdar://81621441
1 parent 7d165d1 commit e26d07b

31 files changed

+586
-586
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ let package = Package(
161161
/** Primitive Package model objects */
162162
name: "PackageModel",
163163
dependencies: ["SwiftToolsSupport-auto", "Basics"]),
164+
164165
.target(
165166
/** Package model conventions and loading support */
166167
name: "PackageLoading",

Sources/PackageGraph/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ add_library(PackageGraph
1414
DependencyResolver.swift
1515
Diagnostics.swift
1616
GraphLoadingNode.swift
17-
LocalPackageContainer.swift
1817
PackageContainer.swift
1918
PackageGraph.swift
2019
PackageGraph+Loading.swift
@@ -27,7 +26,6 @@ add_library(PackageGraph
2726
Pubgrub/PartialSolution.swift
2827
Pubgrub/PubgrubDependencyResolver.swift
2928
Pubgrub/Term.swift
30-
RepositoryPackageContainer.swift
3129
ResolvedPackage.swift
3230
ResolvedProduct.swift
3331
ResolvedTarget.swift

Sources/PackageGraph/CheckoutState.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCBasic
12-
import SourceControl
13-
import TSCUtility
11+
import struct SourceControl.Revision // FIXME: remove this dependency
12+
import struct TSCUtility.Version
1413

1514
/// A checkout state represents the current state of a repository.
1615
///

Sources/PackageGraph/DependencyMirrors.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
*/
1010

1111
import Foundation
12-
1312
import TSCBasic
14-
import TSCUtility
1513

1614
/// A collection of dependency mirrors.
1715
public final class DependencyMirrors: Equatable {

Sources/PackageGraph/GraphLoadingNode.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCBasic
1211
import PackageLoading
1312
import PackageModel
14-
import TSCUtility
13+
import TSCBasic
1514

1615
/// A node used while loading the packages in a resolved graph.
1716
///

Sources/PackageGraph/PackageContainer.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
*/
1010

1111
import Dispatch
12-
import PackageLoading
1312
import PackageModel
14-
import SourceControl
1513
import struct TSCUtility.Version
1614

1715
/// A container of packages.
@@ -104,7 +102,7 @@ extension PackageContainer {
104102
}
105103
}
106104

107-
// MARK: -
105+
// MARK: - PackageContainerConstraint
108106

109107
/// An individual constraint onto a container.
110108
public struct PackageContainerConstraint: Equatable, Hashable {
@@ -139,7 +137,7 @@ extension PackageContainerConstraint: CustomStringConvertible {
139137
}
140138
}
141139

142-
// MARK: -
140+
// MARK: - PackageContainerProvider
143141

144142
/// An interface for resolving package containers.
145143
public protocol PackageContainerProvider {

Sources/PackageGraph/PackageGraph+Loading.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
import Basics
1212
import PackageLoading
1313
import PackageModel
14-
import SourceControl
1514
import TSCBasic
16-
import TSCUtility
1715

1816
extension PackageGraph {
1917

Sources/PackageGraph/PackageGraph.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCBasic
1211
import PackageModel
12+
import TSCBasic
1313

1414
enum PackageGraphError: Swift.Error {
1515
/// Indicates a non-root package with no targets.

Sources/PackageGraph/PackageGraphRoot.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010

1111
import Basics
1212
import PackageModel
13-
import SourceControl
1413
import TSCBasic
15-
import TSCUtility
14+
import enum TSCUtility.Git
1615

1716
/// Represents the input to the package graph root.
1817
public struct PackageGraphRootInput {

Sources/PackageGraph/PackageModel+Extensions.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
*/
1010

1111
import PackageModel
12-
import SourceControl
1312

1413
extension PackageDependency {
1514
/// Create the package reference object for the dependency.

Sources/PackageGraph/PinsStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Basics
1212
import Foundation
1313
import PackageModel
14-
import SourceControl
14+
import struct SourceControl.Revision // FIXME: remove this dependency
1515
import TSCBasic
1616

1717
public final class PinsStore {

Sources/PackageGraph/Version+Extensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCUtility
11+
import struct TSCUtility.Version
1212

1313
extension Version {
1414
func nextPatch() -> Version {

Sources/PackageGraph/VersionSetSpecifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import TSCUtility
11+
import struct TSCUtility.Version
1212

1313
/// An abstract definition for a set of versions.
1414
public enum VersionSetSpecifier: Hashable {

Sources/PackageLoading/Diagnostics.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import Basics
1212
import PackageModel
1313
import TSCBasic
14-
import TSCUtility
1514

1615
extension Basics.Diagnostic {
1716
static func targetHasNoSources(targetPath: String, target: String) -> Self {

Sources/PackageLoading/IdentityResolver.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public struct DefaultIdentityResolver: IdentityResolver {
4747
return try self.resolveIdentity(for: path)
4848
case .remoteSourceControl(let url):
4949
return try self.resolveIdentity(for: url)
50+
case .registry(let identity):
51+
return identity
5052
}
5153
}
5254

Sources/PackageLoading/ManifestJSONParser.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import Basics
1212
import Foundation
1313
import PackageModel
14-
import SourceControl
14+
import SourceControl // FIXME: remove this dependency
1515
import TSCBasic
1616
import TSCUtility
1717

@@ -233,6 +233,9 @@ enum ManifestJSONParser {
233233
case .remoteSourceControl:
234234
// nothing to fix
235235
return dependencyLocation
236+
case .registry:
237+
// nothing to fix
238+
return dependencyLocation
236239
}
237240

238241
if dependencyLocation.hasPrefix("~/") {

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
*/
1010

1111
import Basics
12-
import TSCBasic
13-
import PackageModel
14-
import TSCUtility
1512
import Foundation
16-
public typealias FileSystem = TSCBasic.FileSystem
13+
import PackageModel
14+
import TSCBasic
15+
import struct TSCUtility.Triple
16+
import enum TSCUtility.Diagnostics
17+
import var TSCUtility.verbosity
1718

1819
public enum ManifestParseError: Swift.Error, Equatable {
1920
/// The manifest contains invalid format.

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Basics
1212
import Dispatch
1313
import PackageModel
1414
import TSCBasic
15-
import TSCUtility
1615

1716
/// An error in the structure or layout of a package.
1817
public enum ModuleError: Swift.Error {

Sources/PackageLoading/Target+PkgConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
import Basics
12-
import TSCBasic
1312
import PackageModel
13+
import TSCBasic
1414
import TSCUtility
1515

1616
/// Wrapper struct containing result of a pkgConfig query.

Sources/PackageLoading/TargetSourcesBuilder.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Basics
1212
import Foundation
1313
import PackageModel
1414
import TSCBasic
15-
import TSCUtility
1615

1716
/// A utility to compute the source/resource files of a target.
1817
public struct TargetSourcesBuilder {

Sources/PackageLoading/ToolsVersionLoader.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import Basics
1212
import Foundation
1313
import PackageModel
1414
import TSCBasic
15-
import TSCUtility
1615

1716
/// Protocol for the manifest loader interface.
1817
public protocol ToolsVersionLoaderProtocol {

Sources/PackageModel/PackageReference.swift

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
See http://swift.org/LICENSE.txt for license information
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9-
*/
9+
*/
1010

1111
import Basics
1212
import Foundation
@@ -16,7 +16,7 @@ import TSCUtility
1616
/// A package reference.
1717
///
1818
/// This represents a reference to a package containing its identity and location.
19-
public struct PackageReference: Encodable {
19+
public struct PackageReference {
2020
/// The kind of package reference.
2121
public enum Kind: Equatable {
2222
/// A root package.
@@ -31,6 +31,9 @@ public struct PackageReference: Encodable {
3131
/// A remote source package.
3232
case remoteSourceControl(Foundation.URL)
3333

34+
/// A package from a registry.
35+
case registry(PackageIdentity)
36+
3437
// FIXME: we should not need this
3538
//@available(*, deprecated)
3639
public var locationString: String {
@@ -43,6 +46,9 @@ public struct PackageReference: Encodable {
4346
return path.pathString
4447
case .remoteSourceControl(let url):
4548
return url.absoluteString
49+
case .registry(let identity):
50+
// FIXME: this is a placeholder
51+
return identity.description
4652
}
4753
}
4854

@@ -75,7 +81,7 @@ public struct PackageReference: Encodable {
7581
/// The kind of package: root, local, or remote.
7682
public let kind: Kind
7783

78-
/// Create a package reference given its identity and repository.
84+
/// Create a package reference given its identity and kind.
7985
public init(identity: PackageIdentity, kind: Kind, name: String? = nil) {
8086
self.identity = identity
8187
self.kind = kind
@@ -88,6 +94,9 @@ public struct PackageReference: Encodable {
8894
self.name = name ?? LegacyPackageIdentity.computeDefaultName(fromPath: path)
8995
case .remoteSourceControl(let url):
9096
self.name = name ?? LegacyPackageIdentity.computeDefaultName(fromURL: url)
97+
case .registry(let identity):
98+
// FIXME: this is a placeholder
99+
self.name = name ?? identity.description
91100
}
92101
}
93102

@@ -104,14 +113,17 @@ public struct PackageReference: Encodable {
104113
PackageReference(identity: identity, kind: .fileSystem(path))
105114
}
106115

107-
108116
public static func localSourceControl(identity: PackageIdentity, path: AbsolutePath) -> PackageReference {
109117
PackageReference(identity: identity, kind: .localSourceControl(path))
110118
}
111119

112120
public static func remoteSourceControl(identity: PackageIdentity, url: Foundation.URL) -> PackageReference {
113121
PackageReference(identity: identity, kind: .remoteSourceControl(url))
114122
}
123+
124+
public static func registry(identity: PackageIdentity) -> PackageReference {
125+
PackageReference(identity: identity, kind: .registry(identity))
126+
}
115127
}
116128

117129
extension PackageReference: Equatable {
@@ -136,7 +148,7 @@ extension PackageReference: CustomStringConvertible {
136148

137149
extension PackageReference.Kind: Encodable {
138150
private enum CodingKeys: String, CodingKey {
139-
case root, fileSystem, localSourceControl, remoteSourceControl
151+
case root, fileSystem, localSourceControl, remoteSourceControl, registry
140152
}
141153

142154
public func encode(to encoder: Encoder) throws {
@@ -154,6 +166,9 @@ extension PackageReference.Kind: Encodable {
154166
case .remoteSourceControl(let url):
155167
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .remoteSourceControl)
156168
try unkeyedContainer.encode(url)
169+
case .registry:
170+
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .registry)
171+
try unkeyedContainer.encode(self.isRoot)
157172
}
158173
}
159174
}

Sources/SPMTestSupport/MockManifestLoader.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
99
*/
1010

11-
import func XCTest.XCTFail
12-
import Dispatch
13-
1411
import Basics
15-
import TSCBasic
12+
import Dispatch
1613
import PackageModel
1714
import PackageLoading
1815
import PackageGraph
16+
import TSCBasic
1917
import TSCUtility
18+
import func XCTest.XCTFail
2019

2120
public enum MockManifestLoaderError: Swift.Error {
2221
case unknownRequest(String)
@@ -82,7 +81,7 @@ extension ManifestLoader {
8281
packageKind: PackageModel.PackageReference.Kind,
8382
toolsVersion: PackageModel.ToolsVersion,
8483
identityResolver: IdentityResolver = DefaultIdentityResolver(),
85-
fileSystem: PackageLoading.FileSystem,
84+
fileSystem: TSCBasic.FileSystem,
8685
diagnostics: TSCBasic.DiagnosticsEngine? = nil
8786
) throws -> Manifest{
8887
let packageIdentity: PackageIdentity
@@ -100,6 +99,10 @@ extension ManifestLoader {
10099
case .remoteSourceControl(let url):
101100
packageIdentity = try identityResolver.resolveIdentity(for: url)
102101
packageLocation = url.absoluteString
102+
case .registry(let identity):
103+
packageIdentity = identity
104+
// FIXME: placeholder
105+
packageLocation = identity.description
103106
}
104107
return try tsc_await {
105108
self.load(at: path,

Sources/SPMTestSupport/MockWorkspace.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ extension PackageReference.Kind {
777777
return "localSourceControl"
778778
case .remoteSourceControl:
779779
return "remoteSourceControl"
780+
case .registry:
781+
return "registry"
780782
}
781783
}
782784
}

Sources/Workspace/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ add_library(Workspace
1010
DefaultPluginScriptRunner.swift
1111
Destination.swift
1212
Diagnostics.swift
13+
FileSystemPackageContainer.swift
1314
InitPackage.swift
1415
ManagedArtifact.swift
1516
ManagedDependency.swift
1617
ResolvedFileWatcher.swift
1718
ResolverPrecomputationProvider.swift
19+
SourceControlPackageContainer.swift
1820
ToolsVersionSpecificationRewriter.swift
1921
UserToolchain.swift
2022
Workspace.swift

0 commit comments

Comments
 (0)