diff --git a/manifest.go b/manifest.go index 034a82ef07..e9df035b81 100644 --- a/manifest.go +++ b/manifest.go @@ -158,31 +158,32 @@ func validateManifest(s string) ([]error, error) { return warns, nil } -// ValidateProjectRoots validates the project roots present in manifest. -func ValidateProjectRoots(c *Ctx, m *Manifest, sm gps.SourceManager) error { - projectRoots := make([]gps.ProjectRoot, 0, len(m.Constraints)+len(m.Ovr)) - for pr := range m.Constraints { - projectRoots = append(projectRoots, pr) - } - for pr := range m.Ovr { - projectRoots = append(projectRoots, pr) +// validateProjectRoot validates ProjectRoot. It it used as a goroutine for +// concurrent validation of ProjectRoot(s). +func validateProjectRoot(pr gps.ProjectRoot, sm gps.SourceManager, wg *sync.WaitGroup, errorCh chan<- error) { + defer wg.Done() + origPR, err := sm.DeduceProjectRoot(string(pr)) + if err != nil { + errorCh <- err + } else if origPR != pr { + errorCh <- fmt.Errorf("the name for %q should be changed to %q", pr, origPR) } +} +// ValidateProjectRoots validates the project roots present in manifest. +func ValidateProjectRoots(c *Ctx, m *Manifest, sm gps.SourceManager) error { // Channel to receive all the errors - errorCh := make(chan error, len(projectRoots)) + errorCh := make(chan error, len(m.Constraints)+len(m.Ovr)) var wg sync.WaitGroup - for _, pr := range projectRoots { + + for pr := range m.Constraints { wg.Add(1) - go func(pr gps.ProjectRoot) { - defer wg.Done() - origPR, err := sm.DeduceProjectRoot(string(pr)) - if err != nil { - errorCh <- err - } else if origPR != pr { - errorCh <- fmt.Errorf("the name for %q should be changed to %q", pr, origPR) - } - }(pr) + go validateProjectRoot(pr, sm, &wg, errorCh) + } + for pr := range m.Ovr { + wg.Add(1) + go validateProjectRoot(pr, sm, &wg, errorCh) } wg.Wait()