Skip to content

Commit

Permalink
Use rules_shell's sh_binary and sh_test (#4182)
Browse files Browse the repository at this point in the history
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**
  • Loading branch information
ted-xie authored Nov 26, 2024
1 parent a985583 commit e8adba2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ bazel_dep(name = "bazel_skylib", version = "1.2.0")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_proto", version = "6.0.0")
bazel_dep(name = "protobuf", version = "3.19.2", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_shell", version = "0.3.0")

go_sdk = use_extension("//go:extensions.bzl", "go_sdk")
go_sdk.download(
Expand Down
13 changes: 13 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ load(

apple_support_dependencies()

http_archive(
name = "rules_shell",
sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53",
strip_prefix = "rules_shell-0.3.0",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
)

load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")

rules_shell_dependencies()

rules_shell_toolchains()

load("@googleapis//:repository_rules.bzl", "switched_rules_by_language")

switched_rules_by_language(
Expand Down
3 changes: 2 additions & 1 deletion docs/doc_helpers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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")

def stardoc_with_diff_test(
bzl_library_target,
Expand Down Expand Up @@ -91,7 +92,7 @@ def update_docs(
content = content,
)

native.sh_binary(
sh_binary(
name = name,
srcs = [update_script],
data = data,
Expand Down
8 changes: 8 additions & 0 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,14 @@ def go_rules_dependencies(force = False):
name = "io_bazel_rules_go_bazel_features",
)

wrapper(
http_archive,
name = "rules_shell",
sha256 = "d8cd4a3a91fc1dc68d4c7d6b655f09def109f7186437e3f50a9b60ab436a0c53",
strip_prefix = "rules_shell-0.3.0",
url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.3.0/rules_shell-v0.3.0.tar.gz",
)

def _maybe(repo_rule, name, **kwargs):
if name not in native.existing_rules():
repo_rule(name = name, **kwargs)
Expand Down
4 changes: 3 additions & 1 deletion go/private/tools/files_equal_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

load("@rules_shell//shell:sh_test.bzl", "sh_test")

def files_equal_test(name, golden, actual, error_message = None, **kwargs):
# This genrule creates a Bash script: the source of the actual test.
# The script:
Expand Down Expand Up @@ -105,7 +107,7 @@ fi
eof""",
)

native.sh_test(
sh_test(
name = name,
srcs = [name + "-src.sh"],
data = [
Expand Down

0 comments on commit e8adba2

Please sign in to comment.