Skip to content

Commit e8adba2

Browse files
authored
Use rules_shell's sh_binary and sh_test (#4182)
Bazel 8 deletes all native shell rules. In order for other rule repositories (i.e. rules_android) to use rules_go, the references to native sh_* must be converted to rules_shell's respective versions. Unblocks bazelbuild/rules_android#278 **What type of PR is this?** Bug fix **What does this PR do? Why is it needed?** Adds rules_shell dep and properly loads sh_binary/test where applicable. **Which issues(s) does this PR fix?** Without this PR, rule repositories cannot depend upon rules_go with Bazel 8. Fixes #4181. **Other notes for review**
1 parent a985583 commit e8adba2

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed

MODULE.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bazel_dep(name = "bazel_skylib", version = "1.2.0")
1313
bazel_dep(name = "platforms", version = "0.0.10")
1414
bazel_dep(name = "rules_proto", version = "6.0.0")
1515
bazel_dep(name = "protobuf", version = "3.19.2", repo_name = "com_google_protobuf")
16+
bazel_dep(name = "rules_shell", version = "0.3.0")
1617

1718
go_sdk = use_extension("//go:extensions.bzl", "go_sdk")
1819
go_sdk.download(

WORKSPACE

+13
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,19 @@ load(
245245

246246
apple_support_dependencies()
247247

248+
http_archive(
249+
name = "rules_shell",
250+
sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53",
251+
strip_prefix = "rules_shell-0.3.0",
252+
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
253+
)
254+
255+
load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")
256+
257+
rules_shell_dependencies()
258+
259+
rules_shell_toolchains()
260+
248261
load("@googleapis//:repository_rules.bzl", "switched_rules_by_language")
249262

250263
switched_rules_by_language(

docs/doc_helpers.bzl

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
1616
load("@bazel_skylib//rules:write_file.bzl", "write_file")
1717
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
18+
load("@rules_shell//shell:sh_binary.bzl", "sh_binary")
1819

1920
def stardoc_with_diff_test(
2021
bzl_library_target,
@@ -91,7 +92,7 @@ def update_docs(
9192
content = content,
9293
)
9394

94-
native.sh_binary(
95+
sh_binary(
9596
name = name,
9697
srcs = [update_script],
9798
data = data,

go/private/repositories.bzl

+8
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ def go_rules_dependencies(force = False):
300300
name = "io_bazel_rules_go_bazel_features",
301301
)
302302

303+
wrapper(
304+
http_archive,
305+
name = "rules_shell",
306+
sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53",
307+
strip_prefix = "rules_shell-0.3.0",
308+
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
309+
)
310+
303311
def _maybe(repo_rule, name, **kwargs):
304312
if name not in native.existing_rules():
305313
repo_rule(name = name, **kwargs)

go/private/tools/files_equal_test.bzl

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
"""Tests that two files contain the same data."""
1717

18+
load("@rules_shell//shell:sh_test.bzl", "sh_test")
19+
1820
def files_equal_test(name, golden, actual, error_message = None, **kwargs):
1921
# This genrule creates a Bash script: the source of the actual test.
2022
# The script:
@@ -105,7 +107,7 @@ fi
105107
eof""",
106108
)
107109

108-
native.sh_test(
110+
sh_test(
109111
name = name,
110112
srcs = [name + "-src.sh"],
111113
data = [

0 commit comments

Comments
 (0)