-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
79 lines (76 loc) · 1.59 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"flag"
"fmt"
"os/exec"
"sort"
"strings"
)
func listCmd(pkg string) []string {
args := []string{"list",
"-f", "{{if not .Standard}}{{.ImportPath}}{{end}}",
"-deps",
"-test",
pkg}
output, err := exec.Command("go", args...).CombinedOutput()
if err != nil {
fmt.Printf("%s", output)
panic(err)
}
ret := strings.Split(string(output), "\n")
// for _, s := range ret {
// if strings.Contains(s, "client-go") {
// fmt.Printf("package %s imported %s\n", pkg, s)
// }
// }
return ret
}
func main() {
flag.Parse()
visited := make(map[string]struct{})
var newPkgs []string
args := flag.Args()
seed := "k8s.io/kubernetes/pkg/routes"
if len(args) != 0 {
seed = args[0]
}
newPkgs = listCmd(seed)
var i int
for {
i++
var remainingNewPkgs []string
for _, pkg := range newPkgs {
parts := strings.Split(pkg, " ")
pkg = parts[0]
pkg = strings.TrimSuffix(pkg, "_test")
pkg = strings.TrimSuffix(pkg, ".test")
if pkg == "" {
continue
}
if _, ok := visited[pkg]; ok {
continue
}
remainingNewPkgs = append(remainingNewPkgs, pkg)
visited[pkg] = struct{}{}
}
// fmt.Printf("=========================%d========================\n", i)
// for _, pkg := range remainingNewPkgs {
// fmt.Println(pkg)
// }
if len(remainingNewPkgs) == 0 {
break
}
newPkgs = []string{}
for _, pkg := range remainingNewPkgs {
newPkgs = append(newPkgs, listCmd(pkg)...)
}
}
var allDeps []string
for pkg, _ := range visited {
allDeps = append(allDeps, pkg)
}
sort.Strings(allDeps)
for _, pkg := range allDeps {
fmt.Println(pkg)
}
}