Skip to content

Commit

Permalink
cmd/dev: add short flag to lint during build
Browse files Browse the repository at this point in the history
Running nogo in every buuld can be very slow so it is common to have config=nolintonbuild
set in bazelrc, but it is still handy to be able to quickly run it locally before CI or when
CI detect a problem. This adds a shorthand --lint/-l to the 'build' cmd to enable validation
during the build process even if the config would normally disable it.

Release note: none.
Epic: none.
  • Loading branch information
dt committed Dec 12, 2024
1 parent 4b31b16 commit fb7afda
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/cmd/dev/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (

const (
crossFlag = "cross"
lintFlag = "lint"
cockroachTarget = "//pkg/cmd/cockroach:cockroach"
nogoEnableFlag = "--run_validations"
nogoDisableFlag = "--norun_validations"
geosTarget = "//c-deps:libgeos"
devTarget = "//pkg/cmd/dev:dev"
Expand Down Expand Up @@ -59,6 +61,7 @@ func makeBuildCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Com
RunE: runE,
}
buildCmd.Flags().String(volumeFlag, "bzlhome", "the Docker volume to use as the container home directory (only used for cross builds)")
buildCmd.Flags().BoolP(lintFlag, "l", false, "perform linting (nogo) as part of the build process (i.e. override nolintonbuild config)")
buildCmd.Flags().String(crossFlag, "", "cross-compiles using the builder image (options: linux, linuxarm, macos, macosarm, windows)")
buildCmd.Flags().Lookup(crossFlag).NoOptDefVal = "linux"
buildCmd.Flags().StringArray(dockerArgsFlag, []string{}, "additional arguments to pass to Docker (only used for cross builds)")
Expand Down Expand Up @@ -141,12 +144,16 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
targets, additionalBazelArgs := splitArgsAtDash(cmd, commandLine)
ctx := cmd.Context()
cross := mustGetFlagString(cmd, crossFlag)
lint := mustGetFlagBool(cmd, lintFlag)
dockerArgs := mustGetFlagStringArray(cmd, dockerArgsFlag)

args, buildTargets, err := d.getBasicBuildArgs(ctx, targets)
if err != nil {
return err
}
if lint {
args = append(args, nogoEnableFlag)
}
args = append(args, additionalBazelArgs...)
configArgs := getConfigArgs(args)

Expand Down

0 comments on commit fb7afda

Please sign in to comment.