Skip to content

Commit e6045ee

Browse files
josephperrottalxhub
authored andcommitted
build: fixes for cross-platform RBE (angular#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 angular#33708
1 parent f2828a0 commit e6045ee

File tree

15 files changed

+201
-40
lines changed

15 files changed

+201
-40
lines changed

WORKSPACE

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,9 @@ load("@io_bazel_rules_webtesting//web:repositories.bzl", "web_test_repositories"
113113

114114
web_test_repositories()
115115

116-
load("@io_bazel_rules_webtesting//web/versioned:browsers-0.3.2.bzl", "browser_repositories")
116+
load("//tools/browsers:browser_repositories.bzl", "browser_repositories")
117117

118-
browser_repositories(
119-
chromium = True,
120-
firefox = True,
121-
)
118+
browser_repositories()
122119

123120
# Setup the rules_typescript tooolchain
124121
load("@npm_bazel_typescript//:index.bzl", "ts_setup_workspace")

modules/benchmarks/benchmark_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
1+
load("//tools:defaults.bzl", "protractor_web_test_suite")
22

33
"""
44
Macro that can be used to define a benchmark test. This differentiates from

modules/playground/e2e_test/example_test.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
2-
load("//tools:defaults.bzl", "ts_library")
1+
load("//tools:defaults.bzl", "protractor_web_test_suite", "ts_library")
32

43
def example_test(name, srcs, server, data = [], **kwargs):
54
ts_library(

packages/compiler-cli/integrationtest/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ function nodejs_repository() {
3434
const nodejsBinaryExt = os.platform() === 'win32' ? '.bat' : '.sh';
3535
const ngcBin = require.resolve(`./ngc_bin${nodejsBinaryExt}`);
3636
const xi18nBin = require.resolve(`./ng_xi18n${nodejsBinaryExt}`);
37-
const nodeBin =
38-
require.resolve(`${nodejs_repository()}/bin/node${(os.platform() === 'win32' ? '.cmd' : '')}`);
37+
const nodeBin = require.resolve(
38+
`${nodejs_repository()}/${(os.platform() === 'win32' ? 'bin/nodejs/node.exe' : 'bin/nodejs/bin/node')}`);
3939
const jasmineBin = require.resolve('npm/node_modules/jasmine/bin/jasmine.js');
4040

4141
// Prepare the test directory before building the integration test output. This ensures that

packages/examples/common/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ts_library")
4-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
3+
load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library")
54
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
65

76
ng_module(

packages/examples/core/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "jasmine_node_test", "ng_module", "ts_library")
4-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
3+
load("//tools:defaults.bzl", "jasmine_node_test", "ng_module", "protractor_web_test_suite", "ts_library")
54
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
65

76
ng_module(

packages/examples/forms/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ts_library")
4-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
3+
load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library")
54
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
65

76
ng_module(

packages/examples/service-worker/push/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ts_library")
4-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
3+
load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library")
54
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
65

76
ng_module(

packages/examples/service-worker/registration-options/BUILD.bazel

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package(default_visibility = ["//visibility:public"])
22

3-
load("//tools:defaults.bzl", "ng_module", "ts_library")
4-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
3+
load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library")
54
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
65

76
ng_module(

packages/examples/upgrade/upgrade_example.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
load("//tools:defaults.bzl", "ng_module", "ts_library")
2-
load("@npm_bazel_protractor//:index.bzl", "protractor_web_test_suite")
1+
load("//tools:defaults.bzl", "ng_module", "protractor_web_test_suite", "ts_library")
32
load("@npm_bazel_typescript//:index.bzl", "ts_devserver")
43

54
"""

packages/zone.js/test/karma_test.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def karma_test(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps,
101101
":" + name + "_env_trim_map",
102102
] + bootstrap +
103103
_karma_test_required_dist_files,
104+
browsers = ["//tools/browsers:chromium"],
104105
static_files = [
105106
":assets/sample.json",
106107
":assets/worker.js",
@@ -123,6 +124,7 @@ def karma_test(name, env_srcs, env_deps, env_entry_point, test_srcs, test_deps,
123124
":" + name + "_env_trim_map",
124125
"//packages/zone.js/dist:zone-testing-bundle-dist-test",
125126
] + _karma_test_required_dist_files,
127+
browsers = ["//tools/browsers:chromium"],
126128
config_file = "//:karma-js.conf.js",
127129
configuration_env_vars = ["KARMA_WEB_TEST_MODE"],
128130
data = [

tools/browsers/BUILD.bazel

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2016 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
################################################################################
16+
#
17+
load("@io_bazel_rules_webtesting//web:web.bzl", "browser", "web_test_archive")
18+
19+
# Override of chromium web_test_archive so that the archive is selected based on platform
20+
web_test_archive(
21+
name = "chromium_archive",
22+
testonly = True,
23+
archive = select({
24+
"@io_bazel_rules_webtesting//common/conditions:linux": "@org_chromium_chromium_amd64//file",
25+
"@io_bazel_rules_webtesting//common/conditions:mac": "@org_chromium_chromium_macos//file",
26+
"@io_bazel_rules_webtesting//common/conditions:windows": "@org_chromium_chromium_windows//file",
27+
}),
28+
extract = "build",
29+
named_files = select({
30+
"@io_bazel_rules_webtesting//common/conditions:linux": {"CHROMIUM": "chrome-linux/chrome"},
31+
"@io_bazel_rules_webtesting//common/conditions:mac": {"CHROMIUM": "chrome-mac/Chromium.app/Contents/MacOS/chromium"},
32+
"@io_bazel_rules_webtesting//common/conditions:windows": {"CHROMIUM": "chrome-win/chrome.exe"},
33+
}),
34+
visibility = ["//tools/browsers:__subpackages__"],
35+
)
36+
37+
# Override of chromedriver web_test_archive so that the archive is selected based on platform
38+
web_test_archive(
39+
name = "chromedriver_archive",
40+
testonly = True,
41+
archive = select({
42+
"@io_bazel_rules_webtesting//common/conditions:linux": "@org_chromium_chromedriver_amd64//file",
43+
"@io_bazel_rules_webtesting//common/conditions:mac": "@org_chromium_chromedriver_macos//file",
44+
"@io_bazel_rules_webtesting//common/conditions:windows": "@org_chromium_chromedriver_windows//file",
45+
}),
46+
extract = "build",
47+
named_files = select({
48+
"@io_bazel_rules_webtesting//common/conditions:linux": {
49+
"CHROMEDRIVER": "chromedriver_linux64/chromedriver",
50+
},
51+
"@io_bazel_rules_webtesting//common/conditions:mac": {
52+
"CHROMEDRIVER": "chromedriver_mac64/chromedriver",
53+
},
54+
"@io_bazel_rules_webtesting//common/conditions:windows": {
55+
"CHROMEDRIVER": "chromedriver_win32/chromedriver.exe",
56+
},
57+
}),
58+
visibility = ["//tools/browsers:__subpackages__"],
59+
)
60+
61+
browser(
62+
name = "chromium",
63+
metadata = "chromium.json",
64+
visibility = ["//visibility:public"],
65+
deps = [
66+
":chromedriver_archive",
67+
":chromium_archive",
68+
"@io_bazel_rules_webtesting//go/wsl",
69+
],
70+
)
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Copyright 2018 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Pinned browser versions.
16+
17+
This function is here to make browser repositories work with cross-platform RBE.
18+
Unlike the rules_webtesting browser_repositories, this function defines
19+
separate repositories for each platform
20+
"""
21+
22+
load("@io_bazel_rules_webtesting//web/internal:platform_http_file.bzl", _platform_http_file = "platform_http_file")
23+
24+
def platform_http_file(name, licenses, sha256, urls):
25+
"""Platform spepcific browser repository.
26+
27+
This works around a dificiency in io_bazel_rules_webtesting platform_http_file in that
28+
it selects the platform when the repository rule is executed. This limits browsers
29+
tests to run on the local user platform only. For cross-platform RBE we want a repository
30+
to be defined per platform so the correct one can be selected.
31+
"""
32+
33+
_platform_http_file(
34+
name = name,
35+
amd64_sha256 = sha256,
36+
amd64_urls = urls,
37+
licenses = licenses,
38+
macos_sha256 = sha256,
39+
macos_urls = urls,
40+
windows_sha256 = sha256,
41+
windows_urls = urls,
42+
)
43+
44+
def browser_repositories():
45+
"""Load pinned rules_webtesting browser versions."""
46+
47+
platform_http_file(
48+
name = "org_chromium_chromium_amd64",
49+
licenses = ["notice"], # BSD 3-clause (maybe more?)
50+
sha256 = "b1e30c4dec8a451f8fe10d1f2d3c71e491d0333425f32247fe5c80a0a354303d",
51+
urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/664981/chrome-linux.zip"],
52+
)
53+
54+
platform_http_file(
55+
name = "org_chromium_chromium_macos",
56+
licenses = ["notice"], # BSD 3-clause (maybe more?)
57+
sha256 = "7c0ba93616f44a421330b1c1262e8899fbdf7916bed8b04c775e0426f6f35ec6",
58+
urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/665002/chrome-mac.zip"],
59+
)
60+
61+
platform_http_file(
62+
name = "org_chromium_chromium_windows",
63+
licenses = ["notice"], # BSD 3-clause (maybe more?)
64+
sha256 = "f2facd0066270078d0e8999e684595274c359cac3946299a1ceedba2a5de1c63",
65+
urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/664999/chrome-win.zip"],
66+
)
67+
68+
platform_http_file(
69+
name = "org_chromium_chromedriver_amd64",
70+
licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT
71+
sha256 = "0ead02145854b60a3317b59031205b362fb4cfdb680fef20e95c89582e6e38be",
72+
urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Linux_x64/664981/chromedriver_linux64.zip"],
73+
)
74+
75+
platform_http_file(
76+
name = "org_chromium_chromedriver_macos",
77+
licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT
78+
sha256 = "8dd159e27b13b16262afa6993b15321e736c3b484da363c0e03bb050d72522c9",
79+
urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/665002/chromedriver_mac64.zip"],
80+
)
81+
82+
platform_http_file(
83+
name = "org_chromium_chromedriver_windows",
84+
licenses = ["reciprocal"], # BSD 3-clause, ICU, MPL 1.1, libpng (BSD/MIT-like), Academic Free License v. 2.0, BSD 2-clause, MIT
85+
sha256 = "1cc881364974102182257a5c5c2b9cfed513689dee28924ca44df082bdf9fd60",
86+
urls = ["https://commondatastorage.googleapis.com/chromium-browser-snapshots/Win/664999/chromedriver_win32.zip"],
87+
)

tools/browsers/chromium.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"environment" : "local",
3+
"capabilities" : {
4+
"browserName" : "chrome",
5+
"goog:chromeOptions" : {
6+
"binary" : "%FILE:CHROMIUM%",
7+
"args" : [
8+
"--headless",
9+
"--use-gl=swiftshader-webgl"
10+
]
11+
},
12+
"google:wslConfig": {
13+
"binary": "%FILE:CHROMEDRIVER%",
14+
"port":"%WSLPORT:WSL%",
15+
"args": ["--port=%WSLPORT:WSL%"],
16+
"status": true,
17+
"shutdown": true
18+
}
19+
}
20+
}

tools/defaults.bzl

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load("@build_bazel_rules_nodejs//:index.bzl", _nodejs_binary = "nodejs_binary",
44
load("@npm_bazel_jasmine//:index.bzl", _jasmine_node_test = "jasmine_node_test")
55
load("@npm_bazel_karma//:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
66
load("@npm_bazel_typescript//:index.bzl", _ts_library = "ts_library")
7+
load("@npm_bazel_protractor//:index.bzl", _protractor_web_test_suite = "protractor_web_test_suite")
78
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
89
load("//tools/ng_rollup_bundle:ng_rollup_bundle.bzl", _ng_rollup_bundle = "ng_rollup_bundle")
910
load("//tools:ng_benchmark.bzl", _ng_benchmark = "ng_benchmark")
@@ -203,28 +204,19 @@ def karma_web_test_suite(bootstrap = [], deps = [], runtime_deps = [], **kwargs)
203204
"//tools/testing:browser",
204205
] + runtime_deps
205206

206-
tags = kwargs.pop("tags", [])
207-
208-
# rules_webtesting has a required_tag "native" for `chromium-local` browser
209-
if not "native" in tags:
210-
tags = tags + ["native"]
211-
212207
_karma_web_test_suite(
213208
runtime_deps = local_runtime_deps,
214209
bootstrap = bootstrap,
215210
deps = local_deps,
216-
# Run unit tests on local Chromium by default.
217-
# You can exclude tests based on tags, e.g. to skip Firefox testing,
218-
# `yarn bazel test --test_tag_filters=-browser:firefox-local [targets]`
219-
browsers = [
220-
"@io_bazel_rules_webtesting//browsers:chromium-local",
221-
# Don't test on local Firefox by default, for faster builds.
222-
# We think that bugs in Angular tend to be caught the same in any
223-
# evergreen browser.
224-
# "@io_bazel_rules_webtesting//browsers:firefox-local",
225-
# TODO(alexeagle): add remote browsers on SauceLabs
226-
],
227-
tags = tags,
211+
browsers = ["//tools/browsers:chromium"],
212+
**kwargs
213+
)
214+
215+
def protractor_web_test_suite(**kwargs):
216+
"""Default values for protractor_web_test_suite"""
217+
218+
_protractor_web_test_suite(
219+
browsers = ["//tools/browsers:chromium"],
228220
**kwargs
229221
)
230222

0 commit comments

Comments
 (0)