Skip to content

Commit

Permalink
feat: add support for darwin m1 browsers (#427)
Browse files Browse the repository at this point in the history
* feat: add support for darwin m1 browsers

`rules_webtesting` currently extracts browser archives as part
of an build action. Additionally, the platform archive is determined
at repository creation using the `repository_ctx.os` property. This
breaks remote build execution, and also makes it impossible to support
darwin ARM64 because the os name is equal regardless of CPU.

This is a good opportunity to move the extraction from a build action
to the repository fetching (improving caching and being more Bazel-idiomatic).
Additionally, with this approach we will be able to select the browser
binaries at configuration time using `select`, allowing for darwin arm64,
and proper remote build execution.

More details can be found in the description of the `platform_archive`
rule.

* fixup! feat: add support for darwin m1 browsers

Make sure tests can run on Windows and fix Sauce-Connect path prefix issue
  • Loading branch information
devversion authored Sep 10, 2021
1 parent 21b7552 commit 6b2ef24
Show file tree
Hide file tree
Showing 38 changed files with 936 additions and 528 deletions.
9 changes: 9 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ test --test_env=SAUCE_ACCESS_KEY
test --test_env=TUNNEL_IDENTIFIER
test --test_env=BUILD_TAG
test --local_test_jobs=5

# Do not build runfile forests by default. If an execution strategy relies on runfile
# forests, the forest is created on-demand. See: https://github.com/bazelbuild/bazel/issues/6627
# and https://github.com/bazelbuild/bazel/commit/03246077f948f2790a83520e7dccc2625650e6df
# Note: This also works around an issue where Bazel does not support spaces in runfiles. The
# Chromium app files for Darwin contain files with spaces and this would break. For darwin though,
# the sandbox strategy is used anyway and runfile forests are not needed.
# Related Bazel bug: https://github.com/bazelbuild/bazel/issues/4327.
build --nobuild_runfile_links
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ bazel-*
*.pyc
.vs/*
user.bazelrc

.idea/
16 changes: 8 additions & 8 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,33 @@ web_test_repositories()

http_archive(
name = "io_bazel_rules_go",
sha256 = "313f2c7a23fecc33023563f082f381a32b9b7254f727a7dd2d6380ccc6dfe09b",
sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/rules_go/releases/download/0.19.3/rules_go-0.19.3.tar.gz",
"https://github.com/bazelbuild/rules_go/releases/download/0.19.3/rules_go-0.19.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.28.0/rules_go-v0.28.0.zip",
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()
go_register_toolchains(version = "1.16.5")

http_archive(
name = "bazel_gazelle",
sha256 = "be9296bfd64882e3c08e3283c58fcb461fa6dd3c171764fcc4cf322f60615a9b",
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/0.18.1/bazel-gazelle-0.18.1.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.23.0/bazel-gazelle-v0.23.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("//web/versioned:browsers-0.3.2.bzl", "browser_repositories")
load("//web/versioned:browsers-0.3.3.bzl", "browser_repositories")

browser_repositories(
chromium = True,
Expand Down
4 changes: 2 additions & 2 deletions browsers/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ browser(
browser(
name = "firefox-local",
disabled = select({
"//common/conditions:windows": "firefox not supported on windows",
"//common/conditions:windows_x64": "firefox not supported on windows",
"//conditions:default": None,
}),
metadata = "firefox-local.json",
required_tags = [
"native",
],
deps = select({
"//common/conditions:windows": [],
"//common/conditions:windows_x64": [],
"//conditions:default": [
"//go/wsl",
"//third_party/firefox",
Expand Down
2 changes: 1 addition & 1 deletion browsers/chromium-local.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"goog:chromeOptions" : {
"binary" : "%FILE:CHROMIUM%",
"args" : [
"--headless",
"--headless",
"--no-sandbox",
"--use-gl=swiftshader-webgl"
]
Expand Down
8 changes: 3 additions & 5 deletions build_files/metadata.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
#
################################################################################
#
load("//web/internal:executable_name.bzl", "get_platform_executable_name")

licenses(["notice"]) # Apache 2.0

alias(
name = "main",
actual = select({
"//common/conditions:linux": "linux_amd64_pure_stripped/main",
"//common/conditions:mac": "darwin_amd64_pure_stripped/main",
"//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
}),
actual = get_platform_executable_name(),
visibility = ["//visibility:public"],
testonly = True,
)
10 changes: 3 additions & 7 deletions build_files/wsl.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ licenses(["notice"]) # Apache 2.0

web_test_named_executable(
name = "wsl",
testonly = True,
alt_name = "WEBDRIVER_SERVER_LIGHT",
executable = select({
"//common/conditions:linux": "main/linux_amd64_pure_stripped/main",
"//common/conditions:mac": "main/darwin_amd64_pure_stripped/main",
"//common/conditions:windows": "main/windows_amd64_pure_stripped/main.exe",
}),
executable = "//go/wsl/main",
visibility = ["//visibility:public"],
testonly = True,
)
)
26 changes: 26 additions & 0 deletions build_files/wsl_main.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2019 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("//web/internal:executable_name.bzl", "get_platform_executable_name")

licenses(["notice"]) # Apache 2.0

alias(
name = "main",
actual = get_platform_executable_name(),
visibility = ["//visibility:public"],
testonly = True,
)
8 changes: 3 additions & 5 deletions build_files/wtl.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
#
################################################################################
#
load("//web/internal:executable_name.bzl", "get_platform_executable_name")

licenses(["notice"]) # Apache 2.0

alias(
name = "main",
actual = select({
"//common/conditions:linux": "linux_amd64_pure_stripped/main",
"//common/conditions:mac": "darwin_amd64_pure_stripped/main",
"//common/conditions:windows": "windows_amd64_pure_stripped/main.exe",
}),
actual = get_platform_executable_name(),
visibility = ["//visibility:public"],
testonly = True,
)
29 changes: 23 additions & 6 deletions common/conditions/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,33 @@ package(
)

config_setting(
name = "mac",
values = {"cpu": "darwin"},
name = "linux_x64",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "linux",
values = {"cpu": "k8"},
name = "macos_x64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "windows",
values = {"cpu": "x64_windows"},
name = "macos_arm64",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:aarch64",
],
)

config_setting(
name = "windows_x64",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
)
9 changes: 8 additions & 1 deletion go/metadata/main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
################################################################################
#
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//web/internal:executable_name.bzl", "get_platform_executable_name")

licenses(["notice"]) # Apache 2.0

Expand All @@ -31,14 +32,20 @@ go_binary(
testonly = True,
embed = [":go_default_library"],
visibility = ["//visibility:public"],
out = get_platform_executable_name(),
)

sh_test(
name = "merger_test",
srcs = ["merger_test.sh"],
data = [
":main",
"@bazel_tools//tools/bash/runfiles",
"//testdata",
":main",
],
# Pass the executable path so that the test can resolve the merger
# entry-point in a platform-agnostic way.
args = ["$(rootpath :main)"],
tags = ["noci"],

)
39 changes: 28 additions & 11 deletions go/metadata/main/merger_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,43 +16,60 @@
#
################################################################################
#

# --- begin runfiles.bash initialization v2 ---
# Copy-pasted from the Bazel Bash runfiles library v2. We need to copy the runfile
# helper code as we want to resolve Bazel targets through the runfiles (in order to
# make the test work on windows where runfiles are not symlinked). The runfile
# helpers expose a bash function called "rlocation" that can be used to resolve targets.
# https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---

set +e
printenv

error=0

# TODO(DrMarcII): Figure out how to not hard code this path.
merger=$TEST_SRCDIR/$TEST_WORKSPACE/go/metadata/main/linux_amd64_stripped/main
# The path to the merger is passed as `sh_test` attribute. This
# allows us to access the merger in a platform-agnostic way.
merger_root_path=${1}
merger=$(rlocation $TEST_WORKSPACE/${merger_root_path})

$merger --output $TEST_TMPDIR/out.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/chrome-linux.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/android-browser-gingerbread-nexus-s.json
$(rlocation $TEST_WORKSPACE/testdata/chrome-linux.json) \
$(rlocation $TEST_WORKSPACE/testdata/android-browser-gingerbread-nexus-s.json)

diff -b $TEST_TMPDIR/out.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/merger-result.json
$(rlocation $TEST_WORKSPACE/testdata/merger-result.json)
if [[ $? != 0 ]]; then
echo "Merge of chrome-linux.json with android-browser-gingerbread-nexus-s.json didn't equal merger-result.json."
error=1
fi

$merger --output $TEST_TMPDIR/out2.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/named-files1.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/named-files1.json
$(rlocation $TEST_WORKSPACE/testdata/named-files1.json) \
$(rlocation $TEST_WORKSPACE/testdata/named-files1.json)
if [[ $? != 0 ]]; then
echo "Merge of named-files1.json with itself failed."
error=1
fi

$merger --output $TEST_TMPDIR/out2.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/named-files1.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/named-files2.json
$(rlocation $TEST_WORKSPACE/testdata/named-files1.json) \
$(rlocation $TEST_WORKSPACE/testdata/named-files2.json)
if [[ $? == 0 ]]; then
echo "Expected merge of named-files1.json with named-files2.json to fail."
error=1
fi

$merger --output $TEST_TMPDIR/out2.json \
$TEST_SRCDIR/$TEST_WORKSPACE/testdata/bad-named-files.json
$(rlocation $TEST_WORKSPACE/testdata/bad-named-files.json)
if [[ $? == 0 ]]; then
echo "Expected load of bad-named-files.json to fail."
error=1
Expand Down
2 changes: 1 addition & 1 deletion go/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (m *Metadata) ToBytes() ([]byte, error) {
return json.MarshalIndent(m, "", " ")
}

// GetFilePath returns the path to a file specified by web_test_archive,
// GetFilePath returns the path to a file specified by platform_archive,
// web_test_named_executable, or web_test_named_file.
func (m *Metadata) GetFilePath(name string) (string, error) {
for _, a := range m.WebTestFiles {
Expand Down
8 changes: 7 additions & 1 deletion go/webdriver/webdriver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"log"
"net/http"
"path/filepath"
"net/url"
"os"
"strings"
Expand All @@ -39,11 +40,16 @@ func TestMain(m *testing.M) {
log.Fatal(err)
}

dir, err := bazel.Runfile("testdata/")
// Note: We resolve to a testdata file first and then retrieve compute the directory.
// This is necessary in order to support running this test on Windows. The runfile manifest
// only contains mappings for files, so there is no mapping for just the `testdata/` directory.
resolved_file, err := bazel.Runfile("io_bazel_rules_webtesting/testdata/BUILD.bazel")
if err != nil {
log.Fatal(err)
}

dir := filepath.Dir(resolved_file)

go func() {
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), http.FileServer(http.Dir(dir))))
}()
Expand Down
2 changes: 2 additions & 0 deletions go/wsl/main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
################################################################################
#
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//web/internal:executable_name.bzl", "get_platform_executable_name")

licenses(["notice"]) # Apache 2.0

Expand All @@ -30,4 +31,5 @@ go_binary(
name = "main",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
out = get_platform_executable_name(),
)
2 changes: 2 additions & 0 deletions go/wtl/main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
################################################################################
#
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//web/internal:executable_name.bzl", "get_platform_executable_name")

licenses(["notice"]) # Apache 2.0

Expand All @@ -34,4 +35,5 @@ go_binary(
testonly = True,
embed = [":go_default_library"],
visibility = ["//visibility:public"],
out = get_platform_executable_name(),
)
Loading

0 comments on commit 6b2ef24

Please sign in to comment.