Skip to content

refactor workspace repository handling #3766

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

Merged
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 Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ let package = Package(
/** Primitive Package model objects */
name: "PackageModel",
dependencies: ["SwiftToolsSupport-auto", "Basics"]),

.target(
/** Package model conventions and loading support */
name: "PackageLoading",
Expand Down
2 changes: 0 additions & 2 deletions Sources/PackageGraph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ add_library(PackageGraph
DependencyResolver.swift
Diagnostics.swift
GraphLoadingNode.swift
LocalPackageContainer.swift
PackageContainer.swift
PackageGraph.swift
PackageGraph+Loading.swift
Expand All @@ -27,7 +26,6 @@ add_library(PackageGraph
Pubgrub/PartialSolution.swift
Pubgrub/PubgrubDependencyResolver.swift
Pubgrub/Term.swift
RepositoryPackageContainer.swift
ResolvedPackage.swift
ResolvedProduct.swift
ResolvedTarget.swift
Expand Down
5 changes: 2 additions & 3 deletions Sources/PackageGraph/CheckoutState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCBasic
import SourceControl
import TSCUtility
import struct SourceControl.Revision // FIXME: remove this dependency
import struct TSCUtility.Version

/// A checkout state represents the current state of a repository.
///
Expand Down
2 changes: 0 additions & 2 deletions Sources/PackageGraph/DependencyMirrors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/

import Foundation

import TSCBasic
import TSCUtility

/// A collection of dependency mirrors.
public final class DependencyMirrors: Equatable {
Expand Down
3 changes: 1 addition & 2 deletions Sources/PackageGraph/GraphLoadingNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCBasic
import PackageLoading
import PackageModel
import TSCUtility
import TSCBasic

/// A node used while loading the packages in a resolved graph.
///
Expand Down
6 changes: 2 additions & 4 deletions Sources/PackageGraph/PackageContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
*/

import Dispatch
import PackageLoading
import PackageModel
import SourceControl
import struct TSCUtility.Version

/// A container of packages.
Expand Down Expand Up @@ -104,7 +102,7 @@ extension PackageContainer {
}
}

// MARK: -
// MARK: - PackageContainerConstraint

/// An individual constraint onto a container.
public struct PackageContainerConstraint: Equatable, Hashable {
Expand Down Expand Up @@ -139,7 +137,7 @@ extension PackageContainerConstraint: CustomStringConvertible {
}
}

// MARK: -
// MARK: - PackageContainerProvider

/// An interface for resolving package containers.
public protocol PackageContainerProvider {
Expand Down
2 changes: 0 additions & 2 deletions Sources/PackageGraph/PackageGraph+Loading.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import Basics
import PackageLoading
import PackageModel
import SourceControl
import TSCBasic
import TSCUtility

extension PackageGraph {

Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/PackageGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCBasic
import PackageModel
import TSCBasic

enum PackageGraphError: Swift.Error {
/// Indicates a non-root package with no targets.
Expand Down
3 changes: 1 addition & 2 deletions Sources/PackageGraph/PackageGraphRoot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

import Basics
import PackageModel
import SourceControl
import TSCBasic
import TSCUtility
import enum TSCUtility.Git

/// Represents the input to the package graph root.
public struct PackageGraphRootInput {
Expand Down
1 change: 0 additions & 1 deletion Sources/PackageGraph/PackageModel+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/

import PackageModel
import SourceControl

extension PackageDependency {
/// Create the package reference object for the dependency.
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/PinsStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Basics
import Foundation
import PackageModel
import SourceControl
import struct SourceControl.Revision // FIXME: remove this dependency
import TSCBasic

public final class PinsStore {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/Version+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCUtility
import struct TSCUtility.Version

extension Version {
func nextPatch() -> Version {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/VersionSetSpecifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCUtility
import struct TSCUtility.Version

/// An abstract definition for a set of versions.
public enum VersionSetSpecifier: Hashable {
Expand Down
1 change: 0 additions & 1 deletion Sources/PackageLoading/Diagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import Basics
import PackageModel
import TSCBasic
import TSCUtility

extension Basics.Diagnostic {
static func targetHasNoSources(targetPath: String, target: String) -> Self {
Expand Down
2 changes: 2 additions & 0 deletions Sources/PackageLoading/IdentityResolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public struct DefaultIdentityResolver: IdentityResolver {
return try self.resolveIdentity(for: path)
case .remoteSourceControl(let url):
return try self.resolveIdentity(for: url)
case .registry(let identity):
return identity
}
}

Expand Down
5 changes: 4 additions & 1 deletion Sources/PackageLoading/ManifestJSONParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import Basics
import Foundation
import PackageModel
import SourceControl
import SourceControl // FIXME: remove this dependency
import TSCBasic
import TSCUtility

Expand Down Expand Up @@ -233,6 +233,9 @@ enum ManifestJSONParser {
case .remoteSourceControl:
// nothing to fix
return dependencyLocation
case .registry:
// nothing to fix
return dependencyLocation
}

if dependencyLocation.hasPrefix("~/") {
Expand Down
9 changes: 5 additions & 4 deletions Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
*/

import Basics
import TSCBasic
import PackageModel
import TSCUtility
import Foundation
public typealias FileSystem = TSCBasic.FileSystem
import PackageModel
import TSCBasic
import struct TSCUtility.Triple
import enum TSCUtility.Diagnostics
import var TSCUtility.verbosity

public enum ManifestParseError: Swift.Error, Equatable {
/// The manifest contains invalid format.
Expand Down
1 change: 0 additions & 1 deletion Sources/PackageLoading/PackageBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Basics
import Dispatch
import PackageModel
import TSCBasic
import TSCUtility

/// An error in the structure or layout of a package.
public enum ModuleError: Swift.Error {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageLoading/Target+PkgConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/

import Basics
import TSCBasic
import PackageModel
import TSCBasic
import TSCUtility

/// Wrapper struct containing result of a pkgConfig query.
Expand Down
1 change: 0 additions & 1 deletion Sources/PackageLoading/TargetSourcesBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Basics
import Foundation
import PackageModel
import TSCBasic
import TSCUtility

/// A utility to compute the source/resource files of a target.
public struct TargetSourcesBuilder {
Expand Down
1 change: 0 additions & 1 deletion Sources/PackageLoading/ToolsVersionLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Basics
import Foundation
import PackageModel
import TSCBasic
import TSCUtility

/// Protocol for the manifest loader interface.
public protocol ToolsVersionLoaderProtocol {
Expand Down
25 changes: 20 additions & 5 deletions Sources/PackageModel/PackageReference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

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

import Basics
import Foundation
Expand All @@ -16,7 +16,7 @@ import TSCUtility
/// A package reference.
///
/// This represents a reference to a package containing its identity and location.
public struct PackageReference: Encodable {
public struct PackageReference {
/// The kind of package reference.
public enum Kind: Equatable {
/// A root package.
Expand All @@ -31,6 +31,9 @@ public struct PackageReference: Encodable {
/// A remote source package.
case remoteSourceControl(Foundation.URL)

/// A package from a registry.
case registry(PackageIdentity)

// FIXME: we should not need this
//@available(*, deprecated)
public var locationString: String {
Expand All @@ -43,6 +46,9 @@ public struct PackageReference: Encodable {
return path.pathString
case .remoteSourceControl(let url):
return url.absoluteString
case .registry(let identity):
// FIXME: this is a placeholder
return identity.description
}
}

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

/// Create a package reference given its identity and repository.
/// Create a package reference given its identity and kind.
public init(identity: PackageIdentity, kind: Kind, name: String? = nil) {
self.identity = identity
self.kind = kind
Expand All @@ -88,6 +94,9 @@ public struct PackageReference: Encodable {
self.name = name ?? LegacyPackageIdentity.computeDefaultName(fromPath: path)
case .remoteSourceControl(let url):
self.name = name ?? LegacyPackageIdentity.computeDefaultName(fromURL: url)
case .registry(let identity):
// FIXME: this is a placeholder
self.name = name ?? identity.description
}
}

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


public static func localSourceControl(identity: PackageIdentity, path: AbsolutePath) -> PackageReference {
PackageReference(identity: identity, kind: .localSourceControl(path))
}

public static func remoteSourceControl(identity: PackageIdentity, url: Foundation.URL) -> PackageReference {
PackageReference(identity: identity, kind: .remoteSourceControl(url))
}

public static func registry(identity: PackageIdentity) -> PackageReference {
PackageReference(identity: identity, kind: .registry(identity))
}
}

extension PackageReference: Equatable {
Expand All @@ -136,7 +148,7 @@ extension PackageReference: CustomStringConvertible {

extension PackageReference.Kind: Encodable {
private enum CodingKeys: String, CodingKey {
case root, fileSystem, localSourceControl, remoteSourceControl
case root, fileSystem, localSourceControl, remoteSourceControl, registry
}

public func encode(to encoder: Encoder) throws {
Expand All @@ -154,6 +166,9 @@ extension PackageReference.Kind: Encodable {
case .remoteSourceControl(let url):
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .remoteSourceControl)
try unkeyedContainer.encode(url)
case .registry:
var unkeyedContainer = container.nestedUnkeyedContainer(forKey: .registry)
try unkeyedContainer.encode(self.isRoot)
}
}
}
13 changes: 8 additions & 5 deletions Sources/SPMTestSupport/MockManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import func XCTest.XCTFail
import Dispatch

import Basics
import TSCBasic
import Dispatch
import PackageModel
import PackageLoading
import PackageGraph
import TSCBasic
import TSCUtility
import func XCTest.XCTFail

public enum MockManifestLoaderError: Swift.Error {
case unknownRequest(String)
Expand Down Expand Up @@ -82,7 +81,7 @@ extension ManifestLoader {
packageKind: PackageModel.PackageReference.Kind,
toolsVersion: PackageModel.ToolsVersion,
identityResolver: IdentityResolver = DefaultIdentityResolver(),
fileSystem: PackageLoading.FileSystem,
fileSystem: TSCBasic.FileSystem,
diagnostics: TSCBasic.DiagnosticsEngine? = nil
) throws -> Manifest{
let packageIdentity: PackageIdentity
Expand All @@ -100,6 +99,10 @@ extension ManifestLoader {
case .remoteSourceControl(let url):
packageIdentity = try identityResolver.resolveIdentity(for: url)
packageLocation = url.absoluteString
case .registry(let identity):
packageIdentity = identity
// FIXME: placeholder
packageLocation = identity.description
}
return try tsc_await {
self.load(at: path,
Expand Down
2 changes: 2 additions & 0 deletions Sources/SPMTestSupport/MockWorkspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ extension PackageReference.Kind {
return "localSourceControl"
case .remoteSourceControl:
return "remoteSourceControl"
case .registry:
return "registry"
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/Workspace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ add_library(Workspace
DefaultPluginScriptRunner.swift
Destination.swift
Diagnostics.swift
FileSystemPackageContainer.swift
InitPackage.swift
ManagedArtifact.swift
ManagedDependency.swift
ResolvedFileWatcher.swift
ResolverPrecomputationProvider.swift
SourceControlPackageContainer.swift
ToolsVersionSpecificationRewriter.swift
UserToolchain.swift
Workspace.swift
Expand Down
Loading