From f9de6210650be9335b91c8535806334ddf78b6d6 Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Fri, 3 Mar 2023 17:12:41 -0600 Subject: [PATCH] bazel: add `gcassert` job in TC This simple job generates code then runs `gcassert` as a standalone binary. Closes #65485. Epic: none Release note: None --- build/teamcity/cockroach/ci/tests/gcassert.sh | 12 ++++ .../cockroach/ci/tests/gcassert_impl.sh | 15 +++++ pkg/testutils/lint/BUILD.bazel | 1 + pkg/testutils/lint/gcassert_paths.txt | 29 +++++++++ pkg/testutils/lint/lint_test.go | 59 +++++++------------ 5 files changed, 78 insertions(+), 38 deletions(-) create mode 100755 build/teamcity/cockroach/ci/tests/gcassert.sh create mode 100755 build/teamcity/cockroach/ci/tests/gcassert_impl.sh create mode 100644 pkg/testutils/lint/gcassert_paths.txt diff --git a/build/teamcity/cockroach/ci/tests/gcassert.sh b/build/teamcity/cockroach/ci/tests/gcassert.sh new file mode 100755 index 000000000000..66589db130cf --- /dev/null +++ b/build/teamcity/cockroach/ci/tests/gcassert.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +set -euo pipefail + +dir="$(dirname $(dirname $(dirname $(dirname $(dirname "${0}")))))" + +source "$dir/teamcity-support.sh" # For $root +source "$dir/teamcity-bazel-support.sh" # For run_bazel + +tc_start_block "GcAssert" +run_bazel build/teamcity/cockroach/ci/tests/gcassert_impl.sh +tc_end_block "GcAssert" diff --git a/build/teamcity/cockroach/ci/tests/gcassert_impl.sh b/build/teamcity/cockroach/ci/tests/gcassert_impl.sh new file mode 100755 index 000000000000..2834a2f77374 --- /dev/null +++ b/build/teamcity/cockroach/ci/tests/gcassert_impl.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +set -xeuo pipefail + +bazel build @com_github_jordanlewis_gcassert//cmd/gcassert:gcassert --config=ci +bazel run //pkg/gen:code +GODIR=$(dirname $(bazel run @go_sdk//:bin/go --run_under=realpath)) +echo "##teamcity[testStarted name='GcAssert' captureStandardOutput='true']" +exit_status=0 +PATH=$GODIR:$PATH $(bazel info bazel-bin --config=ci)/external/com_github_jordanlewis_gcassert/cmd/gcassert/gcassert_/gcassert $(cat ./pkg/testutils/lint/gcassert_paths.txt | sed 's|^|./pkg/|') || exit_status=$? +if [ "$exit_status" -ne 0 ]; then + echo "##teamcity[testFailed name='GcAssert']" +fi +echo "##teamcity[testFinished name='GcAssert']" + diff --git a/pkg/testutils/lint/BUILD.bazel b/pkg/testutils/lint/BUILD.bazel index 037051acfd69..ca29269326a2 100644 --- a/pkg/testutils/lint/BUILD.bazel +++ b/pkg/testutils/lint/BUILD.bazel @@ -23,6 +23,7 @@ go_test( args = ["-test.timeout=295s"], data = glob(["testdata/**"]), embed = [":lint"], + embedsrcs = ["gcassert_paths.txt"], gotags = ["lint"], tags = ["integration"], visibility = ["//build/bazelutil:__subpackages__"], diff --git a/pkg/testutils/lint/gcassert_paths.txt b/pkg/testutils/lint/gcassert_paths.txt new file mode 100644 index 000000000000..db51958416f6 --- /dev/null +++ b/pkg/testutils/lint/gcassert_paths.txt @@ -0,0 +1,29 @@ +col/coldata +col/colserde +keys +kv/kvclient/rangecache +kv/kvpb +roachpb +sql/catalog/descs +sql/colcontainer +sql/colconv +sql/colexec +sql/colexec/colexecagg +sql/colexec/colexecbase +sql/colexec/colexechash +sql/colexec/colexecjoin +sql/colexec/colexecproj +sql/colexec/colexecprojconst +sql/colexec/colexecsel +sql/colexec/colexecspan +sql/colexec/colexecwindow +sql/colfetcher +sql/opt +sql/row +storage +storage/enginepb +storage/pebbleiter +util +util/admission +util/hlc +util/intsets diff --git a/pkg/testutils/lint/lint_test.go b/pkg/testutils/lint/lint_test.go index 107aaa449bc1..0fa232924f22 100644 --- a/pkg/testutils/lint/lint_test.go +++ b/pkg/testutils/lint/lint_test.go @@ -16,6 +16,7 @@ package lint import ( "bufio" "bytes" + _ "embed" "encoding/json" "fmt" "os" @@ -41,6 +42,9 @@ import ( const cockroachDB = "github.com/cockroachdb/cockroach" +//go:embed gcassert_paths.txt +var rawGcassertPaths string + func dirCmd( dir string, name string, args ...string, ) (*exec.Cmd, *bytes.Buffer, stream.Filter, error) { @@ -2036,46 +2040,23 @@ func TestLint(t *testing.T) { t.Run("TestGCAssert", func(t *testing.T) { skip.UnderShort(t) - skip.UnderBazelWithIssue(t, 65485, "Doesn't work in Bazel -- not really sure why yet") t.Parallel() - gcassertPaths := []string{ - "../../col/coldata", - "../../col/colserde", - "../../keys", - "../../kv/kvclient/rangecache", - "../../kv/kvpb", - "../../roachpb", - "../../sql/catalog/descs", - "../../sql/colcontainer", - "../../sql/colconv", - "../../sql/colexec", - "../../sql/colexec/colexecagg", - "../../sql/colexec/colexecbase", - "../../sql/colexec/colexechash", - "../../sql/colexec/colexecjoin", - "../../sql/colexec/colexecproj", - "../../sql/colexec/colexecprojconst", - "../../sql/colexec/colexecsel", - "../../sql/colexec/colexecspan", - "../../sql/colexec/colexecwindow", - "../../sql/colfetcher", - "../../sql/opt", - "../../sql/row", - "../../storage", - "../../storage/enginepb", - "../../storage/pebbleiter", - "../../util", - "../../util/admission", - "../../util/hlc", - "../../util/intsets", + var gcassertPaths []string + for _, path := range strings.Split(rawGcassertPaths, "\n") { + path = strings.TrimSpace(path) + if path == "" { + continue + } + gcassertPaths = append(gcassertPaths, fmt.Sprintf("../../%s", path)) } // Ensure that all packages that have '//gcassert' or '// gcassert' // assertions are included into gcassertPaths. t.Run("Coverage", func(t *testing.T) { t.Parallel() + cmd, stderr, filter, err := dirCmd( pkgDir, "git", @@ -2120,13 +2101,15 @@ func TestLint(t *testing.T) { } }) - var buf strings.Builder - if err := gcassert.GCAssert(&buf, gcassertPaths...); err != nil { - t.Fatal(err) - } - output := buf.String() - if len(output) > 0 { - t.Fatalf("failed gcassert:\n%s", output) + if !bazel.BuiltWithBazel() { + var buf strings.Builder + if err := gcassert.GCAssert(&buf, gcassertPaths...); err != nil { + t.Fatal(err) + } + output := buf.String() + if len(output) > 0 { + t.Fatalf("failed gcassert:\n%s", output) + } } })