11"""Bzlmod extensions"""
22
3- load ("@bazel_tools//tools/build_defs/repo:utils.bzl" , "maybe" )
43load (
54 "//helm/private:repositories.bzl" ,
65 "helm_host_alias_repository" ,
@@ -33,27 +32,17 @@ def _find_modules(module_ctx):
3332def _helm_impl (module_ctx ):
3433 root_mod , rules_mod = _find_modules (module_ctx )
3534
36- toolchains = root_mod .tags .toolchain
37- if not toolchains :
38- toolchains = rules_mod .tags .toolchain
39-
4035 host_tools = root_mod .tags .host_tools
4136 if not host_tools :
4237 host_tools = rules_mod .tags .host_tools
4338
44- for attrs in toolchains :
45- if attrs .version not in HELM_VERSIONS :
46- fail ("Helm toolchain hub `{}` was given unsupported version `{}`. Try: {}" .format (
47- attrs .name ,
48- attrs .version ,
49- HELM_VERSIONS .keys (),
50- ))
51- available = HELM_VERSIONS [attrs .version ]
52- toolchain_names = []
53- toolchain_labels = {}
54- target_compatible_with = {}
55- exec_compatible_with = {}
39+ toolchain_names = []
40+ toolchain_labels = {}
41+ target_compatible_with = {}
42+ exec_compatible_with = {}
43+ target_settings = {}
5644
45+ for version , available in HELM_VERSIONS .items ():
5746 for platform , integrity in available .items ():
5847 if platform .startswith ("windows" ):
5948 compression = "zip"
@@ -67,99 +56,53 @@ def _helm_impl(module_ctx):
6756 if url_platform == "linux-i386" :
6857 url_platform = "linux-386"
6958
70- toolchain_repo_name = "{}__{} _{}_bin" .format (attrs . name , attrs . version , platform .replace ("-" , "_" ))
59+ toolchain_repo_name = "helm_toolchains__{} _{}_bin" .format (version , platform .replace ("-" , "_" ))
7160
72- # Create the hub-specific binary repository
73- maybe (
74- helm_toolchain_repository ,
61+ helm_toolchain_repository (
7562 name = toolchain_repo_name ,
7663 urls = [
7764 template .replace (
7865 "{version}" ,
79- attrs . version ,
66+ version ,
8067 ).replace (
8168 "{platform}" ,
8269 url_platform ,
8370 ).replace (
8471 "{compression}" ,
8572 compression ,
8673 )
87- for template in attrs . helm_url_templates
74+ for template in DEFAULT_HELM_URL_TEMPLATES
8875 ],
8976 integrity = integrity ,
9077 strip_prefix = url_platform ,
91- plugins = attrs .plugins ,
9278 platform = platform ,
9379 )
9480
9581 toolchain_names .append (toolchain_repo_name )
9682 toolchain_labels [toolchain_repo_name ] = "@{}" .format (toolchain_repo_name )
9783 target_compatible_with [toolchain_repo_name ] = []
9884 exec_compatible_with [toolchain_repo_name ] = CONSTRAINTS [platform ]
85+ target_settings [toolchain_repo_name ] = ["@rules_helm//helm/settings:version_{}" .format (version )]
86+
87+ helm_toolchain_repository_hub (
88+ name = "helm_toolchains" ,
89+ toolchain_labels = toolchain_labels ,
90+ toolchain_names = toolchain_names ,
91+ exec_compatible_with = exec_compatible_with ,
92+ target_compatible_with = target_compatible_with ,
93+ target_settings = target_settings ,
94+ )
9995
100- maybe (
101- helm_toolchain_repository_hub ,
102- name = attrs .name ,
103- toolchain_labels = toolchain_labels ,
104- toolchain_names = toolchain_names ,
105- exec_compatible_with = exec_compatible_with ,
106- target_compatible_with = target_compatible_with ,
107- )
108-
109- # Process host_tools tags
11096 for host_tools_attrs in host_tools :
111- maybe (
112- helm_host_alias_repository ,
97+ helm_host_alias_repository (
11398 name = host_tools_attrs .name ,
99+ toolchain_repo_prefix = "helm_toolchains__{}" .format (host_tools_attrs .version ),
114100 )
115101
116102 return module_ctx .extension_metadata (
117103 reproducible = True ,
118104 )
119105
120- _toolchain = tag_class (
121- doc = """\
122- An extension for defining a `helm_toolchain` from a download archive.
123-
124- An example of defining and registering toolchains:
125-
126- ```python
127- helm = use_extension("@rules_helm//helm:extensions.bzl", "helm")
128- helm.toolchain(
129- name = "helm_toolchains",
130- version = "3.14.4",
131- )
132- use_repo(helm, "helm_toolchains")
133-
134- register_toolchains(
135- "@helm_toolchains//:all",
136- )
137- ```
138- """ ,
139- attrs = {
140- "helm_url_templates" : attr .string_list (
141- doc = (
142- "A url template used to download helm. The template can contain the following " +
143- "format strings `{platform}` for the helm platform, `{version}` for the helm " +
144- "version, and `{compression}` for the archive type containing the helm binary."
145- ),
146- default = DEFAULT_HELM_URL_TEMPLATES ,
147- ),
148- "name" : attr .string (
149- doc = "The name of the toolchain hub repository." ,
150- default = "helm_toolchains" ,
151- ),
152- "plugins" : attr .string_list (
153- doc = "A list of plugins to add to the generated toolchain." ,
154- default = [],
155- ),
156- "version" : attr .string (
157- doc = "The version of helm to download for the toolchain." ,
158- default = DEFAULT_HELM_VERSION ,
159- ),
160- },
161- )
162-
163106_host_tools = tag_class (
164107 doc = """\
165108 An extension for creating a host alias repository that provides a shorter name for the host platform's helm binary.
@@ -179,13 +122,16 @@ use_repo(helm, "helm")
179122 doc = "The name of the host alias repository." ,
180123 default = "helm" ,
181124 ),
125+ "version" : attr .string (
126+ doc = "The version of helm to use for host tools." ,
127+ default = DEFAULT_HELM_VERSION ,
128+ ),
182129 },
183130)
184131
185132helm = module_extension (
186133 implementation = _helm_impl ,
187134 tag_classes = {
188135 "host_tools" : _host_tools ,
189- "toolchain" : _toolchain ,
190136 },
191137)
0 commit comments