@@ -284,34 +284,17 @@ func Prepare(params SolveParameters, sm SourceManager) (Solver, error) {
284
284
params .stdLibFn = paths .IsStandardImportPath
285
285
}
286
286
287
+ // Validate the solver parameters
288
+ if err := validateParams (sm , rd , params .stdLibFn ); err != nil {
289
+ return nil , err
290
+ }
291
+
287
292
s := & solver {
288
293
tl : params .TraceLogger ,
289
294
stdLibFn : params .stdLibFn ,
290
295
rd : rd ,
291
296
}
292
297
293
- var deducePkgsGroup sync.WaitGroup
294
- deductionErrs := make (DeductionFailureErrs )
295
-
296
- checkPkg := func (ip string , sm SourceManager ) {
297
- _ , err := sm .DeduceProjectRoot (ip )
298
- if err != nil {
299
- deductionErrs [ip ] = err
300
- }
301
- deducePkgsGroup .Done ()
302
- }
303
-
304
- for _ , ip := range rd .externalImportList (params .stdLibFn ) {
305
- deducePkgsGroup .Add (1 )
306
- go checkPkg (ip , sm )
307
- }
308
-
309
- deducePkgsGroup .Wait ()
310
-
311
- if len (deductionErrs ) > 0 {
312
- return nil , deductionErrs
313
- }
314
-
315
298
// Set up the bridge and ensure the root dir is in good, working order
316
299
// before doing anything else.
317
300
if params .mkBridgeFn == nil {
@@ -414,8 +397,7 @@ func (s *solver) Solve() (Solution, error) {
414
397
s .vUnify .mtr = s .mtr
415
398
416
399
// Prime the queues with the root project
417
- err := s .selectRoot ()
418
- if err != nil {
400
+ if err := s .selectRoot (); err != nil {
419
401
return nil , err
420
402
}
421
403
@@ -556,6 +538,37 @@ func (s *solver) solve() (map[atom]map[string]struct{}, error) {
556
538
return projs , nil
557
539
}
558
540
541
+ // validateParams validates the solver parameters to ensure solving can be completed.
542
+ func validateParams (sm SourceManager , rd rootdata , stdLibFn func (string ) bool ) error {
543
+ // Ensure that all packages are deducible without issues.
544
+ var deducePkgsGroup sync.WaitGroup
545
+ deductionErrs := make (DeductionFailureErrs )
546
+ var errsMut sync.Mutex
547
+
548
+ deducePkg := func (ip string , sm SourceManager ) {
549
+ _ , err := sm .DeduceProjectRoot (ip )
550
+ if err != nil {
551
+ errsMut .Lock ()
552
+ deductionErrs [ip ] = err
553
+ errsMut .Unlock ()
554
+ }
555
+ deducePkgsGroup .Done ()
556
+ }
557
+
558
+ for _ , ip := range rd .externalImportList (stdLibFn ) {
559
+ deducePkgsGroup .Add (1 )
560
+ go deducePkg (ip , sm )
561
+ }
562
+
563
+ deducePkgsGroup .Wait ()
564
+
565
+ if len (deductionErrs ) > 0 {
566
+ return deductionErrs
567
+ }
568
+
569
+ return nil
570
+ }
571
+
559
572
// selectRoot is a specialized selectAtom, used solely to initially
560
573
// populate the queues at the beginning of a solve run.
561
574
func (s * solver ) selectRoot () error {
0 commit comments