Skip to content

Commit edb1a99

Browse files
authored
Merge pull request stackb#323 from stackb/bazel-gazelle-031
Upgrade bazelbuild/bazel-gazelle to 0.31.0
2 parents c4a724b + fd61b8e commit edb1a99

File tree

330 files changed

+20900
-19652
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

330 files changed

+20900
-19652
lines changed

.bazelci/presubmit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ bazel: 5.1.1
66
tasks:
77
default_workspace_ubuntu1804:
88
platform: ubuntu1804
9+
build_targets:
10+
- "@protoapis//..."
911
test_targets:
1012
- //example/...
1113
- //language/...
@@ -19,6 +21,8 @@ tasks:
1921
- --deleted_packages=//plugin/grpc-ecosystem/grpc-gateway
2022
default_workspace_macos:
2123
platform: macos
24+
build_targets:
25+
- "@protoapis//..."
2226
test_targets:
2327
- //example/...
2428
- //language/...

.bazelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
common --enable_platform_specific_config
2+
3+
build:windows --cxxopt='/std:c++14'
4+
build:windows --host_cxxopt='/std:c++14'
5+
build:linux --cxxopt='-std=c++14'
6+
build:linux --host_cxxopt='-std=c++14'
7+
build:macos --cxxopt='-std=c++14'
8+
build:macos --host_cxxopt='-std=c++14'
9+
build:freebsd --cxxopt='-std=c++14'
10+
build:freebsd --host_cxxopt='-std=c++14'
11+
112
build:bazelci --deleted_packages=docs
13+
214
# workaround for scala
315
build --incompatible_java_common_parameters=false
16+

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ gazelle(
4949

5050
filegroup(
5151
name = "all_files",
52+
testonly = True,
5253
srcs = [
5354
"BUILD.bazel",
5455
"WORKSPACE",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ test:
2828

2929
.PHONY: get
3030
get:
31-
$(BAZEL) run @go_sdk//:bin/go -- get github.com/bazelbuild/bazel-gazelle@v0.27.0
31+
$(BAZEL) run @go_sdk//:bin/go -- get github.com/bazelbuild/bazel-gazelle@v0.31.0
3232
$(BAZEL) run @go_sdk//:bin/go -- mod download github.com/bazelbuild/buildtools
3333
$(BAZEL) run @go_sdk//:bin/go -- mod vendor

WORKSPACE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
workspace(name = "build_stack_rules_proto")
22

3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
35
# gazelle:repo bazel_gazelle
46

57
# ----------------------------------------------------
68
# Toolchain-Related
79
# ----------------------------------------------------
810

911
register_toolchains("//toolchain:standard")
12+
# alternatively:
13+
# register_toolchains("//toolchain:prebuilt")
1014

1115
# ----------------------------------------------------
1216
# Top-Level Dependency Trees
@@ -95,6 +99,18 @@ go_deps()
9599
# Core gRPC
96100
# ----------------------------------------------------
97101

102+
http_archive(
103+
name = "com_google_absl",
104+
generator_function = "grpc_deps",
105+
generator_name = "com_google_absl",
106+
sha256 = "9a2b5752d7bfade0bdeee2701de17c9480620f8b237e1964c1b9967c75374906",
107+
strip_prefix = "abseil-cpp-20230125.2",
108+
urls = [
109+
"https://storage.googleapis.com/grpc-bazel-mirror/github.com/abseil/abseil-cpp/archive/20230125.2.tar.gz",
110+
"https://github.com/abseil/abseil-cpp/archive/20230125.2.tar.gz",
111+
],
112+
)
113+
98114
load(
99115
"@com_github_grpc_grpc//bazel:grpc_deps.bzl",
100116
"grpc_deps",
@@ -120,6 +136,7 @@ load(
120136
maven_install(
121137
artifacts = IO_GRPC_GRPC_JAVA_ARTIFACTS,
122138
generate_compat_repositories = True,
139+
maven_install_json = "//:maven_install.json",
123140
override_targets = IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS,
124141
repositories = [
125142
"https://repo.maven.apache.org/maven2/",
@@ -225,3 +242,11 @@ load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories")
225242
node_repositories()
226243

227244
register_toolchains("//toolchain:nodejs")
245+
246+
# ----------------------------------------------------
247+
# proto_repositories
248+
# ----------------------------------------------------
249+
250+
load("//:proto_repositories.bzl", "proto_repositories")
251+
252+
proto_repositories()

cmd/gazelle/BUILD.bazel

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ go_library(
1717
tags = ["manual"],
1818
visibility = ["//visibility:public"],
1919
deps = [
20+
"//cmd/gazelle/internal/module",
21+
"//cmd/gazelle/internal/wspace",
2022
"//language/protobuf",
2123
"@bazel_gazelle//config:go_default_library",
2224
"@bazel_gazelle//flag:go_default_library",
@@ -58,6 +60,11 @@ go_test(
5860

5961
filegroup(
6062
name = "all_files",
61-
srcs = ["BUILD.bazel"] + glob(["*.go"]),
63+
testonly = True,
64+
srcs = glob(["*.go"]) + [
65+
"BUILD.bazel",
66+
"//cmd/gazelle/internal/module:all_files",
67+
"//cmd/gazelle/internal/wspace:all_files",
68+
],
6269
visibility = ["//:__pkg__"],
6370
)

cmd/gazelle/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# cmd/gazelle
2+
3+
This is essentially a copy of the files in bazelbuild/bazel-gazelle/cmd/gazelle.
4+
5+
To upgrade gazelle, one must:
6+
7+
- `go get` the correct version and update `go.mod` file
8+
- `make tidy` to propagate changes to `go.sum` and `go_repositories.bzl`.
9+
- update the version of @bazel_gazelle in `deps/BUILD.bazel`, then run `make
10+
deps` to regenerate the actual deps tree.
11+
- Compare changes in the source repo to the files here. It's easiest to just
12+
copy over each file and see where the diffs are. Make sure `langs.go`
13+
includes the `github.com/stackb/rules_proto/language/protobuf`. Internal
14+
packages referenced must also be copied over (ugh). There's probably a more elegant solution to keeping a modified copy of gazelle binary here.
15+
- Since the `proto_gazelle.bzl` rule uses
16+
`@bazel_gazelle//internal:gazelle.bash.in`, changes there must remain
17+
compatible with proto_gazelle. Look at the diff there and make sure the proto_gazelle_impl is satifying the needs of that template.
18+
- Remember that this `cmd/gazelle` must be buildable via the standard go
19+
toolchain (see proto_repository_tools.bzl):
20+
21+
```py
22+
args = [
23+
go_tool,
24+
"install",
25+
"-ldflags",
26+
"-w -s",
27+
"-gcflags",
28+
"all=-trimpath=" + env["GOPATH"],
29+
"-asmflags",
30+
"all=-trimpath=" + env["GOPATH"],
31+
"github.com/stackb/rules_proto/cmd/gazelle",
32+
]
33+
result = env_execute(ctx, args, environment = env)
34+
if result.return_code:
35+
fail("failed to build tools: " + result.stderr)
36+
```
37+
38+
So any and all deps must be in the vendor tree.

cmd/gazelle/diff.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/pmezard/go-difflib/difflib"
2828
)
2929

30-
var exitError = fmt.Errorf("encountered changes while running diff")
30+
var errExit = fmt.Errorf("encountered changes while running diff")
3131

3232
func diffFile(c *config.Config, f *rule.File) error {
3333
rel, err := filepath.Rel(c.RepoRoot, f.Path)
@@ -36,7 +36,11 @@ func diffFile(c *config.Config, f *rule.File) error {
3636
}
3737
rel = filepath.ToSlash(rel)
3838

39-
date := "1970-01-01 00:00:00.000000000 +0000"
39+
// The epoch timestamp is assumed to represent file creation/deletion events
40+
// by some tools, so use a dummy timestamp that is one ns past the epoch.
41+
// See https://github.com/bazelbuild/bazel-gazelle/issues/1528.
42+
date := "1970-01-01 00:00:00.000000001 +0000"
43+
4044
diff := difflib.UnifiedDiff{
4145
Context: 3,
4246
FromDate: date,
@@ -60,7 +64,7 @@ func diffFile(c *config.Config, f *rule.File) error {
6064
}
6165

6266
if len(f.Content) != 0 {
63-
diff.A = difflib.SplitLines(string(f.Content))
67+
diff.A = difflib.SplitLines(string(f.Content))
6468
}
6569

6670
diff.B = difflib.SplitLines(string(newContent))
@@ -80,7 +84,7 @@ func diffFile(c *config.Config, f *rule.File) error {
8084
return fmt.Errorf("error diffing %s: %v", f.Path, err)
8185
}
8286
if ds, _ := difflib.GetUnifiedDiffString(diff); ds != "" {
83-
return exitError
87+
return errExit
8488
}
8589

8690
return nil

0 commit comments

Comments
 (0)