Skip to content

Commit

Permalink
feat(bazel): expose browser driver binaries through toolchain aliases
Browse files Browse the repository at this point in the history
Similarly to how we expose the browser binaries currently (in a
platfrom-agnostic way), we will be exosing the drivers (chromedriver
and geckodriver) so that they can be used in integration tests for
running protractor/webdriverio etc.
  • Loading branch information
devversion committed Nov 8, 2021
1 parent 2c09737 commit 88d1b37
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 57 deletions.
18 changes: 10 additions & 8 deletions bazel/browsers/browser_toolchain_alias.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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)
for dep in ctx.attr.deps:
base_path = dep.label.workspace_name
named_files = dep[NamedFilesInfo].value

for key, value in named_files.items():
template_variables[key] = "external/%s/%s" % (base_path, value)

return [
platform_common.TemplateVariableInfo(template_variables),
Expand All @@ -15,13 +17,13 @@ def _browser_toolchain_alias_impl(ctx):
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.
included in the browser metadata dependencies. 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.""",
"deps": attr.label_list(
doc = """Metadata targets that provides the browser named files.""",
mandatory = True,
providers = [NamedFilesInfo, DefaultInfo],
),
Expand Down
47 changes: 22 additions & 25 deletions bazel/browsers/chromium/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,36 @@ load("//bazel/browsers:browser_toolchain_alias.bzl", "browser_toolchain_alias")

package(default_visibility = ["//visibility:public"])

PLATFORM_METADATA = select({
"//bazel/constraints:linux_x64": [
"@org_chromium_chromedriver_linux_x64//:metadata",
"@org_chromium_chromium_linux_x64//:metadata",
],
"//bazel/constraints:macos_x64": [
"@org_chromium_chromedriver_macos_x64//:metadata",
"@org_chromium_chromium_macos_x64//:metadata",
],
"//bazel/constraints:macos_arm64": [
"@org_chromium_chromedriver_macos_arm64//:metadata",
"@org_chromium_chromium_macos_arm64//:metadata",
],
"//bazel/constraints:windows_x64": [
"@org_chromium_chromedriver_windows//:metadata",
"@org_chromium_chromium_windows//:metadata",
],
})

browser(
name = "chromium",
metadata = "chromium.json",
deps = [
deps = PLATFORM_METADATA + [
"@io_bazel_rules_webtesting//go/wsl",
] + select({
"//bazel/constraints:linux_x64": [
"@org_chromium_chromedriver_linux_x64//:metadata",
"@org_chromium_chromium_linux_x64//:metadata",
],
"//bazel/constraints:macos_x64": [
"@org_chromium_chromedriver_macos_x64//:metadata",
"@org_chromium_chromium_macos_x64//:metadata",
],
"//bazel/constraints:macos_arm64": [
"@org_chromium_chromedriver_macos_arm64//:metadata",
"@org_chromium_chromium_macos_arm64//:metadata",
],
"//bazel/constraints:windows_x64": [
"@org_chromium_chromedriver_windows//:metadata",
"@org_chromium_chromium_windows//:metadata",
],
}),
],
)

browser_toolchain_alias(
name = "toolchain_alias",
metadata = select({
"//bazel/constraints:linux_x64": "@org_chromium_chromium_linux_x64//:metadata",
"//bazel/constraints:macos_x64": "@org_chromium_chromium_macos_x64//:metadata",
"//bazel/constraints:macos_arm64": "@org_chromium_chromium_macos_arm64//:metadata",
"//bazel/constraints:windows_x64": "@org_chromium_chromium_windows//:metadata",
}),
deps = PLATFORM_METADATA,
)

# Make source files available for distribution via pkg_npm
Expand Down
45 changes: 21 additions & 24 deletions bazel/browsers/firefox/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@ load("//bazel/browsers:browser_toolchain_alias.bzl", "browser_toolchain_alias")

package(default_visibility = ["//visibility:public"])

PLATFORM_METADATA = select({
"//bazel/constraints:linux_x64": [
"@org_mozilla_firefox_linux_x64//:metadata",
"@org_mozilla_geckodriver_linux_x64//:metadata",
],
"//bazel/constraints:macos_x64": [
# Firefox has a launcher that conditionally starts x64/arm64
"@org_mozilla_firefox_macos//:metadata",
"@org_mozilla_geckodriver_macos_x64//:metadata",
],
"//bazel/constraints:macos_arm64": [
# Firefox has a launcher that conditionally starts x64/arm64
"@org_mozilla_firefox_macos//:metadata",
"@org_mozilla_geckodriver_macos_arm64//:metadata",
],
"//conditions:default": [],
})

browser(
name = "firefox",
disabled = select({
Expand All @@ -14,35 +32,14 @@ browser(
"//conditions:default": None,
}),
metadata = "firefox.json",
deps = [
deps = PLATFORM_METADATA + [
"@io_bazel_rules_webtesting//go/wsl",
] + select({
"//bazel/constraints:linux_x64": [
"@org_mozilla_firefox_linux_x64//:metadata",
"@org_mozilla_geckodriver_linux_x64//:metadata",
],
"//bazel/constraints:macos_x64": [
# Firefox has a launcher that conditionally starts x64/arm64
"@org_mozilla_firefox_macos//:metadata",
"@org_mozilla_geckodriver_macos_x64//:metadata",
],
"//bazel/constraints:macos_arm64": [
# Firefox has a launcher that conditionally starts x64/arm64
"@org_mozilla_firefox_macos//:metadata",
"@org_mozilla_geckodriver_macos_arm64//:metadata",
],
"//conditions:default": [],
}),
],
)

browser_toolchain_alias(
name = "toolchain_alias",
metadata = select({
"//bazel/constraints:linux_x64": "@org_mozilla_firefox_linux_x64//:metadata",
# Firefox has a launcher that conditionally starts x64/arm64
"//bazel/constraints:macos_x64": "@org_mozilla_firefox_macos//:metadata",
"//bazel/constraints:macos_arm64": "@org_mozilla_firefox_macos//:metadata",
}),
deps = PLATFORM_METADATA,
)

# Make source files available for distribution via pkg_npm
Expand Down
3 changes: 3 additions & 0 deletions bazel/integration/tests/angular-cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ integration_test(
"yarn",
"yarn ng build",
"yarn ng test --no-watch",
"yarn ng e2e",
],
data = [
# The Yarn files also need to be part of the integration test as runfiles
Expand All @@ -16,6 +17,8 @@ integration_test(
"//bazel/browsers/chromium",
],
environment = {
"CHROMEDRIVER_SKIP_DOWNLOAD": "true",
"CHROMEDRIVER_PATH": "$(CHROMEDRIVER)",
"CHROME_BIN": "$(CHROMIUM)",
},
tags = [
Expand Down

0 comments on commit 88d1b37

Please sign in to comment.