Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
add validateProjectRoot() goroutine
Browse files Browse the repository at this point in the history
`validateProjectRoot()` goroutine is used to validate a single
ProjectRoot at a time.
  • Loading branch information
darkowlzz committed Sep 5, 2017
1 parent 793785b commit 2fbfda9
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2fbfda9

Please sign in to comment.