Skip to content

Commit c814872

Browse files
committed
add glog for skipped packages
1 parent f70a013 commit c814872

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

tools/depcheck/pkg/cmd/cmd.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package cmd
22

33
import (
4+
"flag"
45
"fmt"
56
"io"
67

78
"github.com/spf13/cobra"
9+
"github.com/spf13/pflag"
810

911
"github.com/openshift/origin/tools/depcheck/pkg/cmd/trace"
1012
)
@@ -13,7 +15,7 @@ func NewCmdDepCheck(name string, out, errout io.Writer) *cobra.Command {
1315
cmd := &cobra.Command{
1416
Use: fmt.Sprintf("%s (ARGUMENT) [OPTIONS]", name),
1517
Short: "Gather information about a dependency tree.",
16-
Long: "Modfify or gather information about a dependency tree.",
18+
Long: "Modify or gather information about a dependency tree.",
1719
Example: fmt.Sprintf(pinImportsExample, name),
1820
RunE: func(c *cobra.Command, args []string) error {
1921
c.SetOutput(errout)
@@ -23,5 +25,9 @@ func NewCmdDepCheck(name string, out, errout io.Writer) *cobra.Command {
2325

2426
cmd.AddCommand(NewCmdPinImports(name, out, errout))
2527
cmd.AddCommand(trace.NewCmdTraceImports(name, out, errout))
28+
29+
// add glog flags to our global flag set
30+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
31+
pflag.CommandLine.Set("logtostderr", "true")
2632
return cmd
2733
}

tools/depcheck/pkg/cmd/trace/pkg.go

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"regexp"
66
"strings"
77

8+
"github.com/golang/glog"
9+
810
"github.com/gonum/graph/concrete"
911

1012
depgraph "github.com/openshift/origin/tools/depcheck/pkg/graph"
@@ -94,6 +96,7 @@ func BuildGraph(packages *PackageList, excludes []string) (*depgraph.MutableDire
9496
// if a package imports a dependency that we did not visit
9597
// while traversing the code tree, ignore it, as it is not
9698
// required for the root repository to build.
99+
glog.V(1).Infof("Skipping unvisited (missing) dependency %q, which is imported by package %q", dependency, pkg.ImportPath)
97100
continue
98101
}
99102

tools/depcheck/pkg/cmd/trace/pkg_test.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,32 @@ var pkgs = &PackageList{
6969
ImportPath: "github.com/test/repo/unique/unique_vendor_one",
7070
Imports: []string{},
7171
},
72+
73+
// simulate a package that is not brought in through any of the repo entrypoints
74+
// ("github.com/test/repo/root" in this case) but exists in the codebase
75+
// because another package that is part of its repo is a transitive dependency
76+
// of one of the main repo's entrypoints.
77+
{
78+
Dir: "/path/to/github.com/test/repo/unique/unique_vendor_two",
79+
ImportPath: "github.com/test/repo/unique/unique_vendor_two",
80+
Imports: []string{
81+
"github.com/test/repo/no/node/should/exist/for/this/pkg",
82+
},
83+
},
7284
},
7385
}
7486

87+
// pkgsWithNoNodes is a map containing importPaths for packages
88+
// that are not expected to have a node in the dependency graph
89+
var pkgsWithNoNodes = map[string]bool{
90+
"github.com/test/repo/no/node/should/exist/for/this/pkg": true,
91+
}
92+
93+
func shouldHaveNode(name string) bool {
94+
_, exists := pkgsWithNoNodes[name]
95+
return !exists
96+
}
97+
7598
func TestBuildGraphCreatesExpectedNodesAndEdges(t *testing.T) {
7699
invalidImports := map[string]bool{
77100
"fmt": true,
@@ -98,8 +121,16 @@ func TestBuildGraphCreatesExpectedNodesAndEdges(t *testing.T) {
98121
}
99122

100123
to, exists := g.NodeByName(dep)
124+
if !shouldHaveNode(dep) {
125+
if exists {
126+
t.Fatalf("expected node with name %q to not exist", dep)
127+
}
128+
129+
continue
130+
}
131+
101132
if !exists || !g.Has(to) {
102-
t.Fatalf("expected node with name ")
133+
t.Fatalf("expected node with name %q to exist", dep)
103134
}
104135

105136
if !g.HasEdgeFromTo(from, to) {

0 commit comments

Comments
 (0)