@@ -143,6 +143,10 @@ public class Workspace {
143
143
144
144
/// Computes the identities which are declared in the manifests but aren't present in dependencies.
145
145
func missingPackageIdentities( ) -> Set < String > {
146
+ return computePackageIdentities ( ) . missing
147
+ }
148
+
149
+ func computePackageIdentities( ) -> ( required: Set < String > , missing: Set < String > ) {
146
150
let manifestsMap = Dictionary ( items:
147
151
root. manifests. map ( { ( $0. name. lowercased ( ) , $0) } ) +
148
152
dependencies. map ( { ( PackageReference . computeIdentity ( packageURL: $0. manifest. url) , $0. manifest) } ) )
@@ -160,7 +164,9 @@ public class Workspace {
160
164
// We should never have loaded a manifest we don't need.
161
165
assert ( availableIdentities. isSubset ( of: requiredIdentities) )
162
166
// These are the missing package identities.
163
- return requiredIdentities. subtracting ( availableIdentities)
167
+ let missingIdentities = requiredIdentities. subtracting ( availableIdentities)
168
+
169
+ return ( requiredIdentities, missingIdentities)
164
170
}
165
171
166
172
/// Returns constraints of the dependencies, including edited package constraints.
@@ -524,6 +530,7 @@ extension Workspace {
524
530
525
531
// Update the pins store.
526
532
return pinAll (
533
+ graphRoot: graphRoot,
527
534
pinsStore: pinsStore,
528
535
diagnostics: diagnostics)
529
536
}
@@ -812,13 +819,21 @@ extension Workspace {
812
819
813
820
/// Pins all of the current managed dependencies at their checkout state.
814
821
fileprivate func pinAll(
822
+ graphRoot: PackageGraphRoot ,
815
823
pinsStore: PinsStore ,
816
824
diagnostics: DiagnosticsEngine
817
825
) {
818
- // Reset the pinsStore and start pinning each dependency .
826
+ // Reset the pinsStore and start pinning the required dependencies .
819
827
pinsStore. unpinAll ( )
820
- for dependency in managedDependencies. values {
821
- pinsStore. pin ( dependency)
828
+
829
+ let currentManifests = loadDependencyManifests (
830
+ root: graphRoot, diagnostics: diagnostics)
831
+ let requiredIdentities = currentManifests. computePackageIdentities ( ) . required
832
+
833
+ for dependency in managedDependencies. values {
834
+ if requiredIdentities. contains ( dependency. packageRef. identity) {
835
+ pinsStore. pin ( dependency)
836
+ }
822
837
}
823
838
diagnostics. wrap ( { try pinsStore. saveState ( ) } )
824
839
}
@@ -1049,7 +1064,7 @@ extension Workspace {
1049
1064
// If we don't need resolution and there are no extra constraints,
1050
1065
// just validate pinsStore and return.
1051
1066
if !result. resolve && extraConstraints. isEmpty {
1052
- validatePinsStore ( with : diagnostics)
1067
+ validatePinsStore ( dependencyManifests : currentManifests , diagnostics : diagnostics)
1053
1068
return currentManifests
1054
1069
}
1055
1070
@@ -1102,7 +1117,7 @@ extension Workspace {
1102
1117
}
1103
1118
1104
1119
// Update the pinsStore.
1105
- self . pinAll ( pinsStore: pinsStore, diagnostics: diagnostics)
1120
+ self . pinAll ( graphRoot : graphRoot , pinsStore: pinsStore, diagnostics: diagnostics)
1106
1121
1107
1122
return loadDependencyManifests ( root: graphRoot, diagnostics: diagnostics)
1108
1123
}
@@ -1190,20 +1205,33 @@ extension Workspace {
1190
1205
}
1191
1206
1192
1207
/// Validates that each checked out managed dependency has an entry in pinsStore.
1193
- private func validatePinsStore( with diagnostics: DiagnosticsEngine ) {
1208
+ private func validatePinsStore( dependencyManifests : DependencyManifests , diagnostics: DiagnosticsEngine ) {
1194
1209
guard let pinsStore = diagnostics. wrap ( { try pinsStore. load ( ) } ) else {
1195
1210
return
1196
1211
}
1197
1212
1213
+ let pins = pinsStore. pinsMap. keys
1214
+ let requiredIdentities = dependencyManifests. computePackageIdentities ( ) . required
1215
+
1198
1216
for dependency in managedDependencies. values {
1199
1217
switch dependency. state {
1200
1218
case . checkout: break
1201
1219
case . edited, . local: continue
1202
1220
}
1203
- // If we find any checkout that is not in pins store, invoke pin all and return.
1204
- if pinsStore. pinsMap [ dependency. packageRef. identity] == nil {
1205
- return self . pinAll ( pinsStore: pinsStore, diagnostics: diagnostics)
1221
+
1222
+ let identity = dependency. packageRef. identity
1223
+
1224
+ if requiredIdentities. contains ( identity) {
1225
+ // If required identity contains this dependency, it should be in the pins store.
1226
+ if pins. contains ( identity) {
1227
+ continue
1228
+ }
1229
+ } else if !pins. contains ( identity) {
1230
+ // Otherwise, it should *not* be in the pins store.
1231
+ continue
1206
1232
}
1233
+
1234
+ return self . pinAll ( graphRoot: dependencyManifests. root, pinsStore: pinsStore, diagnostics: diagnostics)
1207
1235
}
1208
1236
}
1209
1237
0 commit comments