Skip to content
Closed
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
7 changes: 7 additions & 0 deletions ruby/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ ruby_bundle_fetch = tag_class(attrs = {
"name": attr.string(doc = "Resulting repository name for the bundle"),
"srcs": attr.label_list(),
"env": attr.string_dict(),
"env_bzl": attr.label(doc = """\
Optional .bzl file exporting a dict named `bundle_env`, merged into the generated \
rb_bundle_install `env`. Unlike `env` (static strings), values are resolved at \
BUILD-evaluation time, so they can come from generated repositories (e.g. a \
machine-resolved toolchain path).\
""",),
"extra_args": attr.string_list(doc = "Extra arguments appended to `bundle install`. Supports `$(location ...)` against `data`."),
"data": attr.label_list(doc = "Files referenced from `extra_args` via `$(location ...)`."),
"binstubs": attr.bool(default = True, doc = "Run `bundle binstubs --all` after install. Set False for cross-platform bundles."),
Expand Down Expand Up @@ -81,6 +87,7 @@ def _ruby_module_extension(module_ctx):
name = bundle_fetch.name,
srcs = bundle_fetch.srcs,
env = bundle_fetch.env,
env_bzl = bundle_fetch.env_bzl,
extra_args = bundle_fetch.extra_args,
data = [str(label) for label in bundle_fetch.data],
binstubs = bundle_fetch.binstubs,
Expand Down
17 changes: 16 additions & 1 deletion ruby/private/bundle_fetch.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ def _rb_bundle_fetch_impl(repository_ctx):
},
)

if repository_ctx.attr.env_bzl:
env_load = 'load("{}", "bundle_env")'.format(str(repository_ctx.attr.env_bzl))
env_value = "bundle_env"
if repository_ctx.attr.env:
env_value = "bundle_env | {}".format(repr(repository_ctx.attr.env))
else:
env_load = ""
env_value = repr(repository_ctx.attr.env)

repository_ctx.template(
"BUILD",
repository_ctx.attr._build_tpl,
Expand All @@ -246,7 +255,8 @@ def _rb_bundle_fetch_impl(repository_ctx):
"{gems}": _join_and_indent(gem_full_names),
"{gem_fragments}": "".join(gem_fragments),
"{gem_install_fragments}": "".join(gem_install_fragments),
"{env}": repr(repository_ctx.attr.env),
"{env_load}": env_load,
"{env}": env_value,
"{extra_args}": repr(repository_ctx.attr.extra_args),
"{data}": _join_and_indent(repository_ctx.attr.data),
"{binstubs}": repr(repository_ctx.attr.binstubs),
Expand Down Expand Up @@ -309,6 +319,11 @@ rb_bundle_fetch = repository_rule(
"`$(location ...)` expansion against `data` (forwarded to the " +
"generated rb_bundle_install `env`).",
),
"env_bzl": attr.label(
doc = "Optional .bzl file exporting `bundle_env` (dict), merged into the " +
"generated rb_bundle_install `env`. Values are resolved at " +
"BUILD-evaluation time, so they can come from generated repositories.",
),
"extra_args": attr.string_list(
doc = "Extra arguments appended to the `bundle install` command line " +
"run by the generated rb_bundle_install target. Supports " +
Expand Down
1 change: 1 addition & 0 deletions ruby/private/bundle_fetch/BUILD.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""@generated by @rules_ruby//:ruby/private/bundle_fetch.bzl"""

load("@rules_ruby//ruby:defs.bzl", "rb_bundle_install", "rb_gem", "rb_gem_install")
{env_load}

package(default_visibility = ["//visibility:public"])

Expand Down
Loading