Skip to content

Commit

Permalink
build: fixes for cross-platform RBE
Browse files Browse the repository at this point in the history
* patch for build_bazel_rules_nodejs from bazel-contrib/rules_nodejs#1320
* patch for @bazel/protractor from bazel-contrib/rules_nodejs#1320
* work-around for rules_webtesting cross-platform RBE issues
  • Loading branch information
josephperrott authored and gregmagolan committed Nov 9, 2019
1 parent 1d429b2 commit b0dc0f4
Show file tree
Hide file tree
Showing 19 changed files with 653 additions and 55 deletions.
12 changes: 6 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ http_archive(
name = "build_bazel_rules_nodejs",
patch_args = ["-p1"],
# Patch https://github.com/bazelbuild/rules_nodejs/pull/903
patches = ["//tools:rollup_bundle_commonjs_ignoreGlobal.patch"],
patches = [
"//tools:rules_nodejs_pull_1320.patch",
"//tools:rollup_bundle_commonjs_ignoreGlobal.patch",
],
sha256 = "3d7296d834208792fa3b2ded8ec04e75068e3de172fae79db217615bd75a6ff7",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.39.1/rules_nodejs-0.39.1.tar.gz"],
)
Expand Down Expand Up @@ -113,12 +116,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")
Expand Down
2 changes: 1 addition & 1 deletion modules/benchmarks/benchmark_test.bzl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions modules/playground/e2e_test/example_test.bzl
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"bazel:lint": "yarn bazel:format --lint=warn",
"bazel:lint-fix": "yarn bazel:format --lint=fix",
"preinstall": "node tools/yarn/check-yarn.js",
"postinstall": "yarn update-webdriver && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
"postinstall": "yarn update-webdriver && patch-package && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
"update-webdriver": "webdriver-manager update --gecko false $CI_CHROMEDRIVER_VERSION_ARG",
"check-env": "gulp check-env",
"commitmsg": "node ./scripts/git/commit-msg.js",
Expand Down Expand Up @@ -159,6 +159,7 @@
"karma-sourcemap-loader": "^0.3.7",
"madge": "0.5.0",
"mutation-observer": "^1.0.3",
"patch-package": "^6.2.0",
"rewire": "2.5.2",
"sauce-connect": "https://saucelabs.com/downloads/sc-4.5.1-linux.tar.gz",
"semver": "^6.3.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/compiler-cli/integrationtest/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/common/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/core/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/forms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/service-worker/push/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
3 changes: 1 addition & 2 deletions packages/examples/upgrade/upgrade_example.bzl
Original file line number Diff line number Diff line change
@@ -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")

"""
Expand Down
2 changes: 2 additions & 0 deletions packages/zone.js/test/karma_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 = [
Expand Down
108 changes: 108 additions & 0 deletions patches/@bazel+protractor+0.39.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
diff --git a/node_modules/@bazel/protractor/protractor.conf.js b/node_modules/@bazel/protractor/protractor.conf.js
index 6f81d40..9f960b8 100755
--- a/node_modules/@bazel/protractor/protractor.conf.js
+++ b/node_modules/@bazel/protractor/protractor.conf.js
@@ -15,6 +15,7 @@
* limitations under the License.
*/
const path = require('path');
+const child_process = require('child_process');

function log_verbose(...m) {
// This is a template file so we use __filename to output the actual filename
@@ -43,6 +44,49 @@ function setConf(conf, name, value, msg) {
conf[name] = value;
}

+/**
+ * Helper function to find a particular namedFile
+ * within the webTestMetadata webTestFiles
+ */
+function findNamedFile(webTestMetadata, key) {
+ let result;
+ webTestMetadata['webTestFiles'].forEach(entry => {
+ const webTestNamedFiles = entry['namedFiles'];
+ if (webTestNamedFiles && webTestNamedFiles[key]) {
+ if (entry['archiveFile']) {
+ const extractExe = findNamedFile(webTestMetadata, 'EXTRACT_EXE');
+ result = extractWebArchive(extractExe, entry['archiveFile'], webTestNamedFiles[key]);
+ } else {
+ result = require.resolve(webTestNamedFiles[key]);
+ }
+ }
+ });
+ return result;
+}
+
+/**
+ * Helper function to extract a browser archive
+ * and return the path to extracted executable
+ */
+function extractWebArchive(extractExe, archiveFile, executablePath) {
+ try {
+ if (!extractExe) {
+ throw new Error('No EXTRACT_EXE found');
+ }
+ extractExe = require.resolve(extractExe);
+ archiveFile = require.resolve(archiveFile);
+ const extractedExecutablePath = path.join(process.cwd(), executablePath);
+ child_process.execFileSync(
+ extractExe, [archiveFile, '.'], {stdio: [process.stdin, process.stdout, process.stderr]});
+ log_verbose(
+ `Extracting web archive ${archiveFile} with ${extractExe} to ${extractedExecutablePath}`);
+ return extractedExecutablePath;
+ } catch (e) {
+ console.error(`Failed to extract ${archiveFile}`);
+ throw e;
+ }
+}
+
function mergeCapabilities(conf, capabilities) {
if (conf.capabilities) {
if (conf.capabilities.browserName === capabilities.browserName) {
@@ -139,12 +183,11 @@ if (process.env['WEB_TEST_METADATA']) {
// "@io_bazel_rules_webtesting//browsers:firefox-local"
// then the 'environment' will equal 'local' and
// 'webTestFiles' will contain the path to the binary to use
- const webTestNamedFiles = webTestMetadata['webTestFiles'][0]['namedFiles'];
const headless = !process.env['DISPLAY'];
- if (webTestNamedFiles['CHROMIUM']) {
- const chromeBin = require.resolve(webTestNamedFiles['CHROMIUM']);
- const chromeDriver = require.resolve(webTestNamedFiles['CHROMEDRIVER']);
-
+ const chromeBin = findNamedFile(webTestMetadata, 'CHROMIUM');
+ const chromeDriver = findNamedFile(webTestMetadata, 'CHROMEDRIVER');
+ console.error(JSON.stringify(webTestMetadata, null, 2))
+ if (chromeBin && chromeDriver) {
// The sandbox needs to be disabled, because it causes Chrome to crash on some environments.
// See: http://chromedriver.chromium.org/help/chrome-doesn-t-start
const args = ['--no-sandbox'];
@@ -161,25 +204,9 @@ if (process.env['WEB_TEST_METADATA']) {
}
});
}
- if (webTestNamedFiles['FIREFOX']) {
- // TODO(gmagolan): implement firefox support for protractor
- throw new Error('Firefox not yet support by protractor_web_test_suite');
-
- // const firefoxBin = require.resolve(webTestNamedFiles['FIREFOX'])
- // const args = [];
- // if (headless) {
- // args.push("--headless")
- // args.push("--marionette")
- // }
- // setConf(conf, 'seleniumAddress', process.env.WEB_TEST_HTTP_SERVER.trim() + "/wd/hub", 'is
- // configured by Bazel for firefox browser')
- // mergeCapabilities(conf, {
- // browserName: "firefox",
- // 'moz:firefoxOptions': {
- // binary: firefoxBin,
- // args: args,
- // }
- // }, 'is determined by the browsers attribute');
+ else {
+ // TODO(gmagolan): implement support for other browsers
+ throw new Error('Only chrome supported by protractor_web_test_suite');
}
} else {
console.warn(`Unknown WEB_TEST_METADATA environment '${webTestMetadata['environment']}'`);
68 changes: 68 additions & 0 deletions tools/browsers/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# 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",
}),
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",
}),
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",
],
)
Loading

0 comments on commit b0dc0f4

Please sign in to comment.