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

Commit

Permalink
Prefetch and log output during InitializeRootManifestAndLock
Browse files Browse the repository at this point in the history
  • Loading branch information
xmattstrongx committed Oct 14, 2017
1 parent ac1a162 commit db0b31c
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cmd/dep/root_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
package main

import (
"context"
"io/ioutil"
"log"

"golang.org/x/sync/errgroup"

"github.com/golang/dep"
fb "github.com/golang/dep/internal/feedback"
"github.com/golang/dep/internal/gps"
Expand Down Expand Up @@ -45,6 +48,9 @@ func (a *rootAnalyzer) InitializeRootManifestAndLock(dir string, pr gps.ProjectR

if rootM == nil {
rootM = dep.NewManifest()
if err := a.cacheDeps(pr); err != nil {
return nil, nil, err
}
}
if rootL == nil {
rootL = &dep.Lock{}
Expand All @@ -53,6 +59,58 @@ func (a *rootAnalyzer) InitializeRootManifestAndLock(dir string, pr gps.ProjectR
return
}

func (a *rootAnalyzer) cacheDeps(pr gps.ProjectRoot) error {
logger := a.ctx.Err
g, _ := errgroup.WithContext(context.TODO())
concurrency := 4

syncDep := func(pr gps.ProjectRoot, sm gps.SourceManager) error {
if err := sm.SyncSourceFor(gps.ProjectIdentifier{ProjectRoot: pr}); err != nil {
logger.Printf("Unable to cache %s - %s", pr, err)
return err
}
logger.Printf("Cached %s", pr)
return nil
}

deps := make(chan gps.ProjectRoot)

for i := 0; i < concurrency; i++ {
g.Go(func() error {
for d := range deps {
err := syncDep(d, a.sm)
if err != nil {
return err
}
}
return nil
})
}

g.Go(func() error {
defer close(deps)
for ip := range a.directDeps {
logger.Printf("Package %q, analyzing...", ip)
pr, err := a.sm.DeduceProjectRoot(ip)
if err != nil {
return err
}
deps <- pr
}
return nil
})

go func() {
g.Wait()
}()

if err := g.Wait(); err != nil {
return err
}
logger.Printf("Successfully cached all deps.")
return nil
}

func (a *rootAnalyzer) importManifestAndLock(dir string, pr gps.ProjectRoot, suppressLogs bool) (*dep.Manifest, *dep.Lock, error) {
logger := a.ctx.Err
if suppressLogs {
Expand Down

0 comments on commit db0b31c

Please sign in to comment.