@@ -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.
@@ -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,8 @@ public struct PubgrubDependencyResolver {
517
499
return . conflict
518
500
}
519
501
520
- log ( " derived: \( unsatisfiedTerm. inverse) " )
502
+ //log("derived: \(unsatisfiedTerm.inverse)")
503
+ self . delegate? . derived ( term: unsatisfiedTerm. inverse)
521
504
state. derive ( unsatisfiedTerm. inverse, cause: incompatibility)
522
505
523
506
return . almostSatisfied( node: unsatisfiedTerm. node)
@@ -527,7 +510,7 @@ public struct PubgrubDependencyResolver {
527
510
// https://github.com/dart-lang/pub/tree/master/doc/solver.md#conflict-resolution
528
511
// https://github.com/dart-lang/pub/blob/master/lib/src/solver/version_solver.dart#L201
529
512
internal func resolve( state: State , conflict: Incompatibility ) throws -> Incompatibility {
530
- log ( " conflict: \( conflict) " )
513
+ self . delegate ? . conflict ( conflict: conflict)
531
514
532
515
var incompatibility = conflict
533
516
var createdIncompatibility = false
@@ -594,12 +577,17 @@ public struct PubgrubDependencyResolver {
594
577
)
595
578
createdIncompatibility = true
596
579
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) " )
580
+ if let term = mostRecentTerm {
581
+ if let diff = difference {
582
+ self . delegate? . partiallySatisfied ( term: term, by: _mostRecentSatisfier, incompatibility: incompatibility, difference: diff)
583
+ } else {
584
+ self . delegate? . satisfied ( term: term, by: _mostRecentSatisfier, incompatibility: incompatibility)
585
+ }
586
+ }
600
587
}
601
588
602
- log ( " failed: \( incompatibility) " )
589
+ //log("failed: \(incompatibility)")
590
+ self . delegate? . failedToResolve ( incompatibility: incompatibility)
603
591
throw PubgrubError . _unresolvable ( incompatibility, state. incompatibilities)
604
592
}
605
593
@@ -649,8 +637,10 @@ public struct PubgrubDependencyResolver {
649
637
let counts = try result. get ( )
650
638
// forced unwraps safe since we are testing for count and errors above
651
639
let pkgTerm = undecided. min { counts [ $0] ! < counts [ $1] ! } !
640
+ self . delegate? . willResolve ( term: pkgTerm)
652
641
// at this point the container is cached
653
642
let container = try self . provider. getCachedContainer ( for: pkgTerm. node. package )
643
+
654
644
// Get the best available version for this package.
655
645
guard let version = try container. getBestAvailableVersion ( for: pkgTerm) else {
656
646
state. addIncompatibility ( try Incompatibility ( pkgTerm, root: state. root, cause: . noAvailableVersion) , at: . decisionMaking)
@@ -670,7 +660,7 @@ public struct PubgrubDependencyResolver {
670
660
// Add the incompatibility to our partial solution.
671
661
state. addIncompatibility ( incompatibility, at: . decisionMaking)
672
662
673
- // Check if this incompatibility will statisfy the solution.
663
+ // Check if this incompatibility will satisfy the solution.
674
664
haveConflict = haveConflict || incompatibility. terms. allSatisfy {
675
665
// We only need to check if the terms other than this package
676
666
// are satisfied because we _know_ that the terms matching
@@ -682,7 +672,8 @@ public struct PubgrubDependencyResolver {
682
672
683
673
// Decide this version if there was no conflict with its dependencies.
684
674
if !haveConflict {
685
- self . log ( " decision: \( pkgTerm. node. package ) @ \( version) " )
675
+ //self.log("decision: \(pkgTerm.node.package)@\(version)")
676
+ self . delegate? . didResolve ( term: pkgTerm, version: version)
686
677
state. decide ( pkgTerm. node, at: version)
687
678
}
688
679
@@ -692,20 +683,6 @@ public struct PubgrubDependencyResolver {
692
683
}
693
684
}
694
685
}
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
686
}
710
687
711
688
private struct DiagnosticReportBuilder {
0 commit comments