@@ -57,72 +57,15 @@ JQ_VERSIONS = {
57
57
},
58
58
}
59
59
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
-
103
60
def _jq_toolchains_repo_impl (rctx ):
104
61
# Expose a concrete toolchain which is the result of Bazel resolving the toolchain
105
62
# for the execution or target platform.
106
63
# Workaround for https://github.com/bazelbuild/bazel/issues/14009
107
64
starlark_content = """# @generated by @aspect_bazel_lib//lib/private:jq_toolchain.bzl
65
+ load("@aspect_bazel_lib//lib:binary_toolchain.bzl", "resolved_binary_rule")
108
66
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")
126
69
"""
127
70
rctx .file ("defs.bzl" , starlark_content )
128
71
@@ -132,10 +75,10 @@ resolved_toolchain = rule(
132
75
# By default all these toolchains are registered by the jq_register_toolchains macro
133
76
# so you don't normally need to interact with these targets.
134
77
135
- load(":defs.bzl", "resolved_toolchain")
78
+ load(":defs.bzl", "resolved_toolchain", "resolved_binary" )
136
79
137
80
resolved_toolchain(name = "resolved_toolchain", visibility = ["//visibility:public"])
138
-
81
+ resolved_binary(name = "resolved_binary", visibility = ["//visibility:public"])
139
82
"""
140
83
141
84
for [platform , meta ] in JQ_PLATFORMS .items ():
@@ -146,6 +89,12 @@ toolchain(
146
89
toolchain = "@{user_repository_name}_{platform}//:jq_toolchain",
147
90
toolchain_type = "@aspect_bazel_lib//lib:jq_toolchain_type",
148
91
)
92
+ toolchain(
93
+ name = "{platform}_runtime_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
+ )
149
98
""" .format (
150
99
platform = platform ,
151
100
user_repository_name = rctx .attr .user_repository_name ,
@@ -182,9 +131,10 @@ def _jq_platform_repo_impl(rctx):
182
131
integrity = JQ_VERSIONS [rctx .attr .version ][release_platform ],
183
132
)
184
133
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 ")
186
135
exports_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"])
188
138
""" .format ("jq.exe" if is_windows else "jq" )
189
139
190
140
# Base BUILD file for this repository
0 commit comments