From a3c856b6598f993d101ca2ec822882d74860feda Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Wed, 22 Jun 2022 10:16:03 -0500 Subject: [PATCH] dev: run `build/bazelutil/check.sh` after `dev generate` This runs a couple additional checks. I add a fast path to the script to make sure this doesn't stall anyone. Release note: None --- build/bazelutil/check.sh | 27 +++++++++++++----------- dev | 2 +- pkg/cmd/dev/generate.go | 11 +++++++++- pkg/cmd/dev/testdata/datadriven/generate | 18 ++++++++++++++++ 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/build/bazelutil/check.sh b/build/bazelutil/check.sh index a9245dcae898..6fdd151d363c 100755 --- a/build/bazelutil/check.sh +++ b/build/bazelutil/check.sh @@ -3,7 +3,8 @@ set -euo pipefail # This script performs assorted checks to make sure there is nothing obviously -# wrong with the Bazel build. +# wrong with the Bazel build. This is run in CI as well as by `dev generate`. +# Set COCKROACH_BAZEL_CHECK_FAST to skip the longer-running logic in this file. EXISTING_GO_GENERATE_COMMENTS=" pkg/roachprod/vm/aws/config.go://go:generate go-bindata -mode 0600 -modtime 1400000000 -pkg aws -o embedded.go config.json old.json @@ -60,17 +61,19 @@ pkg/util/buildutil/crdb_test_off.go://go:build !crdb_test || crdb_test_off pkg/util/buildutil/crdb_test_on.go://go:build crdb_test && !crdb_test_off " -git grep 'go:generate stringer' pkg | while read LINE; do - dir=$(dirname $(echo $LINE | cut -d: -f1)) - type=$(echo $LINE | grep -o -- '-type[= ][^ ]*' | sed 's/-type[= ]//g' | awk '{print tolower($0)}') - build_out=$(bazel query --output=build "//$dir:${type}_string.go") - if [[ -z "$build_out" ]]; then - echo 'Detected an autogenerated file that is not built inside the Bazel sandbox: ' - echo " $dir/${type}_string.go, generated by: $LINE" - echo 'Generate this file using the Bazel sandbox (see the utilities in build/STRINGER.bzl);' - exit 1 - fi -done +if [ -z "${COCKROACH_BAZEL_CHECK_FAST:-}" ]; then + git grep 'go:generate stringer' pkg | while read LINE; do + dir=$(dirname $(echo $LINE | cut -d: -f1)) + type=$(echo $LINE | grep -o -- '-type[= ][^ ]*' | sed 's/-type[= ]//g' | awk '{print tolower($0)}') + build_out=$(bazel query --output=build "//$dir:${type}_string.go") + if [[ -z "$build_out" ]]; then + echo 'Detected an autogenerated file that is not built inside the Bazel sandbox: ' + echo " $dir/${type}_string.go, generated by: $LINE" + echo 'Generate this file using the Bazel sandbox (see the utilities in build/STRINGER.bzl);' + exit 1 + fi + done +fi # We exclude stringer and add-leaktest.sh -- the former is already all # Bazelfied, and the latter can be safely ignored since we have a lint to check diff --git a/dev b/dev index 2459e5d67aa2..e1f378eb93b7 100755 --- a/dev +++ b/dev @@ -3,7 +3,7 @@ set -euo pipefail # Bump this counter to force rebuilding `dev` on all machines. -DEV_VERSION=37 +DEV_VERSION=38 THIS_DIR=$(cd "$(dirname "$0")" && pwd) BINARY_DIR=$THIS_DIR/bin/dev-versions diff --git a/pkg/cmd/dev/generate.go b/pkg/cmd/dev/generate.go index abb746a03597..de07ef590747 100644 --- a/pkg/cmd/dev/generate.go +++ b/pkg/cmd/dev/generate.go @@ -109,7 +109,16 @@ func (d *dev) generate(cmd *cobra.Command, targets []string) error { } } - return nil + ctx := cmd.Context() + env := os.Environ() + envvar := "COCKROACH_BAZEL_CHECK_FAST=1" + d.log.Printf("export %s", envvar) + env = append(env, envvar) + workspace, err := d.getWorkspace(ctx) + if err != nil { + return err + } + return d.exec.CommandContextWithEnv(ctx, env, filepath.Join(workspace, "build", "bazelutil", "check.sh")) } func (d *dev) generateBazel(cmd *cobra.Command) error { diff --git a/pkg/cmd/dev/testdata/datadriven/generate b/pkg/cmd/dev/testdata/datadriven/generate index 063ae61607f3..dddc8a677ae4 100644 --- a/pkg/cmd/dev/testdata/datadriven/generate +++ b/pkg/cmd/dev/testdata/datadriven/generate @@ -2,12 +2,18 @@ exec dev gen protobuf ---- bazel run //pkg/gen:go_proto +export COCKROACH_BAZEL_CHECK_FAST=1 +bazel info workspace --color=no +crdb-checkout/build/bazelutil/check.sh exec dev gen bazel ---- bazel info workspace --color=no crdb-checkout/build/bazelutil/bazel-generate.sh +export COCKROACH_BAZEL_CHECK_FAST=1 +bazel info workspace --color=no +crdb-checkout/build/bazelutil/check.sh exec dev generate bazel --mirror --force @@ -16,11 +22,17 @@ bazel info workspace --color=no export COCKROACH_BAZEL_CAN_MIRROR=1 export COCKROACH_BAZEL_FORCE_GENERATE=1 crdb-checkout/build/bazelutil/bazel-generate.sh +export COCKROACH_BAZEL_CHECK_FAST=1 +bazel info workspace --color=no +crdb-checkout/build/bazelutil/check.sh exec dev generate go_nocgo ---- bazel run //pkg/gen:code +export COCKROACH_BAZEL_CHECK_FAST=1 +bazel info workspace --color=no +crdb-checkout/build/bazelutil/check.sh exec dev generate docs @@ -29,6 +41,9 @@ bazel run //pkg/gen:docs bazel info workspace --color=no crdb-checkout/build/bazelutil/generate_redact_safe.sh echo "" > crdb-checkout/docs/generated/redact_safe.md +export COCKROACH_BAZEL_CHECK_FAST=1 +bazel info workspace --color=no +crdb-checkout/build/bazelutil/check.sh exec dev gen go_nocgo docs @@ -37,3 +52,6 @@ bazel run //pkg/gen bazel info workspace --color=no crdb-checkout/build/bazelutil/generate_redact_safe.sh echo "" > crdb-checkout/docs/generated/redact_safe.md +export COCKROACH_BAZEL_CHECK_FAST=1 +bazel info workspace --color=no +crdb-checkout/build/bazelutil/check.sh