@@ -376,27 +376,22 @@ extension Workspace {
376
376
return diagnostics. emit ( error)
377
377
}
378
378
379
- // Compute the checkout state.
380
- //
381
- // We use a dummy revision in case of version and branch because we
382
- // might not know the needed revision at this point.
383
- let checkoutState : CheckoutState
379
+ // Compute the custom or extra constraint we need to impose.
380
+ let requirement : RepositoryPackageConstraint . Requirement
384
381
if let version = version {
385
- checkoutState = CheckoutState ( revision : Revision ( identifier : " " ) , version: version )
382
+ requirement = . versionSet ( . exact ( version) )
386
383
} else if let branch = branch {
387
- checkoutState = CheckoutState ( revision: Revision ( identifier : " " ) , branch : branch)
384
+ requirement = . revision( branch)
388
385
} else if let revision = revision {
389
- checkoutState = CheckoutState ( revision: Revision ( identifier : revision) )
386
+ requirement = . revision( revision)
390
387
} else {
391
- checkoutState = currentState
388
+ requirement = currentState. requirement ( )
392
389
}
393
-
394
- // Create a pin with above checkout state.
395
- let pin = PinsStore . Pin (
396
- package : dependency. name, repository: dependency. repository, state: checkoutState)
390
+ let constraint = RepositoryPackageConstraint (
391
+ container: dependency. repository, requirement: requirement)
397
392
398
393
// Run the resolution.
399
- _resolve ( root: root, extraPins : [ pin ] , diagnostics: diagnostics)
394
+ _resolve ( root: root, extraConstraints : [ constraint ] , diagnostics: diagnostics)
400
395
}
401
396
402
397
/// Cleans the build artefacts from workspace data.
@@ -886,14 +881,14 @@ extension Workspace {
886
881
887
882
/// Implementation of resolve(root:diagnostics:).
888
883
///
889
- /// The extra pins will override the pin of the same package in the
890
- /// pinsStore. It is useful in situations where a requirement is being
884
+ /// The extra constraints will be added to the main requirements.
885
+ /// It is useful in situations where a requirement is being
891
886
/// imposed outside of manifest and pins file. E.g., when using a command
892
887
/// like `$ swift package resolve foo --version 1.0.0`.
893
888
@discardableResult
894
889
fileprivate func _resolve(
895
890
root: WorkspaceRoot ,
896
- extraPins : [ PinsStore . Pin ] = [ ] ,
891
+ extraConstraints : [ RepositoryPackageConstraint ] = [ ] ,
897
892
diagnostics: DiagnosticsEngine
898
893
) -> DependencyManifests {
899
894
@@ -918,17 +913,18 @@ extension Workspace {
918
913
// The pins to use in case we need to run the resolution.
919
914
var validPins = pinsStore. createConstraints ( )
920
915
921
- // Compute if we need to run the resolver.
916
+ // Compute if we need to run the resolver. We always run the resolver if
917
+ // there are extra constraints.
922
918
if missingURLs. isEmpty {
923
919
// Use root constraints, dependency manifest constraints and extra
924
- // pins to compute if a new resolution is required.
925
- let dependencies = graphRoot. constraints + currentManifests. dependencyConstraints ( )
926
- extraPins. forEach ( pinsStore. add)
920
+ // constraints to compute if a new resolution is required.
921
+ let dependencies = graphRoot. constraints + currentManifests. dependencyConstraints ( ) + extraConstraints
927
922
928
923
let result = isResolutionRequired ( dependencies: dependencies, pinsStore: pinsStore)
929
924
930
- // If we don't need resolution, just validate pinsStore and return.
931
- if !result. resolve {
925
+ // If we don't need resolution and there are no extra constraints,
926
+ // just validate pinsStore and return.
927
+ if !result. resolve && extraConstraints. isEmpty {
932
928
validatePinsStore ( with: diagnostics)
933
929
return currentManifests
934
930
}
@@ -938,13 +934,23 @@ extension Workspace {
938
934
939
935
// Create the constraints.
940
936
var constraints = [ RepositoryPackageConstraint] ( )
941
- constraints += graphRoot. constraints
937
+ constraints += graphRoot. constraints + extraConstraints
942
938
constraints += currentManifests. editedPackagesConstraints ( )
943
939
944
940
// Perform dependency resolution.
945
- let result = resolveDependencies ( dependencies: constraints, pins: validPins, diagnostics: diagnostics)
946
- guard !diagnostics. hasErrors else {
947
- return currentManifests
941
+ let resolverDiagnostics = DiagnosticsEngine ( )
942
+ var result = resolveDependencies ( dependencies: constraints, pins: validPins, diagnostics: resolverDiagnostics)
943
+
944
+ // If we fail, we just try again without any pins because the pins might
945
+ // be completely incompatible.
946
+ //
947
+ // FIXME: We should only do this if resolver emits "unresolvable" error.
948
+ // FIXME: We should merge the engine in case we get no errors but warnings or notes.
949
+ if resolverDiagnostics. hasErrors {
950
+ result = resolveDependencies ( dependencies: constraints, pins: [ ] , diagnostics: diagnostics)
951
+ guard !diagnostics. hasErrors else {
952
+ return currentManifests
953
+ }
948
954
}
949
955
950
956
// Update the checkouts with dependency resolution result.
0 commit comments