Skip to content

Commit

Permalink
Merge #68559
Browse files Browse the repository at this point in the history
68559: dev: teach dev how to lint r=rail a=rickystewart

(Only the most recent commit applies for this review, the other is from #68514)

Closes #68547.

Release note: None

Co-authored-by: Ricky Stewart <[email protected]>
  • Loading branch information
craig[bot] and rickystewart committed Aug 9, 2021
2 parents 764a1a9 + ae6eb78 commit 5473933
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
39 changes: 31 additions & 8 deletions pkg/cmd/dev/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@

package main

import (
"github.com/cockroachdb/errors"
"github.com/spf13/cobra"
)
import "github.com/spf13/cobra"

const shortFlag = "short"

// makeLintCmd constructs the subcommand used to run the specified linters.
func makeLintCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Command {
return &cobra.Command{
lintCmd := &cobra.Command{
Use: "lint",
Short: `Run the specified linters`,
Long: `Run the specified linters.`,
Expand All @@ -26,9 +25,33 @@ func makeLintCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Comm
Args: cobra.NoArgs,
RunE: runE,
}
addCommonTestFlags(lintCmd)
lintCmd.Flags().Bool(shortFlag, false, "run only short lints")
return lintCmd
}

func (*dev) lint(cmd *cobra.Command, args []string) error {
// TODO(irfansharif): Flesh out the example usage patterns.
return errors.New("unimplemented")
func (d *dev) lint(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
filter := mustGetFlagString(cmd, filterFlag)
timeout := mustGetFlagDuration(cmd, timeoutFlag)
short := mustGetFlagBool(cmd, shortFlag)

var args []string
// NOTE the --config=test here. It's very important we compile the test binary with the
// appropriate stuff (gotags, etc.)
args = append(args, "run", "--color=yes", "--config=test", "//build/bazelutil:lint")
args = append(args, getConfigFlags()...)
args = append(args, mustGetRemoteCacheArgs(remoteCacheAddr)...)
args = append(args, "--", "-test.v")
if short {
args = append(args, "-test.short")
}
if timeout > 0 {
args = append(args, "-test.timeout", timeout.String())
}
if filter != "" {
args = append(args, "-test.run", filter)
}

return d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...)
}
3 changes: 1 addition & 2 deletions pkg/cmd/dev/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ func (d *dev) runUnitTest(cmd *cobra.Command, pkgs []string) error {
args = append(args, "--test_output", "errors")
}

err := d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...)
return err
return d.exec.CommandContextInheritingStdStreams(ctx, "bazel", args...)
}

func (d *dev) runLogicTest(cmd *cobra.Command) error {
Expand Down
15 changes: 15 additions & 0 deletions pkg/cmd/dev/testdata/lint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
dev lint
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel run --color=yes --config=test //build/bazelutil:lint --config=dev -- -test.v

dev lint --short --timeout=5m
----
getenv PATH
which cc
readlink /usr/local/opt/ccache/libexec/cc
export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
bazel run --color=yes --config=test //build/bazelutil:lint --config=dev -- -test.v -test.short -test.timeout 5m0s
35 changes: 35 additions & 0 deletions pkg/cmd/dev/testdata/recording/lint.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
getenv PATH
----
/usr/local/opt/ccache/libexec:/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin

which cc
----
/usr/local/opt/ccache/libexec/cc

readlink /usr/local/opt/ccache/libexec/cc
----
../bin/ccache

export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
----

bazel run --color=yes --config=test //build/bazelutil:lint --config=dev -- -test.v
----

getenv PATH
----
/usr/local/opt/ccache/libexec:/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin

which cc
----
/usr/local/opt/ccache/libexec/cc

readlink /usr/local/opt/ccache/libexec/cc
----
../bin/ccache

export PATH=/usr/local/opt/make/libexec/gnubin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Library/Apple/usr/bin
----

bazel run --color=yes --config=test //build/bazelutil:lint --config=dev -- -test.v -test.short -test.timeout 5m0s
----

0 comments on commit 5473933

Please sign in to comment.