From 1de5102141d6c79aae113534fd6f44888dc416ee Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:29:42 +0100 Subject: [PATCH 1/8] Use utils.get_session for the requests of build_platforms As for bugbug's other requests, so that they're retried on transient errors (429 and 5xx responses). --- bugbug/build_platforms.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index 1556496042d..6c9d41dd920 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -21,7 +21,7 @@ import zipfile from typing import Collection, Iterable, Iterator, Mapping -import requests +from bugbug import utils logger = logging.getLogger(__name__) @@ -52,7 +52,9 @@ class _RemoteFile(io.RawIOBase): """A file read with HTTP range requests, to list the files of a remote zip without downloading it.""" def __init__(self, url: str) -> None: - response = requests.head(url, allow_redirects=True, timeout=60) + # A session for the range requests of the file. + self.session = utils.get_session("taskcluster") + response = self.session.head(url, allow_redirects=True, timeout=60) response.raise_for_status() self.url = response.url self.size = int(response.headers["Content-Length"]) @@ -76,7 +78,7 @@ def readinto(self, buffer) -> int: end = min(self.size, self.position + len(buffer)) if end <= self.position: return 0 - response = requests.get( + response = self.session.get( self.url, headers={ "Range": f"bytes={self.position}-{end - 1}", @@ -101,7 +103,7 @@ def _job_files(job: str) -> set[str]: if not name.endswith("/") and not name.startswith("__GENERATED__/") } - response = requests.get( + response = utils.get_session("taskcluster").get( ARTIFACT_URL.format(job=job, artifact="chrome-map.json"), timeout=60 ) response.raise_for_status() From 2a671972e071fa98b52f03c5590a0cc422e1ee2a Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:29:48 +0100 Subject: [PATCH 2/8] Consider the Kotlin, Java and Gradle files only built on Android in build_platforms No Searchfox build lists them, so they were considered built on every platform. They are only used by the Android apps and libraries (Fenix, Focus, android-components, GeckoView), except the HTML parser's Java code, which is translated to the C++ code built on every platform. Of the last 3,500 pushes of the group history, 276 are now considered Android-only, against 21. --- bugbug/build_platforms.py | 19 ++++++++++++++++--- tests/test_build_platforms.py | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index 6c9d41dd920..2077a0cd72a 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -7,9 +7,10 @@ Searchfox's indexing jobs build Firefox for each platform. Their index lists the source files (including headers) the build compiled, and the build's chrome map the files it packaged (JS, CSS, -...): a file is built on the platforms whose builds list it. A file no build lists (a file added -since the builds, tests, docs, Rust or Java files, ...) is built on the platforms that build files -in its closest ancestor directory, or on all platforms if there's none. +...): a file is built on the platforms whose builds list it. The Kotlin, Java and Gradle files of +the Android apps and libraries are only built on Android. Another file no build lists (a file added +since the builds, tests, docs, Rust files, ...) is built on the platforms that build files in its +closest ancestor directory, or on all platforms if there's none. A patch only touching files built on some platforms can only break those (e.g. widget/cocoa only on macOS, gfx/layers/d3d11 only on Windows). @@ -44,6 +45,12 @@ # Directories of code that some platforms' jobs don't build, although their tests run it: the Android # job doesn't build gtests (4 files in gtest directories, against ~800 for the desktop jobs). UNBUILT_DIRECTORIES = {"android": frozenset({"gtest"})} +# Files no build lists that only the Android builds use: the Android apps and libraries (Fenix, Focus, +# android-components, GeckoView, ...) are built by Gradle from Kotlin and Java code. The HTML parser's +# Java code is translated to the C++ code built on every platform. +ANDROID_EXTENSIONS = frozenset({".kt", ".kts", ".java", ".gradle"}) +ANDROID_DIRECTORIES = ("gradle/",) +NOT_ANDROID_DIRECTORIES = ("parser/html/javasrc/",) ARTIFACT_URL = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.{job}/artifacts/public/build/{artifact}" @@ -175,6 +182,12 @@ def _platforms(self, path: str) -> frozenset[str]: } return frozenset(listed) + if ( + os.path.splitext(path)[1] in ANDROID_EXTENSIONS + or path.startswith(ANDROID_DIRECTORIES) + ) and not path.startswith(NOT_ANDROID_DIRECTORIES): + return frozenset({"android"}) + if os.path.splitext(path)[1] not in self.types: return ALL_PLATFORMS diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index 9eefa6a1136..78f617922ed 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -61,6 +61,18 @@ def platforms(path, built=BUILT): # Files of types no build lists (e.g. inputs of code generation) aren't restricted by directory. assert platforms("browser/base/content/metrics.yaml") == set(ALL_PLATFORMS) assert platforms("widget/cocoa/moz.build") == set(ALL_PLATFORMS) + # The Android apps' Kotlin, Java and Gradle files, except the HTML parser's Java code (translated to + # C++). + assert platforms( + "mobile/android/fenix/app/src/main/java/org/mozilla/fenix/HomeActivity.kt" + ) == {"android"} + assert platforms( + "mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java" + ) == {"android"} + assert platforms("mobile/android/fenix/app/build.gradle") == {"android"} + assert platforms("mobile/android/fenix/app/build.gradle.kts") == {"android"} + assert platforms("gradle/libs.versions.toml") == {"android"} + assert platforms("parser/html/javasrc/Tokenizer.java") == set(ALL_PLATFORMS) # Android runs gtests, although its job doesn't build them. assert platforms("dom/media/gtest/TestAudioBuffers.cpp") == set(ALL_PLATFORMS) assert platforms("dom/media/gtest/TestNew.cpp") == set(ALL_PLATFORMS) @@ -84,6 +96,10 @@ def test_find_platforms_for_paths() -> None: "macosx", } assert find([]) == ALL_PLATFORMS + # An Android-only patch. + assert find( + ["mobile/android/fenix/app/build.gradle", "gradle/libs.versions.toml"] + ) == {"android"} def mock_artifacts(files_by_job: dict[str, list[str]]) -> None: From 7742507afc39d427a4c9033f779636790daaf0ea Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:29:54 +0100 Subject: [PATCH 3/8] Consider the browser/ files only built on desktop and the mobile/ ones only on Android No Android build lists a file of browser/, and no desktop build a file of mobile/, but their files of types no build lists (e.g. .jsx, .ftl, test manifests) were considered built on every platform. YAML files are still considered shared, as some are code generation inputs used by every product (e.g. browser/base/content/metrics.yaml is in Glean's gecko_metrics). As the other rules, it only applies to the files no build lists, as the builds' lists are accurate. Of the last 3,500 pushes of the group history, 971 are now restricted to some platforms, against 784. --- bugbug/build_platforms.py | 31 +++++++++++++++++++++++++++---- tests/test_build_platforms.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index 2077a0cd72a..34243577a13 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -8,9 +8,10 @@ Searchfox's indexing jobs build Firefox for each platform. Their index lists the source files (including headers) the build compiled, and the build's chrome map the files it packaged (JS, CSS, ...): a file is built on the platforms whose builds list it. The Kotlin, Java and Gradle files of -the Android apps and libraries are only built on Android. Another file no build lists (a file added -since the builds, tests, docs, Rust files, ...) is built on the platforms that build files in its -closest ancestor directory, or on all platforms if there's none. +the Android apps and libraries are only built on Android, the files of the desktop browser +(browser/) only on desktop, and the ones of the mobile products (mobile/) only on Android. Another +file no build lists (a file added since the builds, tests, docs, Rust files, ...) is built on the +platforms that build files in its closest ancestor directory, or on all platforms if there's none. A patch only touching files built on some platforms can only break those (e.g. widget/cocoa only on macOS, gfx/layers/d3d11 only on Windows). @@ -29,6 +30,7 @@ # The OS families, named as test_scheduling.config_platform_family names them. PLATFORMS = ("android", "linux", "macosx", "windows") ALL_PLATFORMS = frozenset(PLATFORMS) +DESKTOP_PLATFORMS = frozenset({"linux", "macosx", "windows"}) # The Searchfox jobs of each platform (gecko.v2.mozilla-central.latest.firefox.), for the # architectures tests run on. @@ -51,6 +53,11 @@ ANDROID_EXTENSIONS = frozenset({".kt", ".kts", ".java", ".gradle"}) ANDROID_DIRECTORIES = ("gradle/",) NOT_ANDROID_DIRECTORIES = ("parser/html/javasrc/",) +# The directories of the code of a product, only built on its platforms (no Android build lists a file of +# browser/, no desktop build a file of mobile/), except for the code generation inputs which might be used +# by every product: YAML files (e.g. browser/base/content/metrics.yaml is in Glean's gecko_metrics). +PRODUCT_DIRECTORIES = {"browser/": DESKTOP_PLATFORMS, "mobile/": frozenset({"android"})} +YAML_EXTENSIONS = (".yaml", ".yml") ARTIFACT_URL = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.{job}/artifacts/public/build/{artifact}" @@ -169,7 +176,23 @@ def __init__(self, built: Mapping[str, Iterable[str]]) -> None: self.unknown = ALL_PLATFORMS - set(self.files) def platforms(self, path: str) -> frozenset[str]: - return self._platforms(path) | self.unknown | self._unbuilt(path) + result = self._platforms(path) | self.unknown | self._unbuilt(path) + # The rules below only apply to the files no build lists, as the builds' lists are accurate. + if not self._listed(path) and not self._shared(path): + result = self._apply_rules(path, result) + return result + + def _apply_rules(self, path: str, result: frozenset[str]) -> frozenset[str]: + for directory, platforms in PRODUCT_DIRECTORIES.items(): + if path.startswith(directory): + return (result & platforms) or platforms + return result + + def _listed(self, path: str) -> bool: + return any(path in files for files in self.files.values()) + + def _shared(self, path: str) -> bool: + return path.endswith(YAML_EXTENSIONS) def _platforms(self, path: str) -> frozenset[str]: listed = {p for p, files in self.files.items() if path in files} diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index 78f617922ed..e3b4e0ece67 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -73,6 +73,32 @@ def platforms(path, built=BUILT): assert platforms("mobile/android/fenix/app/build.gradle.kts") == {"android"} assert platforms("gradle/libs.versions.toml") == {"android"} assert platforms("parser/html/javasrc/Tokenizer.java") == set(ALL_PLATFORMS) + # The desktop browser's files are only built on desktop, the mobile products' only on Android, whatever + # their type, except YAML files (code generation inputs which might be used by every product, e.g. + # Glean's gecko_metrics). + assert platforms("browser/components/newtab/content/Card.jsx") == DESKTOP + assert platforms("browser/locales/en-US/browser/browser.ftl") == DESKTOP + assert platforms("browser/components/newtab/test/browser/browser.toml") == DESKTOP + assert platforms("mobile/android/fenix/app/src/main/res/values/strings.xml") == { + "android" + } + assert platforms("mobile/shared/modules/geckoview/GeckoViewUtils.sys.mjs") == { + "android" + } + assert platforms("mobile/shared/modules/geckoview/metrics.yaml") == set( + ALL_PLATFORMS + ) + # Platforms whose files are unknown don't add other products' platforms. + without_android = {p: f for p, f in BUILT.items() if p != "android"} + assert platforms("browser/components/newtab/content/Card.jsx", without_android) == ( + DESKTOP + ) + # The builds' lists are more accurate than the rules. + listed = { + **BUILT, + "android": BUILT["android"] + ["browser/base/content/browser.js"], + } + assert platforms("browser/base/content/browser.js", listed) == set(ALL_PLATFORMS) # Android runs gtests, although its job doesn't build them. assert platforms("dom/media/gtest/TestAudioBuffers.cpp") == set(ALL_PLATFORMS) assert platforms("dom/media/gtest/TestNew.cpp") == set(ALL_PLATFORMS) @@ -96,6 +122,10 @@ def test_find_platforms_for_paths() -> None: "macosx", } assert find([]) == ALL_PLATFORMS + # A desktop-only patch. + assert find( + ["browser/components/newtab/content/Card.jsx", "widget/gtk/nsWindow.cpp"] + ) == {"linux", "macosx", "windows"} # An Android-only patch. assert find( ["mobile/android/fenix/app/build.gradle", "gradle/libs.versions.toml"] From 746f86a88480fe9697c3a5aa42114a60ef4f1b19 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:30:29 +0100 Subject: [PATCH 4/8] Consider the files used by the Android Gradle builds built on Android The Android Gradle builds also use files out of mobile/, which the Android build's index doesn't list: e.g. Android Components packages the webcompat extension of browser/, which the previous commit considered desktop-only. The paths they refer to from the source directory are found in the repository when retrieving the built files, and stored with them. If they can't be found, the previous ones are kept, and if they were never found, the browser/ files keep their platforms (as some might be used on Android). Paths the Gradle builds don't refer to anymore are reported (e.g. if a Gradle file refers to one in a way that isn't recognized anymore). --- bugbug/build_platforms.py | 36 +++++++++++++++++- bugbug/test_scheduling.py | 19 +++++++++- http_service/bugbug_http/boot.py | 41 ++++++++++++++++++-- http_service/tests/test_boot.py | 65 +++++++++++++++++++++++++++++++- tests/test_build_platforms.py | 39 +++++++++++++++++++ tests/test_test_scheduling.py | 22 +++++++++++ 6 files changed, 216 insertions(+), 6 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index 34243577a13..ebb2e70f033 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -20,6 +20,7 @@ import io import logging import os +import re import zipfile from typing import Collection, Iterable, Iterator, Mapping @@ -58,6 +59,10 @@ # by every product: YAML files (e.g. browser/base/content/metrics.yaml is in Glean's gecko_metrics). PRODUCT_DIRECTORIES = {"browser/": DESKTOP_PLATFORMS, "mobile/": frozenset({"android"})} YAML_EXTENSIONS = (".yaml", ".yml") +# The Android Gradle builds also use files out of mobile/, which the Android build's index doesn't list +# (e.g. Android Components packages the webcompat extension of browser/): the paths they refer to from +# the source directory (see find_gradle_paths). +GRADLE_SOURCE_PATH = re.compile(r"topsrcdir\}?/([\w.@/-]+)") ARTIFACT_URL = "https://firefox-ci-tc.services.mozilla.com/api/index/v1/task/gecko.v2.mozilla-central.latest.firefox.{job}/artifacts/public/build/{artifact}" @@ -135,6 +140,21 @@ def _job_files(job: str) -> set[str]: return files +def find_gradle_paths(contents: Iterable[str]) -> list[str]: + """The paths out of mobile/ which Gradle files (their contents) refer to from the source directory. + + E.g. "${gradle.mozconfig.topsrcdir}/browser/extensions/webcompat" (Android Components' webcompat + feature): the Android builds use them, although the Android build's index doesn't list them. + """ + paths = set() + for content in contents: + for match in GRADLE_SOURCE_PATH.finditer(content): + path = match.group(1).rstrip("/.") + if path and not path.startswith("mobile/"): + paths.add(path) + return sorted(paths) + + def retrieve_built_files() -> dict[str, list[str]]: """The files built on each platform. Platforms whose files can't be retrieved are left out.""" built = {} @@ -157,6 +177,10 @@ class BuildPlatforms: """The platforms building files, from the files built on each platform (see retrieve_built_files).""" def __init__(self, built: Mapping[str, Iterable[str]]) -> None: + # The paths the Android Gradle builds use (see find_gradle_paths), None if they aren't known. + gradle = built.get("gradle") + self.gradle_files = frozenset(gradle) if gradle is not None else None + self.gradle_directories = tuple(f"{path}/" for path in gradle or ()) self.files = { platform: frozenset(files) for platform, files in built.items() @@ -180,14 +204,24 @@ def platforms(self, path: str) -> frozenset[str]: # The rules below only apply to the files no build lists, as the builds' lists are accurate. if not self._listed(path) and not self._shared(path): result = self._apply_rules(path, result) + if self._used_by_gradle(path): + result |= {"android"} return result def _apply_rules(self, path: str, result: frozenset[str]) -> frozenset[str]: for directory, platforms in PRODUCT_DIRECTORIES.items(): - if path.startswith(directory): + # The rules excluding Android need the files the Android builds use out of mobile/. + if path.startswith(directory) and ( + "android" in platforms or self.gradle_files is not None + ): return (result & platforms) or platforms return result + def _used_by_gradle(self, path: str) -> bool: + return self.gradle_files is not None and ( + path in self.gradle_files or path.startswith(self.gradle_directories) + ) + def _listed(self, path: str) -> bool: return any(path in files for files in self.files.values()) diff --git a/bugbug/test_scheduling.py b/bugbug/test_scheduling.py index fcb1eb1fc14..e08a00a8036 100644 --- a/bugbug/test_scheduling.py +++ b/bugbug/test_scheduling.py @@ -41,7 +41,7 @@ import orjson from tqdm import tqdm -from bugbug import db, repository +from bugbug import build_platforms, db, repository from bugbug.utils import ExpQueue, LMDBDict, get_session, get_user_agent logging.basicConfig(level=logging.INFO) @@ -1888,6 +1888,23 @@ def approximate_manifests_for_paths( return result +def find_gradle_paths(repo_dir: str, rev: str) -> list[str]: + """The paths out of mobile/ which the Android Gradle builds use, at revision `rev`. + + See build_platforms.find_gradle_paths. The files are read with Mercurial, as by + find_manifests_for_paths. + """ + gradle_files = [ + path + for path in _get_files(repo_dir, rev) + if path.startswith("mobile/") and path.endswith((".gradle", ".gradle.kts")) + ] + return build_platforms.find_gradle_paths( + content.decode("utf-8", "replace") + for content in _read_files(repo_dir, rev, gradle_files).values() + ) + + _GTEST_RE = re.compile(rb"^[ \t]*(?:TEST|TEST_F)\(", re.MULTILINE) _GTEST_FOLDERS = ("gtest", "gtests", "googletest") _CPPUNIT_INFRA_FILES = { diff --git a/http_service/bugbug_http/boot.py b/http_service/bugbug_http/boot.py index 5efcccfdfab..240d61a6549 100644 --- a/http_service/bugbug_http/boot.py +++ b/http_service/bugbug_http/boot.py @@ -415,9 +415,42 @@ def retrieve_schedulable_tasks() -> None: update_config_selection_tasks(revs, known_tasks) -def retrieve_build_platforms() -> None: - # The files built on each platform, see build_platforms. +def _read_build_platforms() -> dict: + """The files built on each platform, as previously retrieved (empty if they weren't).""" + try: + with open("build_platforms.json", "rb") as f: + return orjson.loads(f.read()) + except FileNotFoundError, orjson.JSONDecodeError: + return {} + + +def retrieve_build_platforms( + repository_ready: concurrent.futures.Future | None = None, +) -> None: + """Retrieve the files built on each platform (see build_platforms). + + The files the Android Gradle builds use are found in the repository, once `repository_ready` (if + given) is done. If they can't be, the previous ones are kept. + """ built = build_platforms.retrieve_built_files() + previous = _read_build_platforms() + try: + if repository_ready is not None: + repository_ready.result() + with hglib.open(REPO_DIR) as hg: + tip = hg.log(revrange=b"tip")[0].node.decode("ascii") + gradle = test_scheduling.find_gradle_paths(REPO_DIR, tip) + # The Gradle files always refer to some paths: none means they couldn't be parsed. + if not gradle: + raise ValueError("No paths found in the Gradle files") + removed = sorted(set(previous.get("gradle", ())) - set(gradle)) + if removed: + logger.warning("Paths not used by the Gradle builds anymore: %s", removed) + built["gradle"] = gradle + except Exception: + logger.exception("Failed to find the files used by the Gradle builds") + if "gradle" in previous: + built["gradle"] = previous["gradle"] _write("build_platforms.json", json.dumps(built)) logger.info("Retrieved the files built on %s.", ", ".join(sorted(built))) @@ -644,7 +677,9 @@ def extract_commit_experiences() -> None: retrieve_schedulable_tasks_future = executor.submit(retrieve_schedulable_tasks) - retrieve_build_platforms_future = executor.submit(retrieve_build_platforms) + retrieve_build_platforms_future = executor.submit( + retrieve_build_platforms, clone_autoland_future + ) commits_db_extracted = extract_commits() extract_commit_experiences() diff --git a/http_service/tests/test_boot.py b/http_service/tests/test_boot.py index cbebe21e293..d4dab8b57c9 100644 --- a/http_service/tests/test_boot.py +++ b/http_service/tests/test_boot.py @@ -8,7 +8,9 @@ import json import os import re +import subprocess from pathlib import Path +from typing import Callable # mozci.data needs to be imported before mozci.task to avoid a circular import. import mozci.data # noqa: F401 @@ -32,14 +34,75 @@ def test_retrieve_build_platforms( lambda: {"macosx": ["widget/cocoa/nsCocoaWindow.mm"]}, ) + mock_gradle_paths( + monkeypatch, + lambda repo_dir, rev: ( + ["browser/extensions/webcompat"] if rev == "abcdef" else [] + ), + ) + boot.retrieve_build_platforms() with open("build_platforms.json") as f: - assert json.load(f) == {"macosx": ["widget/cocoa/nsCocoaWindow.mm"]} + assert json.load(f) == { + "macosx": ["widget/cocoa/nsCocoaWindow.mm"], + "gradle": ["browser/extensions/webcompat"], + } # The file is written atomically, through a temporary file. assert not any(name.endswith(".tmp") for name in os.listdir()) +def mock_gradle_paths( + monkeypatch: pytest.MonkeyPatch, find_gradle_paths: Callable[[str, str], list[str]] +) -> None: + class Hg: + def __enter__(self): + return self + + def __exit__(self, *args): + pass + + def log(self, revrange): + assert revrange == b"tip" + return [type("Rev", (), {"node": b"abcdef"})] + + monkeypatch.setattr(boot.hglib, "open", lambda repo_dir: Hg()) + monkeypatch.setattr(boot.test_scheduling, "find_gradle_paths", find_gradle_paths) + + +def test_retrieve_build_platforms_gradle_failures( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path, caplog: pytest.LogCaptureFixture +) -> None: + monkeypatch.chdir(tmp_path) + monkeypatch.setattr(boot.build_platforms, "retrieve_built_files", lambda: {}) + with open("build_platforms.json", "w") as f: + json.dump({"gradle": ["browser/extensions/webcompat", "widget/android"]}, f) + + # Paths the Gradle builds don't use anymore are reported. + mock_gradle_paths(monkeypatch, lambda repo_dir, rev: ["widget/android"]) + boot.retrieve_build_platforms() + with open("build_platforms.json") as f: + assert json.load(f) == {"gradle": ["widget/android"]} + assert ( + "Paths not used by the Gradle builds anymore: ['browser/extensions/webcompat']" + in (caplog.text) + ) + + # If the paths can't be found (or none are, e.g. if the Gradle files can't be parsed anymore), the + # previous ones are kept. + def fail(repo_dir, rev): + raise subprocess.CalledProcessError(255, "hg") + + finders: list[Callable[[str, str], list[str]]] = [fail, lambda repo_dir, rev: []] + for find_gradle_paths in finders: + caplog.clear() + mock_gradle_paths(monkeypatch, find_gradle_paths) + boot.retrieve_build_platforms() + with open("build_platforms.json") as f: + assert json.load(f) == {"gradle": ["widget/android"]} + assert "Failed to find the files used by the Gradle builds" in caplog.text + + def test_refresh_data_keeps_going_after_a_failure( monkeypatch: pytest.MonkeyPatch, ) -> None: diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index e3b4e0ece67..6f1ad290db9 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -41,6 +41,8 @@ # gtests, which the Android job doesn't build. for _platform in DESKTOP: BUILT[_platform] = BUILT[_platform] + ["dom/media/gtest/TestAudioBuffers.cpp"] +# The files the Android Gradle builds use out of mobile/. +BUILT["gradle"] = ["browser/extensions/webcompat"] def test_platforms() -> None: @@ -93,6 +95,28 @@ def platforms(path, built=BUILT): assert platforms("browser/components/newtab/content/Card.jsx", without_android) == ( DESKTOP ) + # The files the Android Gradle builds use are used on Android, although no Android build lists them. + gradle = { + **BUILT, + "gradle": ["browser/extensions/webcompat", "netwerk/dns/names.dat"], + } + assert platforms("browser/extensions/webcompat/manifest.json", gradle) == set( + ALL_PLATFORMS + ) + assert platforms("netwerk/dns/names.dat", gradle) == set(ALL_PLATFORMS) + assert ( + platforms("browser/extensions/webcompatible/manifest.json", gradle) == DESKTOP + ) + assert platforms("widget/cocoa/nsCocoaWindow.mm", gradle) == {"macosx"} + # If they aren't known, the browser/ files might be used on Android (but the mobile/ ones are still + # not used on desktop). + no_gradle = {p: f for p, f in BUILT.items() if p != "gradle"} + assert platforms("browser/components/newtab/content/Card.jsx", no_gradle) == set( + ALL_PLATFORMS + ) + assert platforms( + "mobile/android/fenix/app/src/main/res/values/strings.xml", no_gradle + ) == {"android"} # The builds' lists are more accurate than the rules. listed = { **BUILT, @@ -132,6 +156,21 @@ def test_find_platforms_for_paths() -> None: ) == {"android"} +def test_find_gradle_paths() -> None: + assert build_platforms.find_gradle_paths( + [ + """def extension = "${gradle.mozconfig.topsrcdir}/browser/extensions/webcompat".toString() +srcDir "${topsrcdir}/widget/android/bindings/" +apply from: "${topsrcdir}/mobile/android/gradle/debug_level.gradle\"""", + 'file("$topsrcdir/netwerk/dns/effective_tld_names.dat")', + ] + ) == [ + "browser/extensions/webcompat", + "netwerk/dns/effective_tld_names.dat", + "widget/android/bindings", + ] + + def mock_artifacts(files_by_job: dict[str, list[str]]) -> None: for job, files in files_by_job.items(): data = io.BytesIO() diff --git a/tests/test_test_scheduling.py b/tests/test_test_scheduling.py index e466096a427..8baf16698f9 100644 --- a/tests/test_test_scheduling.py +++ b/tests/test_test_scheduling.py @@ -1331,6 +1331,10 @@ def _rev(self) -> Iterator[str]: finally: hg.update(rev=b"tip") + def gradle_paths(self) -> list[str]: + with self._rev() as rev: + return test_scheduling.find_gradle_paths(self.repo_dir, rev) + def manifests(self, paths: list[str]) -> set[str]: with self._rev() as rev: return test_scheduling.find_manifests_for_paths(self.repo_dir, paths, rev) @@ -1668,6 +1672,24 @@ def approximate(paths: list[str]) -> set[str]: } +def test_find_gradle_paths(tmp_path) -> None: + find = _Finder(tmp_path) + (tmp_path / "mobile" / "android" / "feature").mkdir(parents=True) + (tmp_path / "mobile" / "android" / "feature" / "build.gradle").write_text( + 'def extension = "${gradle.mozconfig.topsrcdir}/browser/extensions/webcompat"\n' + ) + (tmp_path / "mobile" / "android" / "settings.gradle.kts").write_text( + 'include("${topsrcdir}/mobile/android/geckoview")\n' + ) + # Not an Android Gradle file. + (tmp_path / "third_party").mkdir() + (tmp_path / "third_party" / "build.gradle").write_text( + 'srcDir "${topsrcdir}/third_party/other"\n' + ) + + assert find.gradle_paths() == ["browser/extensions/webcompat"] + + def test_find_tasks_for_paths(tmp_path) -> None: find = _Finder(tmp_path) known_tasks = ( From 74d43b23e8c2a2455fbec5d105da0f937edce637 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:31:03 +0100 Subject: [PATCH 5/8] Only consider the YAML files of Glean's gecko_* lists shared between the products The other YAML files of browser/ and mobile/ (e.g. the desktop Glean metrics, Fenix's Nimbus feature manifests, the vendoring manifests) are only used by their product. The shared ones are taken from mozilla-central's Glean index when retrieving the built files, and stored with them. If they can't be retrieved (or none are found, e.g. if the index can't be parsed anymore), the previous ones are kept, and if they were never retrieved, every YAML file is still considered shared. Of the last 3,500 pushes of the group history, 87 more are now restricted to some platforms. --- bugbug/build_platforms.py | 44 +++++++++++++++++++++++++++++--- http_service/bugbug_http/boot.py | 3 +++ http_service/tests/test_boot.py | 15 +++++++++++ tests/test_build_platforms.py | 43 +++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 4 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index ebb2e70f033..c69bd09c21f 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -17,6 +17,7 @@ on macOS, gfx/layers/d3d11 only on Windows). """ +import ast import io import logging import os @@ -55,10 +56,12 @@ ANDROID_DIRECTORIES = ("gradle/",) NOT_ANDROID_DIRECTORIES = ("parser/html/javasrc/",) # The directories of the code of a product, only built on its platforms (no Android build lists a file of -# browser/, no desktop build a file of mobile/), except for the code generation inputs which might be used -# by every product: YAML files (e.g. browser/base/content/metrics.yaml is in Glean's gecko_metrics). +# browser/, no desktop build a file of mobile/), except for the code generation inputs used by every +# product: Glean's metrics and pings sent by Gecko (e.g. browser/base/content/metrics.yaml), see +# retrieve_shared_files. If they aren't known, every YAML file is considered shared. PRODUCT_DIRECTORIES = {"browser/": DESKTOP_PLATFORMS, "mobile/": frozenset({"android"})} YAML_EXTENSIONS = (".yaml", ".yml") +GLEAN_INDEX_URL = "https://hg.mozilla.org/mozilla-central/raw-file/tip/toolkit/components/glean/metrics_index.py" # The Android Gradle builds also use files out of mobile/, which the Android build's index doesn't list # (e.g. Android Components packages the webcompat extension of browser/): the paths they refer to from # the source directory (see find_gradle_paths). @@ -155,14 +158,43 @@ def find_gradle_paths(contents: Iterable[str]) -> list[str]: return sorted(paths) +def retrieve_shared_files() -> list[str]: + """The YAML files from which code used by every product is generated: Glean's metrics and pings sent by Gecko. + + They are the gecko_* lists of the Glean index (e.g. gecko_metrics, gecko_pings) of mozilla-central. + """ + response = utils.get_session("hgmo").get(GLEAN_INDEX_URL, timeout=60) + response.raise_for_status() + files = set() + for node in ast.parse(response.text).body: + if ( + isinstance(node, ast.Assign) + and len(node.targets) == 1 + and isinstance(node.targets[0], ast.Name) + and node.targets[0].id.startswith("gecko_") + ): + files.update(ast.literal_eval(node.value)) + # The index always has some: none means it couldn't be parsed. + if not files: + raise ValueError("No gecko_* lists found in the Glean index") + return sorted(files) + + def retrieve_built_files() -> dict[str, list[str]]: - """The files built on each platform. Platforms whose files can't be retrieved are left out.""" + """The files built on each platform, and the shared files (see retrieve_shared_files). + + Platforms whose files can't be retrieved are left out, and so are the shared files. + """ built = {} for platform, jobs in SEARCHFOX_JOBS.items(): try: built[platform] = sorted(set().union(*(_job_files(job) for job in jobs))) except Exception: logger.exception("Failed to retrieve the files built on %s", platform) + try: + built["shared"] = retrieve_shared_files() + except Exception: + logger.exception("Failed to retrieve the shared files") return built @@ -177,6 +209,8 @@ class BuildPlatforms: """The platforms building files, from the files built on each platform (see retrieve_built_files).""" def __init__(self, built: Mapping[str, Iterable[str]]) -> None: + # The shared YAML files (see retrieve_shared_files), None if they aren't known. + self.shared = frozenset(built["shared"]) if "shared" in built else None # The paths the Android Gradle builds use (see find_gradle_paths), None if they aren't known. gradle = built.get("gradle") self.gradle_files = frozenset(gradle) if gradle is not None else None @@ -226,7 +260,9 @@ def _listed(self, path: str) -> bool: return any(path in files for files in self.files.values()) def _shared(self, path: str) -> bool: - return path.endswith(YAML_EXTENSIONS) + return path.endswith(YAML_EXTENSIONS) and ( + self.shared is None or path in self.shared + ) def _platforms(self, path: str) -> frozenset[str]: listed = {p for p, files in self.files.items() if path in files} diff --git a/http_service/bugbug_http/boot.py b/http_service/bugbug_http/boot.py index 240d61a6549..f49d0c0677b 100644 --- a/http_service/bugbug_http/boot.py +++ b/http_service/bugbug_http/boot.py @@ -451,6 +451,9 @@ def retrieve_build_platforms( logger.exception("Failed to find the files used by the Gradle builds") if "gradle" in previous: built["gradle"] = previous["gradle"] + # Keep the previous shared files, if they can't be retrieved (see build_platforms). + if "shared" not in built and "shared" in previous: + built["shared"] = previous["shared"] _write("build_platforms.json", json.dumps(built)) logger.info("Retrieved the files built on %s.", ", ".join(sorted(built))) diff --git a/http_service/tests/test_boot.py b/http_service/tests/test_boot.py index d4dab8b57c9..49e11ca62f3 100644 --- a/http_service/tests/test_boot.py +++ b/http_service/tests/test_boot.py @@ -103,6 +103,21 @@ def fail(repo_dir, rev): assert "Failed to find the files used by the Gradle builds" in caplog.text +def test_retrieve_build_platforms_keeps_shared_files( + monkeypatch: pytest.MonkeyPatch, tmp_path: Path +) -> None: + monkeypatch.chdir(tmp_path) + with open("build_platforms.json", "w") as f: + json.dump({"shared": ["dom/metrics.yaml"], "gradle": ["widget/android"]}, f) + mock_gradle_paths(monkeypatch, lambda repo_dir, rev: ["widget/android"]) + + # The shared files can't be retrieved. + monkeypatch.setattr(boot.build_platforms, "retrieve_built_files", lambda: {}) + boot.retrieve_build_platforms() + with open("build_platforms.json") as f: + assert json.load(f)["shared"] == ["dom/metrics.yaml"] + + def test_refresh_data_keeps_going_after_a_failure( monkeypatch: pytest.MonkeyPatch, ) -> None: diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index 6f1ad290db9..8d5a97e7f47 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -8,6 +8,7 @@ import re import zipfile +import pytest import responses from bugbug import build_platforms @@ -90,6 +91,14 @@ def platforms(path, built=BUILT): assert platforms("mobile/shared/modules/geckoview/metrics.yaml") == set( ALL_PLATFORMS ) + # With the shared files known, the other YAML files of the products are only used by the products. + shared = {**BUILT, "shared": ["browser/base/content/metrics.yaml"]} + assert platforms("browser/base/content/metrics.yaml", shared) == set(ALL_PLATFORMS) + assert platforms("browser/components/newtab/metrics.yaml", shared) == DESKTOP + assert platforms("mobile/android/fenix/app/nimbus.fml.yaml", shared) == {"android"} + assert platforms("toolkit/components/glean/metrics.yaml", shared) == set( + ALL_PLATFORMS + ) # Platforms whose files are unknown don't add other products' platforms. without_android = {p: f for p, f in BUILT.items() if p != "android"} assert platforms("browser/components/newtab/content/Card.jsx", without_android) == ( @@ -214,7 +223,36 @@ def get_range(request, content=content): ) +GLEAN_INDEX = """ +gecko_metrics = [ + "browser/base/content/metrics.yaml", + "dom/metrics.yaml", +] +gecko_pings = ["toolkit/components/glean/pings.yaml"] +firefox_desktop_metrics = ["browser/components/newtab/metrics.yaml"] +""" + + +def test_retrieve_shared_files() -> None: + responses.add(responses.GET, build_platforms.GLEAN_INDEX_URL, body=GLEAN_INDEX) + assert build_platforms.retrieve_shared_files() == [ + "browser/base/content/metrics.yaml", + "dom/metrics.yaml", + "toolkit/components/glean/pings.yaml", + ] + + +def test_retrieve_shared_files_without_lists() -> None: + # An index which can't be parsed anymore isn't taken as having no shared files. + responses.add( + responses.GET, build_platforms.GLEAN_INDEX_URL, body="metrics = load_index()\n" + ) + with pytest.raises(ValueError): + build_platforms.retrieve_shared_files() + + def test_retrieve_built_files() -> None: + responses.add(responses.GET, build_platforms.GLEAN_INDEX_URL, body=GLEAN_INDEX) mock_artifacts( { "linux64-searchfox-debug": ["widget/gtk/nsWindow.cpp"], @@ -242,4 +280,9 @@ def test_retrieve_built_files() -> None: "widget/cocoa/nsCocoaWindow.mm", ], "windows": ["widget/windows/nsWindow.cpp", "win64-searchfox-debug/browser.js"], + "shared": [ + "browser/base/content/metrics.yaml", + "dom/metrics.yaml", + "toolkit/components/glean/pings.yaml", + ], } From d858879dd93a107c2341d3ec0f1a6aac167b1749 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:31:41 +0100 Subject: [PATCH 6/8] Consider the browser-chrome tests and harness files only run on desktop Wherever they are, the browser-chrome tests (browser_* files of test directories), their manifests (browser*.toml) and the harness files only they use (browser-test.js, browser-harness.xhtml) only run on desktop, except in the web-platform tests. Their support files (e.g. head.js) and the helpers they import (e.g. BrowserTestUtils, also used by chrome mochitests) can be used by other suites, so they're not restricted. --- bugbug/build_platforms.py | 16 ++++++++++++++++ tests/test_build_platforms.py | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index c69bd09c21f..04ea9ee0c9f 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -62,6 +62,17 @@ PRODUCT_DIRECTORIES = {"browser/": DESKTOP_PLATFORMS, "mobile/": frozenset({"android"})} YAML_EXTENSIONS = (".yaml", ".yml") GLEAN_INDEX_URL = "https://hg.mozilla.org/mozilla-central/raw-file/tip/toolkit/components/glean/metrics_index.py" +# The browser-chrome tests (named browser_*), their manifests and the harness files only they use, +# only run on desktop wherever they are (but in the web-platform tests, which are another suite). Their +# support files (e.g. head.js) and the helpers they import (e.g. BrowserTestUtils) can be shared with +# other suites. +BROWSER_CHROME_TEST = re.compile( + r"(^|/)tests?/(.+/)?(browser_[^/]+|browser[\w-]*\.toml)$" +) +BROWSER_CHROME_HARNESS = ( + "testing/mochitest/browser-harness.xhtml", + "testing/mochitest/browser-test.js", +) # The Android Gradle builds also use files out of mobile/, which the Android build's index doesn't list # (e.g. Android Components packages the webcompat extension of browser/): the paths they refer to from # the source directory (see find_gradle_paths). @@ -249,6 +260,11 @@ def _apply_rules(self, path: str, result: frozenset[str]) -> frozenset[str]: "android" in platforms or self.gradle_files is not None ): return (result & platforms) or platforms + if path in BROWSER_CHROME_HARNESS or ( + BROWSER_CHROME_TEST.search(path) + and not path.startswith("testing/web-platform/") + ): + return (result & DESKTOP_PLATFORMS) or DESKTOP_PLATFORMS return result def _used_by_gradle(self, path: str) -> bool: diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index 8d5a97e7f47..fc61474198d 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -99,6 +99,27 @@ def platforms(path, built=BUILT): assert platforms("toolkit/components/glean/metrics.yaml", shared) == set( ALL_PLATFORMS ) + # The browser-chrome tests and their harness are only run on desktop. + assert platforms("toolkit/components/ml/tests/browser/browser_ml.js") == DESKTOP + assert ( + platforms("toolkit/components/pictureinpicture/tests/browser.toml") == DESKTOP + ) + assert platforms("dom/base/test/browser_document.js") == DESKTOP + assert platforms("testing/mochitest/browser-test.js") == DESKTOP + assert platforms("testing/mochitest/browser-harness.xhtml") == DESKTOP + # Their support files and helpers can be used by other suites, e.g. BrowserTestUtils by chrome + # mochitests. + assert platforms("toolkit/crashreporter/test/browser/head.js") == set(ALL_PLATFORMS) + assert platforms( + "testing/mochitest/BrowserTestUtils/BrowserTestUtils.sys.mjs" + ) == set(ALL_PLATFORMS) + assert platforms("dom/base/test/mochitest.toml") == set(ALL_PLATFORMS) + assert platforms( + "toolkit/components/extensions/schemas/browser_action.json" + ) == set(ALL_PLATFORMS) + assert platforms("testing/web-platform/tests/dom/browser_test.html") == set( + ALL_PLATFORMS + ) # Platforms whose files are unknown don't add other products' platforms. without_android = {p: f for p, f in BUILT.items() if p != "android"} assert platforms("browser/components/newtab/content/Card.jsx", without_android) == ( From 7ce7fc48d9376e58400f75dbbe3a5a4b6d065f16 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:32:19 +0100 Subject: [PATCH 7/8] Ignore the files which don't affect the tests' results when finding a patch's platforms Developer tools (agent skills, linters and the type stubs they use, Fluent migrations) and docs don't affect the tests' results on any platform, so they don't count when a patch also modifies other files. A patch only modifying them keeps their platforms. Of the last 3,500 pushes of the group history, 30 more are now restricted to some platforms. --- bugbug/build_platforms.py | 25 +++++++++++++++++++++++-- tests/test_build_platforms.py | 6 ++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index 04ea9ee0c9f..17f3d0adc65 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -73,6 +73,17 @@ "testing/mochitest/browser-harness.xhtml", "testing/mochitest/browser-test.js", ) +# Files which don't affect the tests' results on any platform (developer tools, type stubs for the +# linters, docs, ...): they don't count when a patch also modifies other files. +NEUTRAL_DIRECTORIES = ( + ".agents/", + ".claude/", + "python/l10n/fluent_migrations/", + "tools/@types/", + "tools/lint/", +) +NEUTRAL_FILES = ("stylelint-rollouts.config.js",) +NEUTRAL_EXTENSIONS = (".md", ".rst") # The Android Gradle builds also use files out of mobile/, which the Android build's index doesn't list # (e.g. Android Components packages the webcompat extension of browser/): the paths they refer to from # the source directory (see find_gradle_paths). @@ -314,6 +325,16 @@ def _unbuilt(self, path: str) -> frozenset[str]: ) def find_platforms_for_paths(self, paths: Collection[str]) -> frozenset[str]: - """The platforms building any of `paths`.""" - result: frozenset[str] = frozenset().union(*map(self.platforms, paths)) + """The platforms building any of `paths` (ignoring the neutral ones, unless they all are).""" + relevant = [path for path in paths if not is_neutral(path)] or paths + result: frozenset[str] = frozenset().union(*map(self.platforms, relevant)) return result or ALL_PLATFORMS + + +def is_neutral(path: str) -> bool: + """Whether a file doesn't affect the tests' results on any platform (see NEUTRAL_DIRECTORIES).""" + return ( + path.startswith(NEUTRAL_DIRECTORIES) + or path in NEUTRAL_FILES + or path.endswith(NEUTRAL_EXTENSIONS) + ) diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index fc61474198d..6527ddddc32 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -176,6 +176,12 @@ def test_find_platforms_for_paths() -> None: "macosx", } assert find([]) == ALL_PLATFORMS + # Files which don't affect the tests' results don't count, unless the patch only modifies them. + assert find(["widget/cocoa/nsCocoaWindow.mm", "tools/@types/lib.gecko.d.ts"]) == { + "macosx" + } + assert find(["widget/cocoa/nsCocoaWindow.mm", "dom/docs/index.md"]) == {"macosx"} + assert find(["tools/lint/eslint.yml", "docs/index.rst"]) == ALL_PLATFORMS # A desktop-only patch. assert find( ["browser/components/newtab/content/Card.jsx", "widget/gtk/nsWindow.cpp"] From fec2705e42d2fb1e2fab5c5fd45f393143ecfa8a Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 2 Dec 2026 10:32:54 +0100 Subject: [PATCH 8/8] Consider the build files of a directory built on the platforms building the directory A directory's moz.build and jar manifests are only read by the builds building the directory (e.g. widget/gtk/moz.build on Linux), so they get the platforms of the files of their directory, as files of types the builds list. Test manifests don't, as their tests can run on platforms which don't build the files of their directory. Of the 23,986 pushes of the group history, 51 more are now restricted to some platforms. --- bugbug/build_platforms.py | 15 ++++++++++++++- tests/test_build_platforms.py | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/bugbug/build_platforms.py b/bugbug/build_platforms.py index 17f3d0adc65..d16446e6e9d 100644 --- a/bugbug/build_platforms.py +++ b/bugbug/build_platforms.py @@ -84,6 +84,11 @@ ) NEUTRAL_FILES = ("stylelint-rollouts.config.js",) NEUTRAL_EXTENSIONS = (".md", ".rst") +# The build files of a directory (moz.build, jar manifests) are only read by the builds building it, unlike +# the test manifests, whose tests can run on platforms which don't build the files of their directory. +BUILD_FILE_NAMES = ("moz.build",) +BUILD_FILE_EXTENSIONS = (".mn",) +TEST_DIRECTORY_NAMES = frozenset({"test", "tests", "gtest", "gtests", "mochitest"}) # The Android Gradle builds also use files out of mobile/, which the Android build's index doesn't list # (e.g. Android Components packages the webcompat extension of browser/): the paths they refer to from # the source directory (see find_gradle_paths). @@ -308,7 +313,7 @@ def _platforms(self, path: str) -> frozenset[str]: ) and not path.startswith(NOT_ANDROID_DIRECTORIES): return frozenset({"android"}) - if os.path.splitext(path)[1] not in self.types: + if os.path.splitext(path)[1] not in self.types and not is_build_file(path): return ALL_PLATFORMS for directory in _ancestors(path): @@ -338,3 +343,11 @@ def is_neutral(path: str) -> bool: or path in NEUTRAL_FILES or path.endswith(NEUTRAL_EXTENSIONS) ) + + +def is_build_file(path: str) -> bool: + """Whether a file is a build file of its directory (see BUILD_FILE_NAMES).""" + return ( + os.path.basename(path) in BUILD_FILE_NAMES + or path.endswith(BUILD_FILE_EXTENSIONS) + ) and not TEST_DIRECTORY_NAMES & set(path.split("/")[:-1]) diff --git a/tests/test_build_platforms.py b/tests/test_build_platforms.py index 6527ddddc32..85ce535f93c 100644 --- a/tests/test_build_platforms.py +++ b/tests/test_build_platforms.py @@ -63,7 +63,10 @@ def platforms(path, built=BUILT): assert platforms("README.md") == set(ALL_PLATFORMS) # Files of types no build lists (e.g. inputs of code generation) aren't restricted by directory. assert platforms("browser/base/content/metrics.yaml") == set(ALL_PLATFORMS) - assert platforms("widget/cocoa/moz.build") == set(ALL_PLATFORMS) + # Build files, unlike test manifests, are only read by the builds building their directory. + assert platforms("widget/cocoa/moz.build") == {"macosx"} + assert platforms("widget/cocoa/jar.mn") == {"macosx"} + assert platforms("dom/media/gtest/moz.build") == set(ALL_PLATFORMS) # The Android apps' Kotlin, Java and Gradle files, except the HTML parser's Java code (translated to # C++). assert platforms(