diff --git a/common/BUILD.bazel b/common/BUILD.bazel index bdbd57da83007..29fa09d3bb531 100644 --- a/common/BUILD.bazel +++ b/common/BUILD.bazel @@ -1,5 +1,19 @@ +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + package(default_visibility = ["//visibility:public"]) +bool_flag( + name = "pin_browsers", + build_setting_default = False +) + +config_setting( + name = "use_pinned_browser", + flag_values = { + ":pin_browsers": "true", + }, +) + config_setting( name = "linux", constraint_values = ["@platforms//os:linux"], @@ -30,6 +44,7 @@ config_setting( name = "use_local_chromedriver", flag_values = { "@local_drivers//:use_chromedriver": "true", + ":pin_browsers": "false", }, ) @@ -42,6 +57,7 @@ config_setting( name = "use_local_geckodriver", flag_values = { "@local_drivers//:use_geckodriver": "true", + ":pin_browsers": "false", }, ) @@ -54,5 +70,22 @@ config_setting( name = "use_local_msedgedriver", flag_values = { "@local_drivers//:use_msedgedriver": "true", + ":pin_browsers": "false", }, ) + +[ + [ + config_setting( + name = "use_pinned_%s_%s" % (platform, browser), + flag_values = { + ":pin_browsers": "true", + }, + constraint_values = [ + "@platforms//os:%s" % platform, + ], + ) + + for platform in ["linux", "macos", "windows"]] + + for browser in ["chrome", "edge", "firefox"]] diff --git a/common/private/convert_dmg.sh b/common/private/convert_dmg.sh new file mode 100755 index 0000000000000..d4427781209de --- /dev/null +++ b/common/private/convert_dmg.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# Copyright 2018 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. +# +################################################################################ +# + +DMGFILE=$1 +OUTFILE=$2 +mkdir -p tmp +VOLUME=$(hdiutil attach "${DMGFILE}" | tail -1 | awk '{print $3}') +cp -r "${VOLUME}/"*.app tmp +hdiutil detach "${VOLUME}" >/dev/null +cd tmp +zip -r "../${OUTFILE}" * +cd .. +rm -rf tmp +rm "${DMGFILE}" diff --git a/common/private/dmg_archive.bzl b/common/private/dmg_archive.bzl new file mode 100644 index 0000000000000..759d85a0d819f --- /dev/null +++ b/common/private/dmg_archive.bzl @@ -0,0 +1,43 @@ + +def _dmg_archive_impl(repository_ctx): + url = repository_ctx.attr.url + (ignored, ignored, dmg_name) = url.rpartition("/") + dmg_name = dmg_name.replace("%20", "_") + + attrs = { + "output": dmg_name + } + if repository_ctx.attr.sha256: + attrs.update({"sha256": repository_ctx.attr.sha256}) + + repository_ctx.download( + url, + **attrs, + ) + + zip_name = dmg_name.replace(".dmg", ".zip") + repository_ctx.execute([ + repository_ctx.path(Label("//common/private:convert_dmg.sh")), dmg_name, zip_name]) + + repository_ctx.extract( + archive = zip_name, + stripPrefix = repository_ctx.attr.strip_prefix, + ) + + repository_ctx.file( + "BUILD.bazel", + repository_ctx.attr.build_file_content, + ) + +dmg_archive = repository_rule( + _dmg_archive_impl, + attrs = { + "url": attr.string( + mandatory = True, + ), + "sha256": attr.string(), + "strip_prefix": attr.string(), + "build_file_content": attr.string(), + "build_file": attr.label(), + } +) diff --git a/common/private/pkg_archive.bzl b/common/private/pkg_archive.bzl new file mode 100644 index 0000000000000..f6a8b2848f5f6 --- /dev/null +++ b/common/private/pkg_archive.bzl @@ -0,0 +1,40 @@ + +def _pkg_archive_impl(repository_ctx): + url = repository_ctx.attr.url + (ignored, ignored, pkg_name) = url.rpartition("/") + idx = pkg_name.find("?") + if idx != -1: + pkg_name = pkg_name[0:idx] + pkg_name = pkg_name.replace("%20", "_") + + attrs = { + "output": pkg_name + ".download" + } + if repository_ctx.attr.sha256: + attrs.update({"sha256": repository_ctx.attr.sha256}) + + repository_ctx.download( + url, + **attrs, + ) + + repository_ctx.execute([ + repository_ctx.which("pkgutil"), "--expand-full", pkg_name + ".download", pkg_name]) + + for (key, value) in repository_ctx.attr.move.items(): + repository_ctx.execute(["mv", pkg_name + "/" + key, value]) + + repository_ctx.file("BUILD.bazel", repository_ctx.attr.build_file_content) + +pkg_archive = repository_rule( + _pkg_archive_impl, + attrs = { + "url": attr.string( + mandatory = True, + ), + "sha256": attr.string(), + "move": attr.string_dict(), + "build_file_content": attr.string(), + "build_file": attr.label(), + } +) diff --git a/common/repositories.bzl b/common/repositories.bzl index bb770be29793b..cfdb3b41a1817 100644 --- a/common/repositories.bzl +++ b/common/repositories.bzl @@ -1,6 +1,201 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("//common/private:dmg_archive.bzl", "dmg_archive") load("//common/private:drivers.bzl", "local_drivers") +load("//common/private:pkg_archive.bzl", "pkg_archive") + +_edge_version = "89.0.713.0" + +_versions = { + # The chrome version number is found by visiting http://omahaproxy.appspot.com, + # looking for the current stable version for any platform, and using the "lookup" + # feature to find out "Version information". The "Branch Base Position" gives you + # the version. + # 800218 = 86.0.4240.198 + "chrome": { + "linux": { + "url": "https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/800218/chrome-linux.zip", + "sha256": "01140ec2c7f397023541f65ecd26cf8c5b9a59af90c887dbf7c3ee0344870077", + }, + "mac": { + "url": "https://storage.googleapis.com/chromium-browser-snapshots/Mac/800218/chrome-mac.zip", + "sha256": "2e0a534510dba96a4e52effb31bede2cababc9328e624c8c538867f8e71b6292", + }, + "windows": { + "url": "https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/800218/chrome-win.zip", + "sha256": None, + }, + }, + # Versions found by visiting https://chromedriver.chromium.org/downloads + "chromedriver": { + "linux": { + "url": "https://chromedriver.storage.googleapis.com/86.0.4240.22/chromedriver_linux64.zip", + "sha256": "d498eaacc414adbaf638333b59390cdfea5d780f941f57f41fd90280df78b159", + }, + "mac": { + "url": "https://chromedriver.storage.googleapis.com/86.0.4240.22/chromedriver_mac64.zip", + "sha256": "351ae30e9feab7ca6ccb94a549afcd62d6355561b78b8386cd4271d480a2fdc6", + }, + "windows": { + "url": "https://chromedriver.storage.googleapis.com/86.0.4240.22/chromedriver_win32.zip", + "sha256": None, + }, + }, + # Ultimately, this will is determined by visiting https://www.microsoft.com/en-us/edge + "edge": { + "linux": { + "url": None, + "sha256": None, + }, + "mac": { + "url": "https://officecdn-microsoft-com.akamaized.net/pr/C1297A47-86C4-4C1F-97FA-950631F94777/MacAutoupdate/MicrosoftEdgeCanary-89.0.713.0.pkg?platform=Mac&Consent=0&channel=Canary", + "sha256": "25dfe56b00d5f0af1f9d7ed3d84442fd9d783aa2abe1be93c9ea8e7088f5e5c6", + }, + "windows": { + "url": None, + "sha256": None, + }, + }, + # Versions found by visiting https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ + "edgedriver": { + "linux": { + "url": None, + "sha256": "d498eaacc414adbaf638333b59390cdfea5d780f941f57f41fd90280df78b159", + }, + "mac": { + "url": "https://msedgedriver.azureedge.net/%s/edgedriver_mac64.zip" % _edge_version, + "sha256": "0282fa65d7f303f59fc4f8001b3d1ce25a44b0394a449f18291f68b6d0f9e691", + }, + "windows": { + "url": "https://msedgedriver.azureedge.net/87.0.669.0/edgedriver_win64.zip", + "sha256": None, + }, + }, + # Versions found by visiting https://ftp.mozilla.org/pub/firefox/releases/ + "firefox": { + "linux": { + "url": "https://ftp.mozilla.org/pub/firefox/releases/83.0/linux-x86_64/en-US/firefox-83.0.tar.bz2", + "sha256": "93ff827fdcba92ddb71851c46ac8192a727ed61402e896c6262943e382f92412", + }, + "mac": { + "url": "https://ftp.mozilla.org/pub/firefox/releases/83.0/mac/en-US/Firefox%2083.0.dmg", + "sha256": "7e527884e40039c6c97929591754b92394aa965fd61d42158fea5df075636ec6", + }, + "windows": { + "url": None, + "sha256": None, + }, + }, + # Versions found by visiting https://github.com/mozilla/geckodriver/releases + "geckodriver": { + "linux": { + "url": "https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz", + "sha256": "61bfc547a623d7305256611a81ecd24e6bf9dac555529ed6baeafcf8160900da", + }, + "mac": { + "url": "https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-macos.tar.gz", + "sha256": "c288ff6db39adfd5eea0e25b4c3e71bfd9fb383eccf521cdd65f67ea78eb1761", + }, + "windows": { + "url": None, + "sha256": None, + }, + }, +} + +def _chrome(): + http_archive( + name = "linux_chromedriver", + url = _versions["chromedriver"]["linux"]["url"], + sha256 = _versions["chromedriver"]["linux"]["sha256"], + build_file_content = "exports_files([\"chromedriver\"])", + ) + + http_archive( + name = "linux_chrome", + url = _versions["chrome"]["linux"]["url"], + sha256 = _versions["chrome"]["linux"]["sha256"], + build_file_content = "exports_files([\"chrome\"])", + ) + + http_archive( + name = "mac_chromedriver", + url = _versions["chromedriver"]["mac"]["url"], + sha256 = _versions["chromedriver"]["mac"]["sha256"], + build_file_content = "exports_files([\"chromedriver\"])", + ) + + http_archive( + name = "mac_chrome", + url = _versions["chrome"]["mac"]["url"], + sha256 = _versions["chrome"]["mac"]["sha256"], + strip_prefix = "chrome-mac", + build_file_content = "exports_files([\"Chromium.app\"])", + ) + +def _edge(): + http_archive( + name = "mac_edgedriver", + url = _versions["edgedriver"]["mac"]["url"], + sha256 = _versions["edgedriver"]["mac"]["sha256"], + build_file_content = "exports_files([\"msedgedriver\"])", + ) + + pkg_archive( + name = "mac_edge", + url = _versions["edge"]["mac"]["url"], + sha256 = _versions["edge"]["mac"]["sha256"], + move = { + "MicrosoftEdgeCanary-%s.pkg/Payload/Microsoft Edge Canary.app" % _edge_version: "Edge.app", + }, + build_file_content = "exports_files([\"Edge.app\"])", + ) + +def _firefox(): + http_archive( + name = "linux_geckodriver", + url = _versions["geckodriver"]["linux"]["url"], + sha256 = _versions["geckodriver"]["linux"]["sha256"], + build_file_content = "exports_files([\"geckodriver\"])", + ) + + http_archive( + name = "linux_firefox", + url = _versions["firefox"]["linux"]["url"], + sha256 = _versions["firefox"]["linux"]["sha256"], + build_file_content = "exports_files([\"firefox\"])", + ) + + http_archive( + name = "mac_geckodriver", + url = _versions["geckodriver"]["mac"]["url"], + sha256 = _versions["geckodriver"]["mac"]["sha256"], + build_file_content = "exports_files([\"geckodriver\"])", + ) + + dmg_archive( + name = "mac_firefox", + url = _versions["firefox"]["mac"]["url"], + sha256 = _versions["firefox"]["mac"]["sha256"], + build_file_content = "exports_files([\"Firefox.app\"])", + ) + + # TODO: figure out how to unpack the firefox exe on Windows +# http_archive( +# name = "windows_geckodriver", +# url = "https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-win64.zip", +# sha256 = "49f991b4f25565a5b7008936698f189debc755e6023789adba0c7440b6c960ac", +# build_file_content = "alias(name = \"geckodriver\", actual = \"geckodriver.exe\", visibility = [\"//visibility:public\"])", +# ) +# +# +# http_archive( +# name = "windows_firefox", +# url = "https://ftp.mozilla.org/pub/firefox/releases/83.0/win64/en-US/Firefox%20Setup%2083.0.exe", +# +# ) def pin_browsers(): local_drivers() - + _chrome() + _edge() + _firefox() diff --git a/java/browsers.bzl b/java/browsers.bzl index 7e24493edf1ff..e5848ac9c7910 100644 --- a/java/browsers.bzl +++ b/java/browsers.bzl @@ -1,41 +1,81 @@ chrome_data = select({ - "//common:use_local_chromedriver": ["//common:chromedriver"], - "//conditions:default": [] + "//common:use_pinned_linux_chrome": [ + "@linux_chromedriver//:chromedriver", + "@linux_chrome//:chrome-linux", + ], + "//common:use_pinned_macos_chrome": [ + "@mac_chromedriver//:chromedriver", + "@mac_chrome//:Chromium.app", + ], + "//common:use_local_chromedriver": ["//common:chromedriver"], + "//conditions:default": [], }) chrome_jvm_flags = select({ - "//common:use_local_chromedriver": [ - "-Dwebdriver.chrome.driver=$(location //common:chromedriver)", - ], - "//conditions:default": [ - "-Dselenium.skiptest=true", - ], + "//common:use_pinned_linux_chrome": [ + "-Dwebdriver.chrome.driver=$(location @linux_chromedriver//:chromedriver)", + "-Dwebdriver.chrome.binary=$(location @linux_chome//:chrome-linux)/linux-chrome/chrome", + ], + "//common:use_pinned_macos_chrome": [ + "-Dwebdriver.chrome.driver=$(location @mac_chromedriver//:chromedriver)", + "-Dwebdriver.chrome.binary=$(location @mac_chrome//:Chromium.app)/Contents/MacOS/Chromium", + ], + "//common:use_local_chromedriver": [ + "-Dwebdriver.chrome.driver=$(location //common:chromedriver)", + ], + "//conditions:default": [ + "-Dselenium.skiptest=true", + ], }) -firefox_data = select({ - "//common:use_local_geckodriver": ["//common:geckodriver"], - "//conditions:default": [] +edge_data = select({ + "//common:use_pinned_macos_chrome": [ + "@mac_edgedriver//:msedgedriver", + "@mac_edge//:Edge.app", + ], + "//common:use_local_msedgedriver": ["//common:msedgedriver"], + "//conditions:default": [], }) -firefox_jvm_flags = select({ - "//common:use_local_geckodriver": [ - "-Dwebdriver.gecko.driver=$(location //common:geckodriver)", - ], - "//conditions:default": [ - "-Dselenium.skiptest=true", - ], +edge_jvm_flags = select({ + "//common:use_pinned_macos_edge": [ + "-Dwebdriver.edge.driver=$(location @mac_edgedriver//:msedgedriver)", + "-Dwebdriver.edge.binary=\"$(location @mac_edge//:Edge.app)/Contents/MacOS/Microsoft Edge Canary\"", + ], + "//common:use_local_msedgedriver": [ + "-Dwebdriver.edge.driver=$(location //common:msedgedriver)", + ], + "//conditions:default": [ + "-Dselenium.skiptest=true", + ], }) -edge_data = select({ - "//common:use_local_msedgedriver": ["//common:msedgedriver"], - "//conditions:default": [] +firefox_data = select({ + "//common:use_pinned_linux_firefox": [ + "@linux_geckodriver//:geckodriver", + "@linux_firefox//:firefox", + ], + "//common:use_pinned_macos_firefox": [ + "@mac_geckodriver//:geckodriver", + "@mac_firefox//:Firefox.app", + ], + "//common:use_local_geckodriver": ["//common:geckodriver"], + "//conditions:default": [], }) -edge_jvm_flags = select({ - "//common:use_local_msedgedriver": [ - "-Dwebdriver.edge.driver=$(location //common:msedgedriver)", - ], - "//conditions:default": [ - "-Dselenium.skiptest=true", - ], +firefox_jvm_flags = select({ + "//common:use_pinned_linux_firefox": [ + "-Dwebdriver.gecko.driver=$(location @linux_geckodriver//:geckodriver)", + "-Dwebdriver.firefox.bin=$(location @linux_firefox//:firefox)/firefox", + ], + "//common:use_pinned_macos_firefox": [ + "-Dwebdriver.gecko.driver=$(location @mac_geckodriver//:geckodriver)", + "-Dwebdriver.firefox.bin=$(location @mac_firefox//:Firefox.app)/Contents/MacOS/firefox", + ], + "//common:use_local_geckodriver": [ + "-Dwebdriver.gecko.driver=$(location //common:geckodriver)", + ], + "//conditions:default": [ + "-Dselenium.skiptest=true", + ], }) diff --git a/java/defs.bzl b/java/defs.bzl index 9820168f764bc..f36f0e8c9a5c8 100644 --- a/java/defs.bzl +++ b/java/defs.bzl @@ -9,8 +9,6 @@ load("//java/private:javadoc.bzl", _javadoc = "javadoc") load("//java/private:module.bzl", _java_module = "java_module") load("//java/private:spotbugs_config.bzl", _spotbugs_config = "spotbugs_config") load("//java/private:suite.bzl", _java_selenium_test_suite = "java_selenium_test_suite", _java_test_suite = "java_test_suite") -#load("//java/private:suite.bzl", _java_test_suite = "java_test_suite") -#load("//java/private:selenium_suite.bzl", _java_selenium_test_suite = "java_selenium_test_suite") java_binary = _java_binary java_dist_zip = _java_dist_zip