1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2017 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 the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Basics
import struct Foundation.URL
import enum TSCUtility.PackageLocation
import struct TSCUtility.Version
/// The basic package representation.
///
/// The package manager conceptually works with five different kinds of
/// packages, of which this is only one:
///
/// 1. Informally, the repository containing a package can be thought of in some
/// sense as the "package". However, this isn't accurate, because the actual
/// Package is derived from its manifest, a Package only actually exists at a
/// particular repository revision (typically a tag). We also may eventually
/// want to support multiple packages within a single repository.
///
/// 2. The `PackageDescription.Package` as defined inside a manifest is a
/// declarative specification for (part of) the package but not the object that
/// the package manager itself is typically working with internally. Rather,
/// that specification is primarily used to load the package (see the
/// `PackageLoading` target).
///
/// 3. A loaded `PackageModel.Manifest` is an abstract representation of a
/// package, and is used during package dependency resolution. It contains the
/// loaded PackageDescription and information necessary for dependency
/// resolution, but nothing else.
///
/// 4. A loaded `PackageModel.Package` which has had dependencies loaded and
/// resolved. This is the result after `Get.get()`.
///
/// 5. A loaded package, as in #4, for which the targets have also been
/// loaded. There is not currently a data structure for this, but it is the
/// result after `PackageLoading.transmute()`.
public final class Package {
/// The identity of the package.
public let identity: PackageIdentity
/// The manifest describing the package.
public let manifest: Manifest
/// The local path of the package.
public let path: AbsolutePath
/// The targets contained in the package.
public var modules: [Module]
/// The products produced by the package.
public let products: [Product]
// The directory containing the targets which did not explicitly specify
// their path. If all targets are explicit, this is the preferred path for
// future targets.
public let targetSearchPath: AbsolutePath
// The directory containing the test targets which did not explicitly specify
// their path. If all test targets are explicit, this is the preferred path
// for future test targets.
public let testTargetSearchPath: AbsolutePath
public init(
identity: PackageIdentity,
manifest: Manifest,
path: AbsolutePath,
targets: [Module],
products: [Product],
targetSearchPath: AbsolutePath,
testTargetSearchPath: AbsolutePath
) {
self.identity = identity
self.manifest = manifest
self.path = path
self.modules = targets
self.products = products
self.targetSearchPath = targetSearchPath
self.testTargetSearchPath = testTargetSearchPath
}
public enum Error: Swift.Error, Equatable {
case noManifest(at: AbsolutePath, version: Version?)
}
}
extension Package: Hashable {
public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
}
public static func == (lhs: Package, rhs: Package) -> Bool {
ObjectIdentifier(lhs) == ObjectIdentifier(rhs)
}
}
extension Package {
public var diagnosticsMetadata: ObservabilityMetadata {
return .packageMetadata(identity: self.identity, kind: self.manifest.packageKind)
}
}
extension Package: CustomStringConvertible {
public var description: String {
return self.identity.description
}
}
extension Package.Error: CustomStringConvertible {
public var description: String {
switch self {
case .noManifest(let path, let version):
var string = "\(path) has no Package.swift manifest"
if let version {
string += " for version \(version)"
}
return string
}
}
}
extension Manifest {
public var disambiguateByProductIDs: Bool {
return self.toolsVersion >= .v5_8
}
public var usePackageNameFlag: Bool {
return self.toolsVersion >= .v5_9
}
}
extension ObservabilityMetadata {
public static func packageMetadata(identity: PackageIdentity, kind: PackageReference.Kind) -> Self {
var metadata = ObservabilityMetadata()
metadata.packageIdentity = identity
metadata.packageKind = kind
return metadata
}
}
extension ObservabilityMetadata {
public var packageIdentity: PackageIdentity? {
get {
self[PackageIdentityKey.self]
}
set {
self[PackageIdentityKey.self] = newValue
}
}
enum PackageIdentityKey: Key {
typealias Value = PackageIdentity
}
}
/*
extension ObservabilityMetadata {
public var packageLocation: String? {
get {
self[PackageLocationKey.self]
}
set {
self[PackageLocationKey.self] = newValue
}
}
enum PackageLocationKey: Key {
typealias Value = String
}
}*/
extension ObservabilityMetadata {
public var packageKind: PackageReference.Kind? {
get {
self[PackageKindKey.self]
}
set {
self[PackageKindKey.self] = newValue
}
}
enum PackageKindKey: Key {
typealias Value = PackageReference.Kind
}
}
|