From bfd48391d7a91ff42739a2c4007743a81748342f Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 29 Jul 2021 20:59:31 +0200 Subject: [PATCH] fix(dev-infra): browser archive rule should handle `.dmg` files (#42992) We recently reworked our browser archive extraction to happen at analysis time for better caching. This resulted in us breaking the extraction of macOS dmg files so that Firefox is currently not usable for local testing on macOS. We implement a similar special logic for `.dmg` files to what has been done within the Bazel webtesting rules. PR Close #42992 --- .../bazel/browsers/browser_archive_repo.bzl | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/dev-infra/bazel/browsers/browser_archive_repo.bzl b/dev-infra/bazel/browsers/browser_archive_repo.bzl index 0d9cdeb215..c51c40336e 100644 --- a/dev-infra/bazel/browsers/browser_archive_repo.bzl +++ b/dev-infra/bazel/browsers/browser_archive_repo.bzl @@ -1,11 +1,27 @@ """Implementation of the `browser_archive` rule.""" def _browser_archive_impl(ctx): - ctx.report_progress("Downloading browser archive from: %s" % ctx.attr.url) - ctx.download_and_extract( - url = ctx.attr.url, - sha256 = ctx.attr.sha256, - ) + url = ctx.attr.url + sha256 = ctx.attr.sha256 + + # If the URL resolves to a `.dmg` file, then we need to convert the file + # to a zip so that we can extract the actual binaries. We use the `convert_dmg` + # script provided by the webtesting Bazel rules. + if url.endswith(".dmg"): + download_file_name = "_download_file_%s.dmg" % ctx.attr.name + result_zip_name = "_converted_file_%s.zip" % ctx.attr.name + + ctx.download(url, download_file_name, sha256) + ctx.execute([ctx.path(Label("@io_bazel_rules_webtesting//web/internal:convert_dmg.sh")), download_file_name, result_zip_name]) + ctx.extract(result_zip_name) + + ctx.delete(result_zip_name) + ctx.delete(download_file_name) + else: + ctx.download_and_extract( + url = url, + sha256 = sha256, + ) # The browser archive has been downloaded and extracted. We now generate a repository # `BUILD.bazel` file that exposes the archive files, together with the specified