Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve module extension #130

Merged
merged 3 commits into from
Jan 7, 2025
Merged
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
30 changes: 20 additions & 10 deletions helm/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@ exports_files(glob(["**"]))
"""

def _helm_impl(ctx):
module = ctx.modules[0]
options = module.tags.options
version = options[0].version
helm_url_templates = options[0].helm_url_templates
plugins = options[0].plugins
for module in ctx.modules:
if not module.is_root:
continue
if module.is_root and len(module.tags.options) > 0:
# TODO Use deprecation tag when available: https://github.com/bazelbuild/bazel/issues/24843
print("helm.options() is deprecated. Use helm.toolchain() instead.") # buildifier: disable=print
toolchain_options = module.tags.toolchain + module.tags.options
if len(toolchain_options) > 1:
fail("Only a single helm toolchain is supported for now.")
if len(toolchain_options) == 1:
toolchain_option = toolchain_options[0]
version = toolchain_option.version
helm_url_templates = toolchain_option.helm_url_templates
plugins = toolchain_option.plugins

_register_toolchains(version, helm_url_templates, plugins)
_register_go_yaml()
_register_toolchains(version, helm_url_templates, plugins)
_register_go_yaml()

def _register_toolchains(version, helm_url_templates, plugins):
if not version in HELM_VERSIONS:
Expand Down Expand Up @@ -93,8 +102,8 @@ def _register_go_yaml():
build_file = Label("//3rdparty/yaml:BUILD.yaml.bazel"),
)

options = tag_class(
doc = "Options used to configure helm toolchains.",
_toolchain = tag_class(
doc = "Configure a helm toolchain.",
attrs = {
"helm_url_templates": attr.string_list(
doc = (
Expand All @@ -118,6 +127,7 @@ options = tag_class(
helm = module_extension(
implementation = _helm_impl,
tag_classes = {
"options": options,
"options": _toolchain, # deprecated: use toolchain instead and remove in next major version
"toolchain": _toolchain,
},
)
Loading