@@ -111,40 +111,22 @@ public struct PubgrubDependencyResolver {
111
111
/// Should resolver prefetch the containers.
112
112
private let isPrefetchingEnabled : Bool
113
113
114
- // Log stream
115
- private let traceStream : OutputByteStream ?
114
+ /// Resolver delegate
115
+ private let delegate : DependencyResolverDelegate ?
116
116
117
117
public init (
118
118
provider: PackageContainerProvider ,
119
119
pinsMap: PinsStore . PinsMap = [ : ] ,
120
120
isPrefetchingEnabled: Bool = false ,
121
121
skipUpdate: Bool = false ,
122
- traceFile: AbsolutePath ? = nil ,
123
- traceStream: OutputByteStream ? = nil
122
+ delegate: DependencyResolverDelegate ? = nil
124
123
) {
125
124
self . packageContainerProvider = provider
126
125
self . pinsMap = pinsMap
127
126
self . isPrefetchingEnabled = isPrefetchingEnabled
128
127
self . skipUpdate = skipUpdate
129
- if let stream = traceStream {
130
- self . traceStream = stream
131
- } else {
132
- self . traceStream = traceFile. flatMap { file in
133
- // FIXME: Emit a warning if this fails.
134
- try ? LocalFileOutputByteStream ( file, closeOnDeinit: true , buffered: false )
135
- }
136
- }
137
128
self . provider = ContainerProvider ( provider: self . packageContainerProvider, skipUpdate: self . skipUpdate, pinsMap: self . pinsMap)
138
- }
139
-
140
- public init (
141
- provider: PackageContainerProvider ,
142
- pinsMap: PinsStore . PinsMap = [ : ] ,
143
- isPrefetchingEnabled: Bool = false ,
144
- skipUpdate: Bool = false ,
145
- traceFile: AbsolutePath ? = nil
146
- ) {
147
- self . init ( provider: provider, pinsMap: pinsMap, isPrefetchingEnabled: isPrefetchingEnabled, skipUpdate: skipUpdate, traceFile: traceFile, traceStream: nil )
129
+ self . delegate = delegate
148
130
}
149
131
150
132
/// Execute the resolution algorithm to find a valid assignment of versions.
@@ -245,7 +227,7 @@ public struct PubgrubDependencyResolver {
245
227
var finalAssignments : [ DependencyResolver . Binding ]
246
228
= flattenedAssignments. keys. sorted ( by: { $0. name < $1. name } ) . map { package in
247
229
let details = flattenedAssignments [ package ] !
248
- return ( container : package , binding: details. binding, products: details. products)
230
+ return ( package : package , binding: details. binding, products: details. products)
249
231
}
250
232
251
233
// Add overriden packages to the result.
@@ -256,7 +238,7 @@ public struct PubgrubDependencyResolver {
256
238
finalAssignments. append ( ( identifier, override. version, override. products) )
257
239
}
258
240
259
- self . log ( finalAssignments)
241
+ self . delegate ? . computed ( bindings : finalAssignments)
260
242
261
243
return ( finalAssignments, state)
262
244
}
@@ -517,7 +499,7 @@ public struct PubgrubDependencyResolver {
517
499
return . conflict
518
500
}
519
501
520
- log ( " derived: \( unsatisfiedTerm. inverse) " )
502
+ self . delegate ? . derived ( term : unsatisfiedTerm. inverse)
521
503
state. derive ( unsatisfiedTerm. inverse, cause: incompatibility)
522
504
523
505
return . almostSatisfied( node: unsatisfiedTerm. node)
@@ -527,7 +509,7 @@ public struct PubgrubDependencyResolver {
527
509
// https://github.com/dart-lang/pub/tree/master/doc/solver.md#conflict-resolution
528
510
// https://github.com/dart-lang/pub/blob/master/lib/src/solver/version_solver.dart#L201
529
511
internal func resolve( state: State , conflict: Incompatibility ) throws -> Incompatibility {
530
- log ( " conflict: \( conflict) " )
512
+ self . delegate ? . conflict ( conflict: conflict)
531
513
532
514
var incompatibility = conflict
533
515
var createdIncompatibility = false
@@ -594,12 +576,16 @@ public struct PubgrubDependencyResolver {
594
576
)
595
577
createdIncompatibility = true
596
578
597
- log ( " CR: \( mostRecentTerm? . description ?? " " ) is \( difference != nil ? " partially " : " " ) satisfied by \( _mostRecentSatisfier) " )
598
- log ( " CR: which is caused by \( _mostRecentSatisfier. cause? . description ?? " " ) " )
599
- log ( " CR: new incompatibility \( incompatibility) " )
579
+ if let term = mostRecentTerm {
580
+ if let diff = difference {
581
+ self . delegate? . partiallySatisfied ( term: term, by: _mostRecentSatisfier, incompatibility: incompatibility, difference: diff)
582
+ } else {
583
+ self . delegate? . satisfied ( term: term, by: _mostRecentSatisfier, incompatibility: incompatibility)
584
+ }
585
+ }
600
586
}
601
587
602
- log ( " failed: \( incompatibility) " )
588
+ self . delegate ? . failedToResolve ( incompatibility : incompatibility)
603
589
throw PubgrubError . _unresolvable ( incompatibility, state. incompatibilities)
604
590
}
605
591
@@ -649,8 +635,10 @@ public struct PubgrubDependencyResolver {
649
635
let counts = try result. get ( )
650
636
// forced unwraps safe since we are testing for count and errors above
651
637
let pkgTerm = undecided. min { counts [ $0] ! < counts [ $1] ! } !
638
+ self . delegate? . willResolve ( term: pkgTerm)
652
639
// at this point the container is cached
653
640
let container = try self . provider. getCachedContainer ( for: pkgTerm. node. package )
641
+
654
642
// Get the best available version for this package.
655
643
guard let version = try container. getBestAvailableVersion ( for: pkgTerm) else {
656
644
state. addIncompatibility ( try Incompatibility ( pkgTerm, root: state. root, cause: . noAvailableVersion) , at: . decisionMaking)
@@ -670,7 +658,7 @@ public struct PubgrubDependencyResolver {
670
658
// Add the incompatibility to our partial solution.
671
659
state. addIncompatibility ( incompatibility, at: . decisionMaking)
672
660
673
- // Check if this incompatibility will statisfy the solution.
661
+ // Check if this incompatibility will satisfy the solution.
674
662
haveConflict = haveConflict || incompatibility. terms. allSatisfy {
675
663
// We only need to check if the terms other than this package
676
664
// are satisfied because we _know_ that the terms matching
@@ -682,7 +670,7 @@ public struct PubgrubDependencyResolver {
682
670
683
671
// Decide this version if there was no conflict with its dependencies.
684
672
if !haveConflict {
685
- self . log ( " decision: \( pkgTerm. node . package ) @ \( version) " )
673
+ self . delegate ? . didResolve ( term : pkgTerm, version: version )
686
674
state. decide ( pkgTerm. node, at: version)
687
675
}
688
676
@@ -692,20 +680,6 @@ public struct PubgrubDependencyResolver {
692
680
}
693
681
}
694
682
}
695
-
696
- private func log( _ assignments: [ ( container: PackageReference , binding: BoundVersion , products: ProductFilter ) ] ) {
697
- log ( " solved: " )
698
- for (container, binding, _) in assignments {
699
- log ( " \( container) \( binding) " )
700
- }
701
- }
702
-
703
- private func log( _ message: String ) {
704
- if let traceStream = traceStream {
705
- traceStream <<< message <<< " \n "
706
- traceStream. flush ( )
707
- }
708
- }
709
683
}
710
684
711
685
private struct DiagnosticReportBuilder {
0 commit comments