Skip to content

Commit 33d8d2b

Browse files
authored
Merge branch 'bazelbuild:main' into negation_support
2 parents 0bccf62 + 60abca8 commit 33d8d2b

File tree

12 files changed

+246
-47
lines changed

12 files changed

+246
-47
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
gazelle/

MODULE.bazel

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module(
22
name = "bazel_skylib",
33
compatibility_level = 1,
4+
# If you change this, please also update @bazel_skylib_gazelle_plugin//:MODULE.bazel
45
version = "1.3.0",
56
)
67

@@ -13,21 +14,7 @@ bazel_dep(name = "platforms", version = "0.0.4")
1314

1415
### INTERNAL ONLY - lines after this are not included in the release packaging.
1516

16-
# Gazelle extension is experimental
17-
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.33.0")
18-
bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.26.0")
19-
20-
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
21-
22-
go_deps.module(
23-
path = "github.com/bazelbuild/buildtools",
24-
sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=",
25-
version = "v0.0.0-20220531122519-a43aed7014c8",
26-
)
27-
28-
use_repo(go_deps, "com_github_bazelbuild_buildtools")
29-
3017
# Build-only / test-only dependencies
3118
bazel_dep(name = "stardoc", dev_dependency = True, repo_name = "io_bazel_stardoc", version = "0.5.3")
3219
bazel_dep(name = "rules_pkg", dev_dependency = True, version = "0.5.1")
33-
bazel_dep(name = "rules_cc", dev_dependency = True, version = "0.0.1")
20+
bazel_dep(name = "rules_cc", dev_dependency = True, version = "0.0.2")

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,38 @@ then you probably forgot to load and call `bazel_skylib_workspace()` in your
132132

133133
See the [maintaner's guide](docs/maintainers_guide.md) for instructions for
134134
cutting a new release.
135+
136+
## Gazelle Plugin
137+
138+
`bazel_skylib` ships with a [gazelle](https://github.com/bazelbuild/bazel-gazelle)
139+
plugin to generate `bzl_library` entries in build files. To use this, in your
140+
`WORKSPACE`:
141+
142+
```starlark
143+
load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace")
144+
145+
bazel_skylib_gazelle_plugin_workspace()
146+
147+
load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_setup"
148+
149+
bazel_skylib_gazelle_plugin_setup()
150+
```
151+
152+
You may then include the plugin using code similar to this in your `BUILD.bazel`
153+
file:
154+
155+
```starlark
156+
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
157+
158+
gazelle(
159+
name = "gazelle",
160+
gazelle = ":gazelle_bin",
161+
)
162+
163+
gazelle_binary(
164+
name = "gazelle_bin",
165+
languages = DEFAULT_LANGUAGES + [
166+
"@bazel_skylib_gazelle_plugin//gazelle/bzl",
167+
],
168+
)
169+
```

WORKSPACE

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@ workspace(name = "bazel_skylib")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
5+
load(":workspace.bzl", "bazel_skylib_workspace")
56

6-
maybe(
7-
name = "io_bazel_rules_go",
8-
repo_rule = http_archive,
9-
sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369",
10-
urls = [
11-
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip",
12-
"https://github.com/bazelbuild/rules_go/releases/download/v0.33.0/rules_go-v0.33.0.zip",
13-
],
7+
bazel_skylib_workspace()
8+
9+
local_repository(
10+
name = "bazel_skylib_gazelle_plugin",
11+
path = "gazelle",
1412
)
1513

16-
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
14+
load("@bazel_skylib_gazelle_plugin//:workspace.bzl", "bazel_skylib_gazelle_plugin_workspace")
15+
16+
bazel_skylib_gazelle_plugin_workspace()
1717

18-
go_rules_dependencies()
18+
load("@bazel_skylib_gazelle_plugin//:setup.bzl", "bazel_skylib_gazelle_plugin_setup")
1919

20-
go_register_toolchains(version = "1.17.1")
20+
bazel_skylib_gazelle_plugin_setup()
2121

2222
# Below this line is for documentation generation only,
2323
# and should thus not be included by dependencies on
@@ -64,22 +64,3 @@ maybe(
6464
load("//lib:unittest.bzl", "register_unittest_toolchains")
6565

6666
register_unittest_toolchains()
67-
68-
# Provide a repository hint for Gazelle to inform it that the go package
69-
# github.com/bazelbuild/rules_go is available from io_bazel_rules_go and it
70-
# doesn't need to duplicatively fetch it.
71-
# gazelle:repository go_repository name=io_bazel_rules_go importpath=github.com/bazelbuild/rules_go
72-
http_archive(
73-
name = "bazel_gazelle",
74-
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
75-
urls = [
76-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
77-
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
78-
],
79-
)
80-
# Another Gazelle repository hint.
81-
# gazelle:repository go_repository name=bazel_gazelle importpath=github.com/bazelbuild/bazel-gazelle/testtools
82-
83-
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
84-
85-
gazelle_dependencies()

gazelle/BUILD

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2+
3+
# The files needed for distribution
4+
filegroup(
5+
name = "distribution",
6+
srcs = glob(
7+
["*"],
8+
allow_empty = True,
9+
),
10+
visibility = [
11+
"//:__pkg__",
12+
],
13+
)
14+
15+
bzl_library(
16+
name = "setup",
17+
srcs = ["setup.bzl"],
18+
visibility = ["//visibility:public"],
19+
deps = [
20+
"@bazel_gazelle//:deps",
21+
"@io_bazel_rules_go//go:deps",
22+
],
23+
)
24+
25+
bzl_library(
26+
name = "workspace",
27+
srcs = ["workspace.bzl"],
28+
visibility = ["//visibility:public"],
29+
deps = [
30+
"@bazel_skylib//:workspace",
31+
"@bazel_tools//tools/build_defs/repo:http.bzl",
32+
"@bazel_tools//tools/build_defs/repo:utils.bzl",
33+
],
34+
)

gazelle/MODULE.bazel

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
module(
2+
name = "bazel_skylib_gazelle_plugin",
3+
compatibility_level = 1,
4+
# If you change this, please also update @bazel_gazelle//:MODULE.bazel
5+
version = "1.3.0",
6+
)
7+
8+
bazel_dep(name = "bazel_skylib", version = "1.3.0")
9+
bazel_dep(name = "gazelle", repo_name = "bazel_gazelle", version = "0.28.0")
10+
bazel_dep(name = "rules_go", repo_name = "io_bazel_rules_go", version = "0.35.0")
11+
12+
go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
13+
14+
go_sdk.download(
15+
name = "go_sdk",
16+
version = "1.18",
17+
)
18+
19+
use_repo(go_sdk, "go_sdk")
20+
21+
register_toolchains("@go_sdk//:all")
22+
23+
go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
24+
25+
go_deps.module(
26+
path = "github.com/bazelbuild/buildtools",
27+
sum = "h1:fmdo+fvvWlhldUcqkhAMpKndSxMN3vH5l7yow5cEaiQ=",
28+
version = "v0.0.0-20220531122519-a43aed7014c8",
29+
)
30+
31+
use_repo(go_deps, "com_github_bazelbuild_buildtools")

gazelle/WORKSPACE

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
workspace(name = "bazel_skylib_gazelle_plugin")
2+
3+
local_repository(
4+
name = "bazel_skylib",
5+
path = "..",
6+
)
7+
8+
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
9+
10+
bazel_skylib_workspace()
11+
12+
load(":workspace.bzl", "bazel_skylib_gazelle_plugin_workspace")
13+
14+
bazel_skylib_gazelle_plugin_workspace()
15+
16+
load(":setup.bzl", "bazel_skylib_gazelle_plugin_setup")
17+
18+
bazel_skylib_gazelle_plugin_setup()
19+
20+
# Provide a repository hint for Gazelle to inform it that the go package
21+
# github.com/bazelbuild/rules_go is available from io_bazel_rules_go and it
22+
# doesn't need to duplicatively fetch it.
23+
# gazelle:repository go_repository name=io_bazel_rules_go importpath=github.com/bazelbuild/rules_go
24+
# Another Gazelle repository hint.
25+
# gazelle:repository go_repository name=bazel_gazelle importpath=github.com/bazelbuild/bazel-gazelle/testtools

gazelle/WORKSPACE.bzlmod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
workspace(name = "bazel_skylib_gazelle_plugin")
2+
3+
# Provide a repository hint for Gazelle to inform it that the go package
4+
# github.com/bazelbuild/rules_go is available from io_bazel_rules_go and it
5+
# doesn't need to duplicatively fetch it.
6+
# gazelle:repository go_repository name=io_bazel_rules_go importpath=github.com/bazelbuild/rules_go
7+
# Another Gazelle repository hint.
8+
# gazelle:repository go_repository name=bazel_gazelle importpath=github.com/bazelbuild/bazel-gazelle/testtools

gazelle/bzl/BUILD

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,25 @@ gazelle(
5151
name = "gazelle",
5252
gazelle = ":gazelle-skylib",
5353
)
54+
55+
# The files needed for distribution
56+
# A fake testdata directory is created so that
57+
# the build file has nothing missing, but we
58+
# do not bloat the distribution tarball
59+
filegroup(
60+
name = "distribution",
61+
srcs = glob(["*.go"]) + [
62+
"BUILD",
63+
":fake-testdata",
64+
],
65+
visibility = [
66+
"//:__pkg__",
67+
"//distribution:__pkg__",
68+
],
69+
)
70+
71+
genrule(
72+
name = "fake-testdata",
73+
outs = ["testdata"],
74+
cmd = "touch $@",
75+
)

gazelle/bzl/gazelle_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
var gazellePath = findGazelle()
3131

32-
const testDataPath = "gazelle/bzl/testdata/"
32+
const testDataPath = "bzl/testdata/"
3333

3434
// TestGazelleBinary runs a gazelle binary with starlib installed on each
3535
// directory in `testdata/*`. Please see `testdata/README.md` for more
@@ -135,7 +135,7 @@ func testPath(t *testing.T, name string, files []bazel.RunfileEntry) {
135135
}
136136

137137
func findGazelle() string {
138-
gazellePath, ok := bazel.FindBinary("gazelle/bzl", "gazelle-skylib")
138+
gazellePath, ok := bazel.FindBinary("bzl", "gazelle-skylib")
139139
if !ok {
140140
panic("could not find gazelle binary")
141141
}

0 commit comments

Comments
 (0)