|
9 | 9 | "log"
|
10 | 10 | "os"
|
11 | 11 | "path/filepath"
|
| 12 | + "sync" |
| 13 | + |
| 14 | + "github.com/pkg/errors" |
12 | 15 | )
|
13 | 16 |
|
14 | 17 | // 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
|
62 | 65 | return err
|
63 | 66 | }
|
64 | 67 |
|
65 |
| - // TODO(sdboyer) parallelize |
| 68 | + var wg sync.WaitGroup |
| 69 | + errCh := make(chan error, len(l.Projects())) |
| 70 | + |
66 | 71 | 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 | + } |
68 | 87 |
|
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) |
77 | 95 | }
|
78 |
| - } |
79 | 96 |
|
| 97 | + removeAll(basedir) |
| 98 | + |
| 99 | + return errors.New("failed to write dep tree") |
| 100 | + } |
80 | 101 | return nil
|
81 | 102 | }
|
82 | 103 |
|
|
0 commit comments