Skip to content

Commit d24646f

Browse files
committed
estimate: un-vendor package
1 parent f5e9c80 commit d24646f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

estimate.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,26 @@ func get(gopath, repo string) error {
3333
return cmd.Run()
3434
}
3535

36+
func removeVendor(gopath string) (found bool, _ error) {
37+
err := filepath.Walk(filepath.Join(gopath, "src"), func(path string, info os.FileInfo, err error) error {
38+
if err != nil {
39+
return err
40+
}
41+
if !info.IsDir() {
42+
return nil // skip non-directories
43+
}
44+
if info.Name() != "vendor" {
45+
return nil
46+
}
47+
found = true
48+
if err := os.RemoveAll(path); err != nil {
49+
return err
50+
}
51+
return filepath.SkipDir
52+
})
53+
return found, err
54+
}
55+
3656
func estimate(importpath string) error {
3757
// construct a separate GOPATH in a temporary directory
3858
gopath, err := ioutil.TempDir("", "dh-make-golang")
@@ -45,6 +65,18 @@ func estimate(importpath string) error {
4565
return err
4666
}
4767

68+
found, err := removeVendor(gopath)
69+
if err != nil {
70+
return err
71+
}
72+
73+
if found {
74+
// Fetch un-vendored dependencies
75+
if err := get(gopath, importpath); err != nil {
76+
return err
77+
}
78+
}
79+
4880
// Use digraph(1) to obtain the forward transitive closure of the repo in
4981
// question.
5082
cmd := exec.Command("/bin/sh", "-c", "go list -f '{{.ImportPath}}{{.Imports}}{{.TestImports}}{{.XTestImports}}' ... | tr '[]' ' ' | digraph forward $(go list "+importpath+"/...)")

0 commit comments

Comments
 (0)