@@ -57,72 +57,15 @@ JQ_VERSIONS = {
5757 },
5858}
5959
60- JqInfo = provider (
61- doc = "Provide info for executing jq" ,
62- fields = {
63- "bin" : "Executable jq binary" ,
64- },
65- )
66-
67- def _jq_toolchain_impl (ctx ):
68- binary = ctx .file .bin
69-
70- # Make the $(JQ_BIN) variable available in places like genrules.
71- # See https://docs.bazel.build/versions/main/be/make-variables.html#custom_variables
72- template_variables = platform_common .TemplateVariableInfo ({
73- "JQ_BIN" : binary .path ,
74- })
75- default_info = DefaultInfo (
76- files = depset ([binary ]),
77- runfiles = ctx .runfiles (files = [binary ]),
78- )
79- jq_info = JqInfo (
80- bin = binary ,
81- )
82-
83- # Export all the providers inside our ToolchainInfo
84- # so the resolved_toolchain rule can grab and re-export them.
85- toolchain_info = platform_common .ToolchainInfo (
86- jqinfo = jq_info ,
87- template_variables = template_variables ,
88- default = default_info ,
89- )
90-
91- return [default_info , toolchain_info , template_variables ]
92-
93- jq_toolchain = rule (
94- implementation = _jq_toolchain_impl ,
95- attrs = {
96- "bin" : attr .label (
97- mandatory = True ,
98- allow_single_file = True ,
99- ),
100- },
101- )
102-
10360def _jq_toolchains_repo_impl (rctx ):
10461 # Expose a concrete toolchain which is the result of Bazel resolving the toolchain
10562 # for the execution or target platform.
10663 # Workaround for https://github.com/bazelbuild/bazel/issues/14009
10764 starlark_content = """# @generated by @aspect_bazel_lib//lib/private:jq_toolchain.bzl
65+ load("@aspect_bazel_lib//lib:binary_toolchain.bzl", "resolved_binary_rule")
10866
109- # Forward all the providers
110- def _resolved_toolchain_impl(ctx):
111- toolchain_info = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"]
112- return [
113- toolchain_info,
114- toolchain_info.default,
115- toolchain_info.jqinfo,
116- toolchain_info.template_variables,
117- ]
118-
119- # Copied from java_toolchain_alias
120- # https://cs.opensource.google/bazel/bazel/+/master:tools/jdk/java_toolchain_alias.bzl
121- resolved_toolchain = rule(
122- implementation = _resolved_toolchain_impl,
123- toolchains = ["@aspect_bazel_lib//lib:jq_toolchain_type"],
124- incompatible_use_toolchain_transition = True,
125- )
67+ resolved_toolchain = resolved_binary_rule(toolchain_type = "@aspect_bazel_lib//lib:jq_toolchain_type", template_variable = "JQ_BIN")
68+ resolved_binary = resolved_binary_rule(toolchain_type = "@aspect_bazel_lib//lib:jq_runtime_toolchain_type", template_variable = "JQ_BIN")
12669"""
12770 rctx .file ("defs.bzl" , starlark_content )
12871
@@ -132,10 +75,10 @@ resolved_toolchain = rule(
13275# By default all these toolchains are registered by the jq_register_toolchains macro
13376# so you don't normally need to interact with these targets.
13477
135- load(":defs.bzl", "resolved_toolchain")
78+ load(":defs.bzl", "resolved_toolchain", "resolved_binary" )
13679
13780resolved_toolchain(name = "resolved_toolchain", visibility = ["//visibility:public"])
138-
81+ resolved_binary(name = "resolved_binary", visibility = ["//visibility:public"])
13982"""
14083
14184 for [platform , meta ] in JQ_PLATFORMS .items ():
@@ -146,6 +89,12 @@ toolchain(
14689 toolchain = "@{user_repository_name}_{platform}//:jq_toolchain",
14790 toolchain_type = "@aspect_bazel_lib//lib:jq_toolchain_type",
14891)
92+ toolchain(
93+ name = "{platform}_toolchain",
94+ target_compatible_with = {compatible_with},
95+ toolchain = "@{user_repository_name}_{platform}//:jq_runtime_toolchain",
96+ toolchain_type = "@aspect_bazel_lib//lib:jq_runtime_toolchain_type",
97+ )
14998""" .format (
15099 platform = platform ,
151100 user_repository_name = rctx .attr .user_repository_name ,
@@ -182,9 +131,10 @@ def _jq_platform_repo_impl(rctx):
182131 integrity = JQ_VERSIONS [rctx .attr .version ][release_platform ],
183132 )
184133 build_content = """# @generated by @aspect_bazel_lib//lib/private:jq_toolchain.bzl
185- load("@aspect_bazel_lib//lib/private:jq_toolchain .bzl", "jq_toolchain ")
134+ load("@aspect_bazel_lib//lib:binary_toolchain .bzl", "binary_toolchain", "binary_runtime_toolchain ")
186135exports_files(["{0}"])
187- jq_toolchain(name = "jq_toolchain", bin = "{0}", visibility = ["//visibility:public"])
136+ binary_toolchain(name = "jq_toolchain", bin = "{0}", visibility = ["//visibility:public"])
137+ binary_runtime_toolchain(name = "jq_runtime_toolchain", bin = "{0}", visibility = ["//visibility:public"])
188138""" .format ("jq.exe" if is_windows else "jq" )
189139
190140 # Base BUILD file for this repository
0 commit comments