Skip to content

Commit 1b95e38

Browse files
committed
Revert "cmd/govulncheck: add -cpuprofile flag"
This reverts commit 9bf256343acc20d22586789d07aecf887d8a5aea. Reason for revert: not needed Change-Id: I70d04b25e4a6dba6a7b3aa2b4fa54d38393531fd Reviewed-on: https://go-review.googlesource.com/c/vuln/+/458176 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Zvonimir Pavlinovic <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 5698668 commit 1b95e38

File tree

3 files changed

+12
-42
lines changed

3 files changed

+12
-42
lines changed

cmd/govulncheck/main.go

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import (
1010
"fmt"
1111
"os"
1212
"path/filepath"
13-
"runtime/pprof"
14-
1513
"strings"
1614

1715
"golang.org/x/tools/go/buildutil"
@@ -26,9 +24,7 @@ var (
2624
jsonFlag = flag.Bool("json", false, "output JSON")
2725
verboseFlag = flag.Bool("v", false, "print a full call stack for each vulnerability")
2826
testFlag = flag.Bool("test", false, "analyze test files. Only valid for source code.")
29-
cpuprofile = flag.String("cpuprofile", "", "write CPU profile to file")
30-
31-
tagsFlag buildutil.TagsFlag
27+
tagsFlag buildutil.TagsFlag
3228

3329
// testmode flags. See main_testmode.go.
3430
dirFlag string
@@ -62,16 +58,6 @@ For details, see https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck.
6258
os.Exit(1)
6359
}
6460

65-
// Profiling support.
66-
if *cpuprofile != "" {
67-
f, err := os.Create(*cpuprofile)
68-
if err != nil {
69-
fmt.Fprintln(os.Stderr, err)
70-
os.Exit(1)
71-
}
72-
pprof.StartCPUProfile(f)
73-
}
74-
7561
patterns := flag.Args()
7662

7763
sourceAnalysis := true
@@ -80,18 +66,14 @@ For details, see https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck.
8066
}
8167
validateFlags(sourceAnalysis)
8268

83-
err := doGovulncheck(patterns, sourceAnalysis)
84-
pprof.StopCPUProfile()
85-
if err != nil {
86-
if code, ok := err.(exitCode); ok {
87-
os.Exit(int(code))
88-
}
89-
die("govulncheck: %v", err)
69+
if err := doGovulncheck(patterns, sourceAnalysis); err != nil {
70+
die(fmt.Sprintf("govulncheck: %v", err))
9071
}
9172
}
9273

93-
// doGovulncheck performs the main govulncheck functionality and
94-
// returns an error, possibly an exitCode.
74+
// doGovulncheck performs main govulncheck functionality and exits the
75+
// program upon success with an appropriate exit status. Otherwise,
76+
// returns an error.
9577
func doGovulncheck(patterns []string, sourceAnalysis bool) error {
9678
ctx := context.Background()
9779
dir := filepath.FromSlash(dirFlag)
@@ -145,11 +127,11 @@ func doGovulncheck(patterns []string, sourceAnalysis bool) error {
145127

146128
if *jsonFlag {
147129
// Following golang.org/x/tools/go/analysis/singlechecker,
148-
// -json mode is always a success.
130+
// return 0 exit code in -json mode.
149131
if err := printJSON(res); err != nil {
150132
return err
151133
}
152-
return nil // success
134+
os.Exit(0)
153135
}
154136

155137
printText(res, *verboseFlag, sourceAnalysis)
@@ -162,21 +144,16 @@ func doGovulncheck(patterns []string, sourceAnalysis bool) error {
162144
if sourceAnalysis {
163145
for _, v := range res.Vulns {
164146
if v.IsCalled() {
165-
return exitCode(3)
147+
os.Exit(3)
166148
}
167149
}
168150
} else if len(res.Vulns) > 0 {
169-
return exitCode(3)
151+
os.Exit(3)
170152
}
153+
os.Exit(0)
171154
return nil
172155
}
173156

174-
// exitCode is an error returned by doGovulncheck to indicate
175-
// that the the program should silently exit with the specified code.
176-
type exitCode int
177-
178-
func (code exitCode) Error() string { return fmt.Sprintf("exit code %d", code) }
179-
180157
func validateFlags(source bool) {
181158
if !source {
182159
if *testFlag {

cmd/govulncheck/main_command_118_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ func TestCommand(t *testing.T) {
3636
if err != nil {
3737
t.Fatal(err)
3838
}
39-
40-
// Comment this out to log all command output (very verbose).
41-
ts.DisableLogging = true
42-
39+
ts.DisableLogging = false
4340
// Define a command that runs govulncheck with our local DB. We can't use
4441
// cmdtest.Program for this because it doesn't let us set the environment,
4542
// and that is the only way to tell govulncheck about an alternative vuln

cmd/govulncheck/testdata/usage.ct

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ usage:
33
govulncheck [flags] package...
44
govulncheck [flags] binary
55

6-
-cpuprofile string
7-
write CPU profile to file
86
-dir string
97
directory to use for loading source files
108
-json
@@ -24,8 +22,6 @@ usage:
2422
govulncheck [flags] package...
2523
govulncheck [flags] binary
2624

27-
-cpuprofile string
28-
write CPU profile to file
2925
-dir string
3026
directory to use for loading source files
3127
-json

0 commit comments

Comments
 (0)