-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bazel: generate contents of
pkg/BUILD.bazel
in make bazel-generate
Previously, the `ALL_TESTS` list was hardcoded, leaving a possibility that it would fall out of sync with the rest of tree. Now we use `bazel query` to enumerate all the tests in the repo generate the contents of `pkg/BUILD.bazel` accordingly. Since this is part of `make bazel-generate`, CI should ensure that this never falls out of sync again. A couple tweaks to the build scripts were necessary to make this work: - To avoid duplication, I moved the `make bazel-generate` logic to its own script at `build/bazelutil/bazel-generate.sh`. - Refactored the Bazel image tag to one script in `build/teamcity-bazel-support.sh` so now there's only one place to update when a new builder image is created. - In `build/teamcity-check.sh`, we were using `builder.sh` to run `make bazel-generate` in CI, but `builder.sh` [is known to work poorly w/ Bazel](#59224). Instead I directly use an appropriate `docker run`. This fixes some build errors that would occur otherwise. Release note: None
- Loading branch information
1 parent
14ac1cf
commit 67200f6
Showing
10 changed files
with
103 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.pb.* -diff | ||
*.eg.go -diff | ||
DEPS.bzl -diff | ||
pkg/BUILD.bazel -diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -exuo pipefail | ||
|
||
bazel run //:gazelle -- update-repos -from_file=go.mod -build_file_proto_mode=disable_global -to_macro=DEPS.bzl%go_deps | ||
bazel run //:gazelle | ||
bazel run //pkg/cmd/generate-test-suites --run_under="cd $PWD && " > pkg/BUILD.bazel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BAZEL_IMAGE=cockroachdb/bazel:20210201-174432 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "generate-test-suites_lib", | ||
srcs = ["main.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/cmd/generate-test-suites", | ||
visibility = ["//visibility:private"], | ||
) | ||
|
||
go_binary( | ||
name = "generate-test-suites", | ||
embed = [":generate-test-suites_lib"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"sort" | ||
"strings" | ||
) | ||
|
||
func main() { | ||
// First list all tests. | ||
buf, err := exec.Command("bazel", "query", "kind(go_test, //pkg/...)", "--output=label").Output() | ||
if err != nil { | ||
log.Printf("Could not query Bazel tests: got error %v", err) | ||
os.Exit(1) | ||
} | ||
labels := strings.Split(string(buf[:]), "\n") | ||
sort.Slice(labels, func(i, j int) bool { return labels[i] < labels[j] }) | ||
|
||
// Write the output to stdout | ||
fmt.Println(`# Code generated by generate-test-suites, DO NOT EDIT. | ||
# gazelle:proto_strip_import_prefix /pkg | ||
ALL_TESTS = [`) | ||
for _, label := range labels { | ||
if len(label) > 0 { | ||
fmt.Printf(" %q,\n", label) | ||
} | ||
} | ||
fmt.Println(`] | ||
# These suites run only the tests with the appropriate "size" (excepting those | ||
# tagged "broken_in_bazel") [1]. Note that tests have a default timeout | ||
# depending on the size [2]. | ||
# [1] https://docs.bazel.build/versions/master/be/general.html#test_suite | ||
# [2] https://docs.bazel.build/versions/master/be/common-definitions.html#common-attributes-tests`) | ||
|
||
for _, size := range []string{"small", "medium", "large", "enormous"} { | ||
fmt.Printf(` | ||
test_suite( | ||
name = "%[1]s_tests", | ||
tags = [ | ||
"-broken_in_bazel", | ||
"%[1]s", | ||
], | ||
tests = ALL_TESTS, | ||
) | ||
`, size) | ||
} | ||
} |