Skip to content

Commit 26e0ba6

Browse files
authored
feat: allow rules_ruby to participate in bazel mod tidy (#220)
1 parent f1af769 commit 26e0ba6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ruby/extensions.bzl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ ruby_toolchain = tag_class(attrs = {
3232
})
3333

3434
def _ruby_module_extension(module_ctx):
35+
direct_dep_names = []
36+
direct_dev_dep_names = []
3537
registrations = {}
3638
for mod in module_ctx.modules:
3739
for bundle in mod.tags.bundle:
@@ -42,6 +44,10 @@ def _ruby_module_extension(module_ctx):
4244
gemfile = bundle.gemfile,
4345
toolchain = bundle.toolchain,
4446
)
47+
if module_ctx.is_dev_dependency(bundle):
48+
direct_dev_dep_names.append(bundle.name)
49+
else:
50+
direct_dep_names.append(bundle.name)
4551

4652
for bundle_fetch in mod.tags.bundle_fetch:
4753
rb_bundle_fetch(
@@ -54,6 +60,10 @@ def _ruby_module_extension(module_ctx):
5460
bundler_remote = bundle_fetch.bundler_remote,
5561
bundler_checksums = bundle_fetch.bundler_checksums,
5662
)
63+
if module_ctx.is_dev_dependency(bundle_fetch):
64+
direct_dev_dep_names.append(bundle_fetch.name)
65+
else:
66+
direct_dep_names.append(bundle_fetch.name)
5767

5868
for toolchain in mod.tags.toolchain:
5969
# Prevent a users dependencies creating conflicting toolchain names
@@ -78,6 +88,12 @@ def _ruby_module_extension(module_ctx):
7888
toolchain.msys2_packages,
7989
toolchain.ruby_build_version,
8090
)
91+
if module_ctx.is_dev_dependency(toolchain):
92+
direct_dev_dep_names.append(toolchain.name)
93+
direct_dev_dep_names.append("%s_toolchains" % toolchain.name)
94+
else:
95+
direct_dep_names.append(toolchain.name)
96+
direct_dep_names.append("%s_toolchains" % toolchain.name)
8197

8298
for name, (version, version_file, msys2_packages, ruby_build_version) in registrations.items():
8399
rb_register_toolchains(
@@ -89,6 +105,12 @@ def _ruby_module_extension(module_ctx):
89105
register = False,
90106
)
91107

108+
return module_ctx.extension_metadata(
109+
reproducible = True,
110+
root_module_direct_deps = direct_dep_names,
111+
root_module_direct_dev_deps = direct_dev_dep_names,
112+
)
113+
92114
ruby = module_extension(
93115
implementation = _ruby_module_extension,
94116
tag_classes = {

0 commit comments

Comments
 (0)