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

Commit

Permalink
internal/gps: parallelize WriteDepTree
Browse files Browse the repository at this point in the history
This commit updates WriteDepTree to parallelize write projects to the
vendor directory.

Signed-off-by: Ibrahim AshShohail <ibra.sho@gmail.com>
  • Loading branch information
ibrasho committed Aug 16, 2017
1 parent 53e80dc commit 1fa8a51
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions internal/gps/result.go
Expand Up @@ -9,6 +9,9 @@ import (
"log"
"os"
"path/filepath"
"sync"

"github.com/pkg/errors"
)

// A Solution is returned by a solver run. It is mostly just a Lock, with some
Expand Down Expand Up @@ -62,21 +65,39 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool, logger *log
return err
}

// TODO(sdboyer) parallelize
var wg sync.WaitGroup
errCh := make(chan error, len(l.Projects()))

for _, p := range l.Projects() {
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))
wg.Add(1)
go func(p LockedProject) {
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))
logger.Printf("Writing out %s@%s", p.Ident().errString(), p.Version())

if err := sm.ExportProject(p.Ident(), p.Version(), to); err != nil {
errCh <- errors.Wrapf(err, "failed to export %s", p.Ident().ProjectRoot)
}

wg.Done()
if sv {
filepath.Walk(to, stripVendor)
}
}(p)
}

logger.Printf("Writing out %s@%s", p.Ident().errString(), p.Version())
err = sm.ExportProject(p.Ident(), p.Version(), to)
if err != nil {
removeAll(basedir)
return fmt.Errorf("error while exporting %s@%s: %s", p.Ident().errString(), p.Version(), err)
}
if sv {
filepath.Walk(to, stripVendor)
wg.Wait()
close(errCh)

if len(errCh) > 0 {
logger.Println("Failed to write dep tree. The following errors occurred:")
for err := range errCh {
logger.Println(" * ", err)
}
}

removeAll(basedir)

return errors.New("failed to write dep tree")
}
return nil
}

Expand Down

0 comments on commit 1fa8a51

Please sign in to comment.