@@ -158,31 +158,32 @@ func validateManifest(s string) ([]error, error) {
158
158
return warns , nil
159
159
}
160
160
161
- // ValidateProjectRoots validates the project roots present in manifest.
162
- func ValidateProjectRoots (c * Ctx , m * Manifest , sm gps.SourceManager ) error {
163
- projectRoots := make ([]gps.ProjectRoot , 0 , len (m .Constraints )+ len (m .Ovr ))
164
- for pr := range m .Constraints {
165
- projectRoots = append (projectRoots , pr )
166
- }
167
- for pr := range m .Ovr {
168
- projectRoots = append (projectRoots , pr )
161
+ // validateProjectRoot validates ProjectRoot. It it used as a goroutine for
162
+ // concurrent validation of ProjectRoot(s).
163
+ func validateProjectRoot (pr gps.ProjectRoot , sm gps.SourceManager , wg * sync.WaitGroup , errorCh chan <- error ) {
164
+ defer wg .Done ()
165
+ origPR , err := sm .DeduceProjectRoot (string (pr ))
166
+ if err != nil {
167
+ errorCh <- err
168
+ } else if origPR != pr {
169
+ errorCh <- fmt .Errorf ("the name for %q should be changed to %q" , pr , origPR )
169
170
}
171
+ }
170
172
173
+ // ValidateProjectRoots validates the project roots present in manifest.
174
+ func ValidateProjectRoots (c * Ctx , m * Manifest , sm gps.SourceManager ) error {
171
175
// Channel to receive all the errors
172
- errorCh := make (chan error , len (projectRoots ))
176
+ errorCh := make (chan error , len (m . Constraints ) + len ( m . Ovr ))
173
177
174
178
var wg sync.WaitGroup
175
- for _ , pr := range projectRoots {
179
+
180
+ for pr := range m .Constraints {
176
181
wg .Add (1 )
177
- go func (pr gps.ProjectRoot ) {
178
- defer wg .Done ()
179
- origPR , err := sm .DeduceProjectRoot (string (pr ))
180
- if err != nil {
181
- errorCh <- err
182
- } else if origPR != pr {
183
- errorCh <- fmt .Errorf ("the name for %q should be changed to %q" , pr , origPR )
184
- }
185
- }(pr )
182
+ go validateProjectRoot (pr , sm , & wg , errorCh )
183
+ }
184
+ for pr := range m .Ovr {
185
+ wg .Add (1 )
186
+ go validateProjectRoot (pr , sm , & wg , errorCh )
186
187
}
187
188
188
189
wg .Wait ()
0 commit comments