diff --git a/bazel/browsers/browser_configure.bzl b/bazel/browsers/browser_configure.bzl index ba184dcdc..5ffd3dfd6 100644 --- a/bazel/browsers/browser_configure.bzl +++ b/bazel/browsers/browser_configure.bzl @@ -1,16 +1,21 @@ load("@io_bazel_rules_webtesting//web/internal:metadata.bzl", "metadata") load("@io_bazel_rules_webtesting//web/internal:provider.bzl", "WebTestInfo") -"""Converts the specified label to a manifest path""" +NamedFilesInfo = provider( + doc = "Provider exposing the named files of an extracted browser archive.", + fields = { + "value": "Dictionary of keys and their corresponding manifest paths", + }, +) def _label_to_manifest_path(label): + """Converts the specified label to a manifest path""" if label.package != "": return "%s/%s" % (label.workspace_name, label.package) return label.workspace_name -"""Implementation of the `browser_configure` rule.""" - def _browser_configure_impl(ctx): + """Implementation of the `browser_configure` rule.""" named_files = {} base_dir = _label_to_manifest_path(ctx.label) @@ -32,6 +37,7 @@ def _browser_configure_impl(ctx): return [ DefaultInfo(runfiles = ctx.runfiles(files = ctx.files.files)), WebTestInfo(metadata = ctx.outputs.web_test_metadata), + NamedFilesInfo(value = ctx.attr.named_files), ] """ diff --git a/bazel/browsers/browser_toolchain_alias.bzl b/bazel/browsers/browser_toolchain_alias.bzl new file mode 100644 index 000000000..d02ccf49d --- /dev/null +++ b/bazel/browsers/browser_toolchain_alias.bzl @@ -0,0 +1,29 @@ +load("//bazel/browsers:browser_configure.bzl", "NamedFilesInfo") + +def _browser_toolchain_alias_impl(ctx): + base_path = ctx.attr.metadata.label.workspace_name + named_files = ctx.attr.metadata[NamedFilesInfo].value + template_variables = {} + + for key, value in named_files.items(): + template_variables[key] = "external/%s/%s" % (base_path, value) + + return [ + platform_common.TemplateVariableInfo(template_variables), + ] + +browser_toolchain_alias = rule( + doc = """ + Exposes a toolchain alias exposing the template variables for all named files + included in the browser metadata. These variables can then be consumed within Bazel + make variable expansion. + """, + implementation = _browser_toolchain_alias_impl, + attrs = { + "metadata": attr.label( + doc = """Metadata target that provides the browser named files.""", + mandatory = True, + providers = [NamedFilesInfo, DefaultInfo], + ), + }, +)