Skip to content

Commit 17cda10

Browse files
authored
bazel: add bazel mirror (pingcap#39072)
close pingcap#39081
1 parent 2ff2d11 commit 17cda10

12 files changed

+7561
-2174
lines changed

BUILD.bazel

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
load("@bazel_gazelle//:def.bzl", "gazelle")
22

3+
exports_files([
4+
"DEPS.bzl",
5+
"WORKSPACE",
6+
"go.mod",
7+
"go.sum",
8+
])
9+
310
# gazelle:proto disable_global
411
# gazelle:prefix github.com/pingcap/tidb
512
# gazelle:exclude tidb-binlog/proto/proto

DEPS.bzl

+6,785-2,169
Large diffs are not rendered by default.

Makefile

+16-1
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,8 @@ generate_grafana_scripts:
433433
bazel_ci_prepare:
434434
bazel $(BAZEL_GLOBAL_CONFIG) run $(BAZEL_CMD_CONFIG) //:gazelle
435435
bazel $(BAZEL_GLOBAL_CONFIG) run $(BAZEL_CMD_CONFIG) //:gazelle -- update-repos -from_file=go.mod -to_macro DEPS.bzl%go_deps -build_file_proto_mode=disable
436+
bazel $(BAZEL_GLOBAL_CONFIG) run $(BAZEL_CMD_CONFIG) //cmd/mirror:mirror -- --mirror> tmp.txt
437+
mv tmp.txt DEPS.bzl
436438
bazel $(BAZEL_GLOBAL_CONFIG) run $(BAZEL_CMD_CONFIG) \
437439
--run_under="cd $(CURDIR) && " \
438440
//tools/tazel:tazel
@@ -448,6 +450,10 @@ bazel_prepare:
448450
bazel run \
449451
--run_under="cd $(CURDIR) && " \
450452
//tools/tazel:tazel
453+
$(eval $@TMP_OUT := $(shell mktemp -d -t tidbbzl.XXXXXX))
454+
bazel run //cmd/mirror -- --mirror> $($@TMP_OUT)/tmp.txt
455+
cp $($@TMP_OUT)/tmp.txt DEPS.bzl
456+
rm -rf $($@TMP_OUT)
451457

452458
bazel_ci_prepare_rbe:
453459
bazel run //:gazelle
@@ -473,7 +479,7 @@ bazel_coverage_test: check-bazel-prepare failpoint-enable bazel_ci_prepare
473479
-- //... -//cmd/... -//tests/graceshutdown/... \
474480
-//tests/globalkilltest/... -//tests/readonlytest/... -//br/pkg/task:task_test -//tests/realtikvtest/...
475481

476-
bazel_build: bazel_ci_prepare
482+
bazel_build:
477483
mkdir -p bin
478484
bazel $(BAZEL_GLOBAL_CONFIG) build $(BAZEL_CMD_CONFIG) \
479485
//... --//build:with_nogo_flag=true
@@ -555,3 +561,12 @@ docker:
555561

556562
docker-test:
557563
docker buildx build --platform linux/amd64,linux/arm64 --push -t "$(DOCKERPREFIX)tidb:latest" --build-arg 'GOPROXY=$(shell go env GOPROXY),' -f Dockerfile .
564+
565+
bazel_mirror:
566+
$(eval $@TMP_OUT := $(shell mktemp -d -t tidbbzl.XXXXXX))
567+
bazel $(BAZEL_GLOBAL_CONFIG) run $(BAZEL_CMD_CONFIG) //cmd/mirror:mirror -- --mirror> $($@TMP_OUT)/tmp.txt
568+
cp $($@TMP_OUT)/tmp.txt DEPS.bzl
569+
rm -rf $($@TMP_OUT)
570+
571+
bazel_sync:
572+
bazel $(BAZEL_GLOBAL_CONFIG) sync $(BAZEL_SYNC_CONFIG)

Makefile.common

+1
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,5 @@ TEST_COVERAGE_DIR := "test_coverage"
122122
ifneq ("$(CI)", "")
123123
BAZEL_GLOBAL_CONFIG := --output_user_root=/home/jenkins/.tidb/tmp
124124
BAZEL_CMD_CONFIG := --config=ci --repository_cache=/home/jenkins/.tidb/tmp
125+
BAZEL_SYNC_CONFIG := --repository_cache=/home/jenkins/.tidb/tmp
125126
endif

build/nogo_config.json

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
"exclude_files": {
161161
"parser/parser.go": "parser/parser.go code",
162162
"external/": "no need to vet third party code",
163+
".cgo/": "no need to cgo code",
163164
".*_generated\\.go$": "ignore generated code",
164165
".*_/testmain\\.go$": "ignore code"
165166
}
@@ -278,6 +279,7 @@
278279
"/cgo/": "ignore cgo code",
279280
"/rules_go_work-*": "ignore generated code",
280281
"tools/check/ut.go": "ignore tools/check code",
282+
"cmd/mirror": "ignore cmd/mirror code",
281283
"tools/check/xprog.go": "ignore tools/check code",
282284
"cmd/pluginpkg/pluginpkg.go": "ignore cmd/pluginpkg code",
283285
"tools/check/xprog.go:": "ignore tools/check code",
@@ -1155,6 +1157,7 @@
11551157
"prealloc": {
11561158
"exclude_files": {
11571159
"parser/parser.go": "parser/parser.go code",
1160+
"cmd/mirror": "cmd/mirror code",
11581161
"external/": "no need to vet third party code",
11591162
".*_generated\\.go$": "ignore generated code",
11601163
"parser/yy_parser.go": "ignore generated code",
@@ -1164,6 +1167,7 @@
11641167
"predeclared": {
11651168
"exclude_files": {
11661169
"external/": "no need to vet third party code",
1170+
"cmd/mirror": "no need to mirror",
11671171
".*_generated\\.go$": "ignore generated code",
11681172
"parser/yy_parser.go": "ignore generated code",
11691173
"parser/parser.go": "ignore generated code",

build/patches/io_etcd_go_etcd_api_v3.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ diff -uprN old/io_etcd_go_etcd_api_v3/etcdserverpb/BUILD.bazel new/io_etcd_go_et
66
"@com_github_gogo_protobuf//gogoproto",
77
"@com_github_golang_protobuf//proto:go_default_library",
88
- "@go_googleapis//google/api:annotations_go_proto",
9-
+ "@org_golang_google_genproto_googleapis_api//annotations:annotations",
9+
+ "@org_golang_google_genproto//googleapis/api/annotations:annotations",
1010
"@org_golang_google_grpc//:go_default_library",
1111
"@org_golang_google_grpc//codes",
1212
"@org_golang_google_grpc//status",

cmd/mirror/BUILD.bazel

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
2+
3+
go_library(
4+
name = "mirror_lib",
5+
srcs = [
6+
"mirror.go",
7+
"skylarkutil.go",
8+
],
9+
importpath = "github.com/pingcap/tidb/cmd/mirror",
10+
visibility = ["//visibility:private"],
11+
deps = [
12+
"@com_github_google_skylark//syntax",
13+
"@com_google_cloud_go_storage//:storage",
14+
"@io_bazel_rules_go//go/tools/bazel:go_default_library",
15+
"@org_golang_google_api//googleapi",
16+
"@org_golang_x_exp//slices",
17+
"@org_golang_x_sync//errgroup",
18+
],
19+
)
20+
21+
go_binary(
22+
name = "mirror",
23+
data = [
24+
"//:DEPS.bzl",
25+
"//:go.mod",
26+
"//:go.sum",
27+
"//build/patches:all_patches",
28+
"//parser:go.mod",
29+
"//parser:go.sum",
30+
"@go_sdk//:files",
31+
],
32+
embed = [":mirror_lib"],
33+
visibility = ["//visibility:public"],
34+
)

0 commit comments

Comments
 (0)