@@ -47,14 +47,39 @@ public struct PackageGraphRoot {
47
47
}
48
48
49
49
/// The top level dependencies.
50
- public let dependencies : [ PackageDependency ]
50
+ private let _dependencies : [ PackageDependency ]
51
+
52
+ public var dependencies : [ PackageDependency ] {
53
+ guard let mirrors = mirrors else {
54
+ return self . _dependencies
55
+ }
56
+
57
+ return self . _dependencies. map {
58
+ switch $0 {
59
+ case . fileSystem: return $0
60
+ case . registry: return $0
61
+ case . sourceControl( let settings) :
62
+ let mappedLocation : PackageDependency . SourceControl . Location
63
+ switch settings. location {
64
+ case . local:
65
+ mappedLocation = settings. location
66
+ case . remote( let url) :
67
+ let effectiveLocation = mirrors. effective ( for: url. absoluteString)
68
+ mappedLocation = . remote( SourceControlURL ( effectiveLocation) )
69
+ }
70
+ return . sourceControl( identity: settings. identity, nameForTargetDependencyResolutionOnly: settings. nameForTargetDependencyResolutionOnly, location: mappedLocation, requirement: settings. requirement, productFilter: settings. productFilter)
71
+ }
72
+ }
73
+ }
74
+
75
+ private let mirrors : DependencyMirrors ?
51
76
52
77
/// Create a package graph root.
53
78
/// Note this quietly skip inputs for which manifests are not found. this could be because the manifest failed to load or for some other reasons
54
79
// FIXME: This API behavior wrt to non-found manifests is fragile, but required by IDEs
55
80
// it may lead to incorrect assumption in downstream code which may expect an error if a manifest was not found
56
81
// we should refactor this API to more clearly return errors for inputs that do not have a corresponding manifest
57
- public init ( input: PackageGraphRootInput , manifests: [ AbsolutePath : Manifest ] , explicitProduct: String ? = nil ) {
82
+ public init ( input: PackageGraphRootInput , manifests: [ AbsolutePath : Manifest ] , explicitProduct: String ? = nil , mirrors : DependencyMirrors ? = nil ) {
58
83
self . packages = input. packages. reduce ( into: . init( ) , { partial, inputPath in
59
84
if let manifest = manifests [ inputPath] {
60
85
let packagePath = manifest. path. parentDirectory
@@ -77,7 +102,8 @@ public struct PackageGraphRoot {
77
102
}
78
103
}
79
104
80
- self . dependencies = adjustedDependencies
105
+ self . _dependencies = adjustedDependencies
106
+ self . mirrors = mirrors
81
107
}
82
108
83
109
/// Returns the constraints imposed by root manifests + dependencies.
0 commit comments