From fb7afda4c27ba9e692a16eaa45cdd8a2a05ecf41 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Thu, 12 Dec 2024 13:16:33 +0000 Subject: [PATCH] cmd/dev: add short flag to lint during build 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. --- pkg/cmd/dev/build.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkg/cmd/dev/build.go b/pkg/cmd/dev/build.go index 12d8aeb18584..8e030fb8bc89 100644 --- a/pkg/cmd/dev/build.go +++ b/pkg/cmd/dev/build.go @@ -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" @@ -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)") @@ -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)