@@ -685,34 +685,69 @@ type constraintsCollection map[string][]projectConstraint
685685
686686// collectConstraints collects constraints declared by all the dependencies.
687687func collectConstraints (ctx * dep.Ctx , p * dep.Project , sm gps.SourceManager ) constraintsCollection {
688- constraintCollection := make (constraintsCollection )
688+ logger := ctx .Err
689+ if ! ctx .Verbose {
690+ logger = log .New (ioutil .Discard , "" , 0 )
691+ }
692+
693+ logger .Println ("Collecting project constraints:" )
689694
690695 // Get direct deps of the root project.
691696 _ , directDeps , err := getDirectDependencies (sm , p )
692697 if err != nil {
693- ctx . Err .Println ("Error getting direct deps:" , err )
698+ logger .Println ("Error getting direct deps:" , err )
694699 }
700+
695701 // Create a root analyzer.
696702 rootAnalyzer := newRootAnalyzer (true , ctx , directDeps , sm )
697703
704+ lp := p .Lock .Projects ()
705+
706+ var mutex sync.Mutex
707+ constraintCollection := make (constraintsCollection )
708+
709+ // Channel for receiving all the errors.
710+ errCh := make (chan error , len (lp ))
711+
712+ var wg sync.WaitGroup
713+
698714 // Iterate through the locked projects and collect constraints of all the projects.
699- for _ , proj := range p .Lock .Projects () {
700- manifest , _ , err := sm .GetManifestAndLock (proj .Ident (), proj .Version (), rootAnalyzer )
701- if err != nil {
702- ctx .Err .Println ("Error getting manifest and lock:" , err )
703- continue
704- }
715+ for i , proj := range lp {
716+ wg .Add (1 )
717+ logger .Printf ("(%d/%d) %s\n " , i + 1 , len (lp ), proj .Ident ().ProjectRoot )
718+
719+ go func (proj gps.LockedProject ) {
720+ defer wg .Done ()
721+
722+ manifest , _ , err := sm .GetManifestAndLock (proj .Ident (), proj .Version (), rootAnalyzer )
723+ if err != nil {
724+ errCh <- errors .Wrap (err , "error getting manifest and lock" )
725+ return
726+ }
727+
728+ // Get project constraints.
729+ pc := manifest .DependencyConstraints ()
730+
731+ // Obtain a lock for constraintCollection.
732+ mutex .Lock ()
733+ defer mutex .Unlock ()
734+ // Iterate through the project constraints to get individual dependency
735+ // project and constraint values.
736+ for pr , pp := range pc {
737+ constraintCollection [string (pr )] = append (
738+ constraintCollection [string (pr )],
739+ projectConstraint {proj .Ident ().ProjectRoot , pp .Constraint },
740+ )
741+ }
742+ }(proj )
743+ }
705744
706- // Get project constraints.
707- pc := manifest . DependencyConstraints ( )
745+ wg . Wait ()
746+ close ( errCh )
708747
709- // Iterate through the project constraints to get individual dependency
710- // project and constraint values.
711- for pr , pp := range pc {
712- constraintCollection [string (pr )] = append (
713- constraintCollection [string (pr )],
714- projectConstraint {proj .Ident ().ProjectRoot , pp .Constraint },
715- )
748+ if len (errCh ) > 0 {
749+ for err := range errCh {
750+ logger .Println (err .Error ())
716751 }
717752 }
718753
0 commit comments