Skip to content

Commit cd70aad

Browse files
committed
load std package list to check if a package is a really "std" lib
1 parent fb6b442 commit cd70aad

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

output.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,22 @@ import (
99
"strings"
1010

1111
"golang.org/x/tools/go/callgraph"
12+
"golang.org/x/tools/go/packages"
1213
"golang.org/x/tools/go/ssa"
1314
)
1415

16+
var stdPackages = map[string]struct{}{}
17+
18+
func init() {
19+
pkgs, err := packages.Load(nil, "std")
20+
if err != nil {
21+
panic(err)
22+
}
23+
for _, p := range pkgs {
24+
stdPackages[p.PkgPath] = struct{}{}
25+
}
26+
}
27+
1528
func isSynthetic(edge *callgraph.Edge) bool {
1629
// TODO: consider handling callee.Func.Pkg == nil
1730
// this could still generate a node for the call, might be useful
@@ -25,10 +38,8 @@ func inStd(node *callgraph.Node) bool {
2538
}
2639

2740
func isStdPkgPath(path string) bool {
28-
if strings.Contains(path, ".") {
29-
return false
30-
}
31-
return true
41+
_, ok := stdPackages[path]
42+
return ok
3243
}
3344

3445
func printOutput(

0 commit comments

Comments
 (0)