move the semacquire to the main build loop so that the build order is kept

* a goroutine could start before another !
This commit is contained in:
Adrien Delorme 2019-05-02 16:34:48 +02:00
parent 852af993e6
commit 1dca416f87
1 changed files with 11 additions and 11 deletions

View File

@ -177,22 +177,22 @@ func (c *BuildCommand) Run(args []string) int {
}()
limitParallel := semaphore.NewWeighted(cfgParallelBuilds)
for _, b := range builds {
// Increment the waitgroup so we wait for this item to finish properly
wg.Add(1)
// Run the build in a goroutine
go func(b packer.Build) {
defer wg.Done()
for i := range builds {
b := builds[i]
name := b.Name()
ui := buildUis[name]
// Increment the waitgroup so we wait for this item to finish properly
wg.Add(1)
if err := limitParallel.Acquire(buildCtx, 1); err != nil {
ui.Error(fmt.Sprintf("Build '%s' failed to acquire semaphore: %s", name, err))
errors[name] = err
return
break
}
// Run the build in a goroutine
go func() {
defer wg.Done()
defer limitParallel.Release(1)
log.Printf("Starting build run: %s", name)
@ -207,7 +207,7 @@ func (c *BuildCommand) Run(args []string) int {
artifacts.m[name] = runArtifacts
artifacts.Unlock()
}
}(b)
}()
if cfgDebug {
log.Printf("Debug enabled, so waiting for build to finish: %s", b.Name())