-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bazel): create toolchain alias rule for browser metadata targets
Creates a toolchain alais rule for exposing template variables extracted from browser metadata (such as chromium or firefox) These toolchain aliases can then be consumed in the `toolchains` attribute of _all_ rules (as this is a common attribute supported by all rules in Bazel). The toolchain aliases within the `toolchains` attribute of rules, such as a `genrule` can then be used to access certain named files through Make variable expansion within Bazel.
- Loading branch information
1 parent
4c02c1b
commit 8c73f43
Showing
2 changed files
with
38 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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], | ||
), | ||
}, | ||
) |