Skip to content

Commit

Permalink
cmd/tools/slowest: Support build tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed May 15, 2020
1 parent 9a46ae9 commit e9510d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions cmd/tool/slowest/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
func writeTestSkip(tcs []testjson.TestCase, skipStmt ast.Stmt) error {
fset := token.NewFileSet()
cfg := packages.Config{
Mode: modeAll(),
Tests: true,
Fset: fset,
// FIXME: BuildFlags: strings.Split(os.Getenv("GOFLAGS"), " "),
Mode: modeAll(),
Tests: true,
Fset: fset,
BuildFlags: buildFlags(),
}
pkgNames, index := testNamesByPkgName(tcs)
pkgs, err := packages.Load(&cfg, pkgNames...)
Expand Down Expand Up @@ -168,3 +168,11 @@ func modeAll() packages.LoadMode {
mode = mode | packages.NeedSyntax | packages.NeedTypesInfo
return mode
}

func buildFlags() []string {
flags := os.Getenv("GOFLAGS")
if len(flags) == 0 {
return nil
}
return strings.Split(os.Getenv("GOFLAGS"), " ")
}
4 changes: 4 additions & 0 deletions cmd/tool/slowest/slowest.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Example - using a custom --skip-stmt:
Note that this tool does not add imports, so using a custom statement may require
you to add any necessary imports to the file.
Go build flags, such as build tags, may be set using the GOFLAGS environment
variable, following the same rules as the go toolchain. See
https://golang.org/cmd/go/#hdr-Environment_variables.
Flags:
`, name, name)
flags.PrintDefaults()
Expand Down

0 comments on commit e9510d9

Please sign in to comment.