Skip to content

Commit

Permalink
dev: run build/bazelutil/check.sh after dev generate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rickystewart committed Jun 24, 2022
1 parent d95c088 commit a3c856b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
27 changes: 15 additions & 12 deletions build/bazelutil/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion pkg/cmd/dev/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions pkg/cmd/dev/testdata/datadriven/generate
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit a3c856b

Please sign in to comment.