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

Commit 1fa8a51

Browse files
committed
internal/gps: parallelize WriteDepTree
This commit updates WriteDepTree to parallelize write projects to the vendor directory. Signed-off-by: Ibrahim AshShohail <[email protected]>
1 parent 53e80dc commit 1fa8a51

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

internal/gps/result.go

+32-11
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
"log"
1010
"os"
1111
"path/filepath"
12+
"sync"
13+
14+
"github.com/pkg/errors"
1215
)
1316

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

65-
// TODO(sdboyer) parallelize
68+
var wg sync.WaitGroup
69+
errCh := make(chan error, len(l.Projects()))
70+
6671
for _, p := range l.Projects() {
67-
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))
72+
wg.Add(1)
73+
go func(p LockedProject) {
74+
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))
75+
logger.Printf("Writing out %s@%s", p.Ident().errString(), p.Version())
76+
77+
if err := sm.ExportProject(p.Ident(), p.Version(), to); err != nil {
78+
errCh <- errors.Wrapf(err, "failed to export %s", p.Ident().ProjectRoot)
79+
}
80+
81+
wg.Done()
82+
if sv {
83+
filepath.Walk(to, stripVendor)
84+
}
85+
}(p)
86+
}
6887

69-
logger.Printf("Writing out %s@%s", p.Ident().errString(), p.Version())
70-
err = sm.ExportProject(p.Ident(), p.Version(), to)
71-
if err != nil {
72-
removeAll(basedir)
73-
return fmt.Errorf("error while exporting %s@%s: %s", p.Ident().errString(), p.Version(), err)
74-
}
75-
if sv {
76-
filepath.Walk(to, stripVendor)
88+
wg.Wait()
89+
close(errCh)
90+
91+
if len(errCh) > 0 {
92+
logger.Println("Failed to write dep tree. The following errors occurred:")
93+
for err := range errCh {
94+
logger.Println(" * ", err)
7795
}
78-
}
7996

97+
removeAll(basedir)
98+
99+
return errors.New("failed to write dep tree")
100+
}
80101
return nil
81102
}
82103

0 commit comments

Comments
 (0)