From e6045ee0b7a3d728fa47506b216f6fe7333b4d5d Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Fri, 1 Nov 2019 11:17:10 -0700 Subject: [PATCH] build: fixes for cross-platform RBE (#33708) The earlier update to nodejs rules 0.40.0 fixes the cross-platform RBE issues with nodejs_binary. This commit adds a work-around for rules_webtesting cross-platform RBE issues. PR Close #33708 --- WORKSPACE | 7 +- modules/benchmarks/benchmark_test.bzl | 2 +- modules/playground/e2e_test/example_test.bzl | 3 +- packages/compiler-cli/integrationtest/test.js | 4 +- packages/examples/common/BUILD.bazel | 3 +- packages/examples/core/BUILD.bazel | 3 +- packages/examples/forms/BUILD.bazel | 3 +- .../examples/service-worker/push/BUILD.bazel | 3 +- .../registration-options/BUILD.bazel | 3 +- packages/examples/upgrade/upgrade_example.bzl | 3 +- packages/zone.js/test/karma_test.bzl | 2 + tools/browsers/BUILD.bazel | 70 +++++++++++++++ tools/browsers/browser_repositories.bzl | 87 +++++++++++++++++++ tools/browsers/chromium.json | 20 +++++ tools/defaults.bzl | 28 +++--- 15 files changed, 201 insertions(+), 40 deletions(-) create mode 100644 tools/browsers/BUILD.bazel create mode 100644 tools/browsers/browser_repositories.bzl create mode 100644 tools/browsers/chromium.json diff --git a/WORKSPACE b/WORKSPACE index 09be7d6f8d..da6b47d474 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -113,12 +113,9 @@ load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories" web_test_repositories() -load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories") +load("//tools/browsers:browser_repositories.bzl", "browser_repositories") -browser_repositories( - chromium = True, - firefox = True, -) +browser_repositories() # Setup the rules_typescript tooolchain load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace") diff --git a/modules/benchmarks/benchmark_test.bzl b/modules/benchmarks/benchmark_test.bzl index b5d7c7419d..1c48ea441c 100644 --- a/modules/benchmarks/benchmark_test.bzl +++ b/modules/benchmarks/benchmark_test.bzl @@ -1,4 +1,4 @@ -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "protractor_web_test_suite") """ Macro that can be used to define a benchmark test. This differentiates from diff --git a/modules/playground/e2e_test/example_test.bzl b/modules/playground/e2e_test/example_test.bzl index 719512a270..45781f923c 100644 --- a/modules/playground/e2e_test/example_test.bzl +++ b/modules/playground/e2e_test/example_test.bzl @@ -1,5 +1,4 @@ -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") -load("//tools:defaults.bzl", "ts_library") +load("//tools:defaults.bzl", "protractor_web_test_suite", "ts_library") def example_test(name, srcs, server, data = [], **kwargs): ts_library( diff --git a/packages/compiler-cli/integrationtest/test.js b/packages/compiler-cli/integrationtest/test.js index e8b9da6b83..c30bb482c6 100644 --- a/packages/compiler-cli/integrationtest/test.js +++ b/packages/compiler-cli/integrationtest/test.js @@ -34,8 +34,8 @@ function nodejs_repository() { const nodejsBinaryExt = os.platform() === 'win32' ? '.bat' : '.sh'; const ngcBin = require.resolve(`./ngc_bin${nodejsBinaryExt}`); const xi18nBin = require.resolve(`./ng_xi18n${nodejsBinaryExt}`); -const nodeBin = - require.resolve(`${nodejs_repository()}/bin/node${(os.platform() === 'win32' ? '.cmd' : '')}`); +const nodeBin = require.resolve( + `${nodejs_repository()}/${(os.platform() === 'win32' ? 'bin/nodejs/node.exe' : 'bin/nodejs/bin/node')}`); const jasmineBin = require.resolve('npm/node_modules/jasmine/bin/jasmine.js'); // Prepare the test directory before building the integration test output. This ensures that diff --git a/packages/examples/common/BUILD.bazel b/packages/examples/common/BUILD.bazel index 15b1efb8ee..552dc825ef 100644 --- a/packages/examples/common/BUILD.bazel +++ b/packages/examples/common/BUILD.bazel @@ -1,7 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("//tools:defaults.bzl", "ng_module", "ts_library") -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_devserver") ng_module( diff --git a/packages/examples/core/BUILD.bazel b/packages/examples/core/BUILD.bazel index 8105dae426..7b74d1738a 100644 --- a/packages/examples/core/BUILD.bazel +++ b/packages/examples/core/BUILD.bazel @@ -1,7 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("//tools:defaults.bzl", "jasmine_node_test", "ng_module", "ts_library") -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "jasmine_node_test", "ng_module", "protractor_web_test_suite", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_devserver") ng_module( diff --git a/packages/examples/forms/BUILD.bazel b/packages/examples/forms/BUILD.bazel index 1d88fded72..367aa52f2d 100644 --- a/packages/examples/forms/BUILD.bazel +++ b/packages/examples/forms/BUILD.bazel @@ -1,7 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("//tools:defaults.bzl", "ng_module", "ts_library") -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_devserver") ng_module( diff --git a/packages/examples/service-worker/push/BUILD.bazel b/packages/examples/service-worker/push/BUILD.bazel index b670a4566a..fc0d167395 100644 --- a/packages/examples/service-worker/push/BUILD.bazel +++ b/packages/examples/service-worker/push/BUILD.bazel @@ -1,7 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("//tools:defaults.bzl", "ng_module", "ts_library") -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_devserver") ng_module( diff --git a/packages/examples/service-worker/registration-options/BUILD.bazel b/packages/examples/service-worker/registration-options/BUILD.bazel index 5b3c4c0657..ad62153d4e 100644 --- a/packages/examples/service-worker/registration-options/BUILD.bazel +++ b/packages/examples/service-worker/registration-options/BUILD.bazel @@ -1,7 +1,6 @@ package(default_visibility = ["//visibility:public"]) -load("//tools:defaults.bzl", "ng_module", "ts_library") -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_devserver") ng_module( diff --git a/packages/examples/upgrade/upgrade_example.bzl b/packages/examples/upgrade/upgrade_example.bzl index 940a614187..51928ead15 100644 --- a/packages/examples/upgrade/upgrade_example.bzl +++ b/packages/examples/upgrade/upgrade_example.bzl @@ -1,5 +1,4 @@ -load("//tools:defaults.bzl", "ng_module", "ts_library") -load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite") +load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library") load("@npm_bazel_typescript//:index.bzl", "ts_devserver") """ diff --git a/packages/zone.js/test/karma_test.bzl b/packages/zone.js/test/karma_test.bzl index bb03db6de7..81ed5e01f5 100644 --- a/packages/zone.js/test/karma_test.bzl +++ b/packages/zone.js/test/karma_test.bzl @@ -101,6 +101,7 @@ def karma_test(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps, ":" + name + "_env_trim_map", ] + bootstrap + _karma_test_required_dist_files, + browsers = ["//tools/browsers:chromium"], static_files = [ ":assets/sample.json", ":assets/worker.js", @@ -123,6 +124,7 @@ def karma_test(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps, ":" + name + "_env_trim_map", "//packages/zone.js/dist:zone-testing-bundle-dist-test", ] + _karma_test_required_dist_files, + browsers = ["//tools/browsers:chromium"], config_file = "//:karma-js.conf.js", configuration_env_vars = ["KARMA_WEB_TEST_MODE"], data = [ diff --git a/tools/browsers/BUILD.bazel b/tools/browsers/BUILD.bazel new file mode 100644 index 0000000000..96aa00190d --- /dev/null +++ b/tools/browsers/BUILD.bazel @@ -0,0 +1,70 @@ +# Copyright 2016 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +################################################################################ +# +load("@io_bazel_rules_webtesting//web:web.bzl", "browser", "web_test_archive") + +# Override of chromium web_test_archive so that the archive is selected based on platform +web_test_archive( + name = "chromium_archive", + testonly = True, + archive = select({ + "@io_bazel_rules_webtesting//common/conditions:linux": "@org_chromium_chromium_amd64//file", + "@io_bazel_rules_webtesting//common/conditions:mac": "@org_chromium_chromium_macos//file", + "@io_bazel_rules_webtesting//common/conditions:windows": "@org_chromium_chromium_windows//file", + }), + extract = "build", + named_files = select({ + "@io_bazel_rules_webtesting//common/conditions:linux": {"CHROMIUM": "chrome-linux/chrome"}, + "@io_bazel_rules_webtesting//common/conditions:mac": {"CHROMIUM": "chrome-mac/Chromium.app/Contents/MacOS/chromium"}, + "@io_bazel_rules_webtesting//common/conditions:windows": {"CHROMIUM": "chrome-win/chrome.exe"}, + }), + visibility = ["//tools/browsers:__subpackages__"], +) + +# Override of chromedriver web_test_archive so that the archive is selected based on platform +web_test_archive( + name = "chromedriver_archive", + testonly = True, + archive = select({ + "@io_bazel_rules_webtesting//common/conditions:linux": "@org_chromium_chromedriver_amd64//file", + "@io_bazel_rules_webtesting//common/conditions:mac": "@org_chromium_chromedriver_macos//file", + "@io_bazel_rules_webtesting//common/conditions:windows": "@org_chromium_chromedriver_windows//file", + }), + extract = "build", + named_files = select({ + "@io_bazel_rules_webtesting//common/conditions:linux": { + "CHROMEDRIVER": "chromedriver_linux64/chromedriver", + }, + "@io_bazel_rules_webtesting//common/conditions:mac": { + "CHROMEDRIVER": "chromedriver_mac64/chromedriver", + }, + "@io_bazel_rules_webtesting//common/conditions:windows": { + "CHROMEDRIVER": "chromedriver_win32/chromedriver.exe", + }, + }), + visibility = ["//tools/browsers:__subpackages__"], +) + +browser( + name = "chromium", + metadata = "chromium.json", + visibility = ["//visibility:public"], + deps = [ + ":chromedriver_archive", + ":chromium_archive", + "@io_bazel_rules_webtesting//go/wsl", + ], +) diff --git a/tools/browsers/browser_repositories.bzl b/tools/browsers/browser_repositories.bzl new file mode 100644 index 0000000000..244de68df3 --- /dev/null +++ b/tools/browsers/browser_repositories.bzl @@ -0,0 +1,87 @@ +# Copyright 2018 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Pinned browser versions. + +This function is here to make browser repositories work with cross-platform RBE. +Unlike the rules_webtesting browser_repositories, this function defines +separate repositories for each platform +""" + +load("@io_bazel_rules_webtesting//web/internal:platform_http_file.bzl", _platform_http_file = "platform_http_file") + +def platform_http_file(name, licenses, sha256, urls): + """Platform spepcific browser repository. + + This works around a dificiency in io_bazel_rules_webtesting platform_http_file in that + it selects the platform when the repository rule is executed. This limits browsers + tests to run on the local user platform only. For cross-platform RBE we want a repository + to be defined per platform so the correct one can be selected. + """ + + _platform_http_file( + name = name, + amd64_sha256 = sha256, + amd64_urls = urls, + licenses = licenses, + macos_sha256 = sha256, + macos_urls = urls, + windows_sha256 = sha256, + windows_urls = urls, + ) + +def browser_repositories(): + """Load pinned rules_webtesting browser versions.""" + + platform_http_file( + name = "org_chromium_chromium_amd64", + licenses = ["notice"], # BSD 3-clause (maybe more?) + sha256 = "b1e30c4dec8a451f8fe10d1f2d3c71e491d0333425f32247fe5c80a0a354303d", + urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/664981/chrome-linux.zip"], + ) + + platform_http_file( + name = "org_chromium_chromium_macos", + licenses = ["notice"], # BSD 3-clause (maybe more?) + sha256 = "7c0ba93616f44a421330b1c1262e8899fbdf7916bed8b04c775e0426f6f35ec6", + urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/665002/chrome-mac.zip"], + ) + + platform_http_file( + name = "org_chromium_chromium_windows", + licenses = ["notice"], # BSD 3-clause (maybe more?) + sha256 = "f2facd0066270078d0e8999e684595274c359cac3946299a1ceedba2a5de1c63", + urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/664999/chrome-win.zip"], + ) + + platform_http_file( + name = "org_chromium_chromedriver_amd64", + licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT + sha256 = "0ead02145854b60a3317b59031205b362fb4cfdb680fef20e95c89582e6e38be", + urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/664981/chromedriver_linux64.zip"], + ) + + platform_http_file( + name = "org_chromium_chromedriver_macos", + licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT + sha256 = "8dd159e27b13b16262afa6993b15321e736c3b484da363c0e03bb050d72522c9", + urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/665002/chromedriver_mac64.zip"], + ) + + platform_http_file( + name = "org_chromium_chromedriver_windows", + licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT + sha256 = "1cc881364974102182257a5c5c2b9cfed513689dee28924ca44df082bdf9fd60", + urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/664999/chromedriver_win32.zip"], + ) diff --git a/tools/browsers/chromium.json b/tools/browsers/chromium.json new file mode 100644 index 0000000000..7fb23d3486 --- /dev/null +++ b/tools/browsers/chromium.json @@ -0,0 +1,20 @@ +{ + "environment" : "local", + "capabilities" : { + "browserName" : "chrome", + "goog:chromeOptions" : { + "binary" : "%FILE:CHROMIUM%", + "args" : [ + "--headless", + "--use-gl=swiftshader-webgl" + ] + }, + "google:wslConfig": { + "binary": "%FILE:CHROMEDRIVER%", + "port":"%WSLPORT:WSL%", + "args": ["--port=%WSLPORT:WSL%"], + "status": true, + "shutdown": true + } + } +} diff --git a/tools/defaults.bzl b/tools/defaults.bzl index 1ad3ddead6..d149cbb010 100644 --- a/tools/defaults.bzl +++ b/tools/defaults.bzl @@ -4,6 +4,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary", load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test") load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite") load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library") +load("@npm_bazel_protractor//:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite") load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package") load("//tools/ng_rollup_bundle:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle") load("//tools:ng_benchmark.bzl", _ng_benchmark = "ng_benchmark") @@ -203,28 +204,19 @@ def karma_web_test_suite(bootstrap = [], deps = [], runtime_deps = [], **kwargs) "//tools/testing:browser", ] + runtime_deps - tags = kwargs.pop("tags", []) - - # rules_webtesting has a required_tag "native" for `chromium-local` browser - if not "native" in tags: - tags = tags + ["native"] - _karma_web_test_suite( runtime_deps = local_runtime_deps, bootstrap = bootstrap, deps = local_deps, - # Run unit tests on local Chromium by default. - # You can exclude tests based on tags, e.g. to skip Firefox testing, - # `yarn bazel test --test_tag_filters=-browser:firefox-local [targets]` - browsers = [ - "@io_bazel_rules_webtesting//browsers:chromium-local", - # Don't test on local Firefox by default, for faster builds. - # We think that bugs in Angular tend to be caught the same in any - # evergreen browser. - # "@io_bazel_rules_webtesting//browsers:firefox-local", - # TODO(alexeagle): add remote browsers on SauceLabs - ], - tags = tags, + browsers = ["//tools/browsers:chromium"], + **kwargs + ) + +def protractor_web_test_suite(**kwargs): + """Default values for protractor_web_test_suite""" + + _protractor_web_test_suite( + browsers = ["//tools/browsers:chromium"], **kwargs )