Skip to content

[build] Support os architecture in pinned chrome browser#17268

Open
nvborisenko wants to merge 1 commit intoSeleniumHQ:trunkfrom
nvborisenko:bazel-pibrowsers-arch-chrome
Open

[build] Support os architecture in pinned chrome browser#17268
nvborisenko wants to merge 1 commit intoSeleniumHQ:trunkfrom
nvborisenko:bazel-pibrowsers-arch-chrome

Conversation

@nvborisenko
Copy link
Copy Markdown
Member

Now I can use Mac x64. Build system doesn't require arm.

💥 What does this PR do?

This pull request updates the way Chrome and Chromedriver binaries are pinned for Mac in the common/repositories.bzl file, making the process architecture-aware. The changes ensure that the correct binaries are fetched for either x86_64 or arm64 architectures, improving compatibility and reliability for Mac users on different hardware.

Architecture-aware browser pinning:

  • Modified the pin_browsers function to accept an arch parameter and determine the correct Chrome architecture (x64 for x86_64 and arm64 otherwise).
  • Updated the pin_browsers_extension implementation to pass the detected architecture from the build context to pin_browsers.

Conditional fetching of Mac Chrome/Chromedriver binaries:

  • Added logic to fetch and configure the correct Mac Chrome binary (mac_chrome) for x64 or arm64, including patch commands and build file setup.
  • Added similar architecture-aware logic for fetching the correct Mac Chromedriver binary (mac_chromedriver).
  • Extended the same conditional logic to the beta versions of both Chrome (mac_beta_chrome) and Chromedriver (mac_beta_chromedriver). [1] [2]

💡 Additional Considerations

Only chrome driver, enough for me at this time.

🔄 Types of changes

  • Bug fix (backwards compatible)
  • New feature (non-breaking change which adds functionality and tests!)

@qodo-code-review
Copy link
Copy Markdown
Contributor

Review Summary by Qodo

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add architecture-aware Chrome/Chromedriver binary pinning for macOS
• Support both x64 and arm64 architectures with conditional fetching
• Update pin_browsers function to accept architecture parameter
• Pass detected OS architecture from build context to browser pinning

Grey Divider

File Changes

1. common/repositories.bzl ✨ Enhancement +127/-38

Architecture-aware macOS Chrome binary pinning

• Modified pin_browsers() function signature to accept arch parameter
• Added architecture detection logic mapping x86_64 to x64 and others to arm64
• Implemented conditional http_archive calls for mac_chrome with architecture-specific URLs and
 checksums
• Implemented conditional http_archive calls for mac_chromedriver with architecture-specific
 URLs and checksums
• Extended same conditional logic to mac_beta_chrome and mac_beta_chromedriver binaries
• Updated _pin_browsers_extension_impl to pass _ctx.os.arch to pin_browsers() function

common/repositories.bzl


Grey Divider

Qodo Logo

@selenium-ci selenium-ci added the B-build Includes scripting, bazel and CI integrations label Mar 29, 2026
@qodo-code-review
Copy link
Copy Markdown
Contributor

qodo-code-review bot commented Mar 29, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (3) 📎 Requirement gaps (0)

Grey Divider


Action required

1. pin_browsers() signature changed 📘 Rule violation ✓ Correctness
Description
The public Starlark symbol pin_browsers was changed from no-args to requiring arch, which can
break any external loads/callers still invoking pin_browsers() with the previous signature.
Code

common/repositories.bzl[9]

+def pin_browsers(arch):
Evidence
PR Compliance ID 1 requires preserving public interfaces; the diff changes def pin_browsers(): to
def pin_browsers(arch):, which is a breaking signature change for any existing callers.

AGENTS.md
common/repositories.bzl[9-9]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`pin_browsers` changed from no-arg to requiring `arch`, which can break existing Bazel/Starlark callers that still invoke `pin_browsers()`.

## Issue Context
This is a build/module interface surface (`common/repositories.bzl`). Even if this repo currently calls it only from the module extension, external consumers may load and call it.

## Fix Focus Areas
- common/repositories.bzl[9-16]
- common/repositories.bzl[445-446]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Generator not updated 🐞 Bug ⚙ Maintainability
Description
common/repositories.bzl is generated by scripts/pinned_browsers.py, but this PR changes the
generated output shape (pin_browsers now takes arch and extension passes _ctx.os.arch) without
updating the generator, so regenerating will overwrite and remove the arch-aware pinning.
Code

common/repositories.bzl[R9-16]

+def pin_browsers(arch):
    local_drivers(name = "local_drivers")

+    if arch == "x86_64":
+        chrome_arch = "x64"
+    else:
+        chrome_arch = "arm64"
+
Evidence
The pinned browsers file is explicitly generated, yet the generator still emits def pin_browsers()
with no parameters and calls it without passing arch; re-running the generator will revert the new
arch-aware logic introduced in this PR.

common/repositories.bzl[1-16]
common/repositories.bzl[445-446]
scripts/pinned_browsers.py[537-570]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`common/repositories.bzl` is generated, but the generator (`scripts/pinned_browsers.py`) still generates the old `pin_browsers()` signature and extension call. Re-running `bazel run scripts:pinned_browsers` will overwrite the PR’s new arch-aware Mac Chrome/Chromedriver pinning.

## Issue Context
The repo relies on `scripts/pinned_browsers.py` to regenerate `common/repositories.bzl` when pinned versions change.

## Fix Focus Areas
- scripts/pinned_browsers.py[537-570]
- common/repositories.bzl[1-16]
- common/repositories.bzl[445-446]

## What to change
- Teach `scripts/pinned_browsers.py` to generate `def pin_browsers(arch):` and emit the `chrome_arch` mapping logic.
- Update the generated extension impl to call `pin_browsers(arch = _ctx.os.arch)`.
- Ensure the generated output matches the committed `common/repositories.bzl` so regeneration is idempotent.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Unknown arch treated arm64 📘 Rule violation ⛯ Reliability
Description
The new logic silently maps any arch value other than x86_64 to arm64, which can fetch the
wrong binaries (or hide misconfiguration) instead of failing fast with a clear error.
Code

common/repositories.bzl[R12-15]

+    if arch == "x86_64":
+        chrome_arch = "x64"
+    else:
+        chrome_arch = "arm64"
Evidence
PR Compliance ID 10 requires early validation of configuration/external inputs; _ctx.os.arch is an
external input, and the code accepts unexpected values by defaulting to arm64 rather than
validating supported architectures and raising an actionable failure.

common/repositories.bzl[12-15]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The code maps all non-`x86_64` values to `arm64` without validation, which can silently select incorrect Chrome/Chromedriver archives.

## Issue Context
`arch` originates from `_ctx.os.arch` (environment-derived). If Bazel reports a different string (e.g., `amd64`, `aarch64`, etc.) or a future value, the logic should either map it explicitly or fail with a clear message.

## Fix Focus Areas
- common/repositories.bzl[12-16]
- common/repositories.bzl[445-446]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Duplicated mac archive blocks 📘 Rule violation ⚙ Maintainability
Description
The PR duplicates nearly identical http_archive setup blocks (including
patch_cmds/build_file_content) across x64 and arm64 branches, increasing drift risk and
maintenance overhead.
Code

common/repositories.bzl[R226-239]

+    if chrome_arch == "x64":
+        http_archive(
+            name = "mac_chrome",
+            url = "https://storage.googleapis.com/chrome-for-testing-public/146.0.7680.165/mac-x64/chrome-mac-x64.zip",
+            sha256 = "266fe088699a2bdaec210ecb5a4951d9f6047ab5a54d58b220d9602ca0b00a5f",
+            strip_prefix = "chrome-mac-x64",
+            patch_cmds = [
+                "mv 'Google Chrome for Testing.app' Chrome.app",
+                "mv 'Chrome.app/Contents/MacOS/Google Chrome for Testing' Chrome.app/Contents/MacOS/Chrome",
+            ],
+            build_file_content = """
load("@aspect_rules_js//js:defs.bzl", "js_library")
package(default_visibility = ["//visibility:public"])
Evidence
PR Compliance ID 13 calls for centralized logic to prevent drift; the new conditional pinning
repeats the same archive configuration structure in multiple branches where only
url/sha256/strip_prefix differ.

common/repositories.bzl[226-269]
Best Practice: Learned patterns

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Multiple `http_archive` definitions are duplicated across arch branches with identical `patch_cmds` and `build_file_content`, increasing the chance future edits update one branch but not the other.

## Issue Context
Only a few fields vary by architecture (`url`, `sha256`, `strip_prefix`). The shared portions can be centralized in a small helper function or shared constants/dicts to reduce drift.

## Fix Focus Areas
- common/repositories.bzl[226-269]
- common/repositories.bzl[288-323]
- common/repositories.bzl[346-389]
- common/repositories.bzl[408-443]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

load("//common/private:pkg_archive.bzl", "pkg_archive")

def pin_browsers():
def pin_browsers(arch):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. pin_browsers() signature changed 📘 Rule violation ✓ Correctness

The public Starlark symbol pin_browsers was changed from no-args to requiring arch, which can
break any external loads/callers still invoking pin_browsers() with the previous signature.
Agent Prompt
## Issue description
`pin_browsers` changed from no-arg to requiring `arch`, which can break existing Bazel/Starlark callers that still invoke `pin_browsers()`.

## Issue Context
This is a build/module interface surface (`common/repositories.bzl`). Even if this repo currently calls it only from the module extension, external consumers may load and call it.

## Fix Focus Areas
- common/repositories.bzl[9-16]
- common/repositories.bzl[445-446]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +9 to +16
def pin_browsers(arch):
local_drivers(name = "local_drivers")

if arch == "x86_64":
chrome_arch = "x64"
else:
chrome_arch = "arm64"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Generator not updated 🐞 Bug ⚙ Maintainability

common/repositories.bzl is generated by scripts/pinned_browsers.py, but this PR changes the
generated output shape (pin_browsers now takes arch and extension passes _ctx.os.arch) without
updating the generator, so regenerating will overwrite and remove the arch-aware pinning.
Agent Prompt
## Issue description
`common/repositories.bzl` is generated, but the generator (`scripts/pinned_browsers.py`) still generates the old `pin_browsers()` signature and extension call. Re-running `bazel run scripts:pinned_browsers` will overwrite the PR’s new arch-aware Mac Chrome/Chromedriver pinning.

## Issue Context
The repo relies on `scripts/pinned_browsers.py` to regenerate `common/repositories.bzl` when pinned versions change.

## Fix Focus Areas
- scripts/pinned_browsers.py[537-570]
- common/repositories.bzl[1-16]
- common/repositories.bzl[445-446]

## What to change
- Teach `scripts/pinned_browsers.py` to generate `def pin_browsers(arch):` and emit the `chrome_arch` mapping logic.
- Update the generated extension impl to call `pin_browsers(arch = _ctx.os.arch)`.
- Ensure the generated output matches the committed `common/repositories.bzl` so regeneration is idempotent.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants