From 723446f9c05742ed1babc02d6722cae129bd4a63 Mon Sep 17 00:00:00 2001 From: Ted Xie Date: Fri, 18 Oct 2024 17:40:06 -0400 Subject: [PATCH] Use rules_shell for shell targets Fixes https://github.com/bazel-contrib/bazel-gazelle/issues/1959 --- MODULE.bazel | 1 + WORKSPACE | 13 +++++++++++++ def.bzl | 5 ++++- docs/BUILD.bazel | 1 + tests/bzl_deps/BUILD.bazel | 5 ++++- tests/cli/BUILD.bazel | 1 + tests/visibility_attr/BUILD.bazel | 1 + tests/visibility_attr/child/BUILD.bazel | 1 + 8 files changed, 26 insertions(+), 2 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index ab60f8314..28a0f2fbc 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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") diff --git a/WORKSPACE b/WORKSPACE index c9a7c690b..d8707123c 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -64,6 +64,19 @@ http_archive( ], ) +http_archive( + name = "rules_shell", + sha256 = "410e8ff32e018b9efd2743507e7595c26e2628567c42224411ff533b57d27c28", + strip_prefix = "rules_shell-0.2.0", + url = "https://github.com/bazelbuild/rules_shell/releases/download/v0.2.0/rules_shell-v0.2.0.tar.gz", +) + +load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains") + +rules_shell_dependencies() + +rules_shell_toolchains() + # Stardoc pulls in a lot of deps, which we need to declare here. load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") diff --git a/def.bzl b/def.bzl index e5fa09787..f19fcf0ff 100644 --- a/def.bzl +++ b/def.bzl @@ -20,6 +20,9 @@ load( "@bazel_skylib//lib:shell.bzl", "shell", ) +load("@rules_shell//shell:sh_binary.bzl", + "sh_binary" +) load( "//internal:gazelle_binary.bzl", _gazelle_binary = "gazelle_binary_wrapper", @@ -218,7 +221,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], diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 6ce4ede3f..39cc1089b 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -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 = { diff --git a/tests/bzl_deps/BUILD.bazel b/tests/bzl_deps/BUILD.bazel index 86679e6b9..d045f79a6 100644 --- a/tests/bzl_deps/BUILD.bazel +++ b/tests/bzl_deps/BUILD.bazel @@ -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", + ], ) diff --git a/tests/cli/BUILD.bazel b/tests/cli/BUILD.bazel index df64d6360..154500b39 100644 --- a/tests/cli/BUILD.bazel +++ b/tests/cli/BUILD.bazel @@ -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() diff --git a/tests/visibility_attr/BUILD.bazel b/tests/visibility_attr/BUILD.bazel index e404f97d2..c3b2aa4bf 100644 --- a/tests/visibility_attr/BUILD.bazel +++ b/tests/visibility_attr/BUILD.bazel @@ -1,3 +1,4 @@ +load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load("//:def.bzl", "gazelle") gazelle( diff --git a/tests/visibility_attr/child/BUILD.bazel b/tests/visibility_attr/child/BUILD.bazel index 5f2e9dc0a..f6b5691f6 100644 --- a/tests/visibility_attr/child/BUILD.bazel +++ b/tests/visibility_attr/child/BUILD.bazel @@ -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",