Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use rules_shell for shell targets #1960

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ bazel_dep(name = "protobuf", version = "3.19.6", repo_name = "com_google_protobu
bazel_dep(name = "rules_go", version = "0.50.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_license", version = "1.0.0")
bazel_dep(name = "rules_proto", version = "4.0.0")
bazel_dep(name = "rules_shell", version = "0.2.0")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")

Expand Down
10 changes: 8 additions & 2 deletions def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ load(
"@bazel_skylib//lib:shell.bzl",
"shell",
)
load("@rules_shell//shell:sh_binary.bzl",
"sh_binary"
)
load("@rules_shell//shell:sh_test.bzl",
"sh_test"
)
load(
"//internal:gazelle_binary.bzl",
_gazelle_binary = "gazelle_binary_wrapper",
Expand Down Expand Up @@ -218,7 +224,7 @@ def gazelle(name, **kwargs):
tags_set = {t: "" for t in kwargs.pop("tags", [])}
tags_set["manual"] = ""
tags = tags_set.keys()
native.sh_binary(
sh_binary(
name = name,
tags = tags,
srcs = [runner_name],
Expand All @@ -242,7 +248,7 @@ def gazelle_test(name, size = None, timeout = None, **kwargs):
tags_set["no-cache"] = ""
tags_set["external"] = ""
tags = tags_set.keys()
native.sh_test(
sh_test(
name = name,
srcs = [runner_name],
visibility = visibility,
Expand Down
13 changes: 13 additions & 0 deletions deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ def gazelle_dependencies(
sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
)

# We are not able to call rules_shell's dependency macros without introducing new levels of
# such macros to gazelle. With Bazel < 8, rules_shell forwards to the native sh_* rules, so
# its dependencies are not needed. With Bazel 8, rules_shell is automatically loaded by Bazel.
_maybe(
http_archive,
name = "rules_shell",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
"https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
],
sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53",
strip_prefix = "rules_shell-0.3.0",
)
if go_sdk:
go_repository_cache(
name = "bazel_gazelle_go_repository_cache",
Expand Down
1 change: 1 addition & 0 deletions docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ the stardoc repository, which is not a dependency users should install.
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")

# gazelle:ignore
_DOC_SRCS = {
Expand Down
5 changes: 4 additions & 1 deletion tests/bzl_deps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ load(":bzl_test.bzl", "bzl_test")
bzl_test(
name = "def_bzl_test",
src = "do_nothing_macro.bzl",
deps = ["//:def"],
deps = [
"//:def",
"@rules_shell//shell:rules_bzl",
],
)
1 change: 1 addition & 0 deletions tests/cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load(":env_variables_test.bzl", "env_variables_test_suite")

env_variables_test_suite()
1 change: 1 addition & 0 deletions tests/visibility_attr/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
load("//:def.bzl", "gazelle")

gazelle(
Expand Down
1 change: 1 addition & 0 deletions tests/visibility_attr/child/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_shell//shell:sh_test.bzl", "sh_test")

build_test(
name = "visibility_test",
Expand Down
10 changes: 8 additions & 2 deletions vendor/github.com/bazelbuild/buildtools/build/build_defs.bzl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.