Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev: run build/bazelutil/check.sh after dev generate #83188

Merged
merged 1 commit into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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