brizental pushed to branch tor-browser-156.0a1-17.0-2 at The Tor Project / Applications / Tor Browser Commits: 47aef959 by Beatriz Rizental at 2026-11-19T09:13:13-03:00 fixup! BB 43564: Modify ./mach bootstrap for Base Browser Bug 45396: Fetch artifacts from our toolchains when building artifact builds. - - - - - 928c2e1e by Beatriz Rizental at 2026-11-19T09:13:14-03:00 fixup! BB 43564: Modify ./mach bootstrap for Base Browser Bug 45396: Remove not about bootstrap being experimental. It's not anymore. - - - - - 6 changed files: - python/mozboot/mozboot/bootstrap.py - python/mozbuild/mozbuild/artifacts.py - python/mozbuild/mozbuild/tbbutils.py - python/mozbuild/mozbuild/test/python.toml - + python/mozbuild/mozbuild/test/test_tbb_artifacts.py - python/mozbuild/mozbuild/test/test_tbbutils.py Changes: ===================================== python/mozboot/mozboot/bootstrap.py ===================================== @@ -54,10 +54,6 @@ Tor Browser for Android frontends, or the GeckoView Java API. They are unsuitabl for those working on C++ code. For more information see: https://firefox-source-docs.mozilla.org/contributing/build/artifact_builds.h.... -# Note to Tor Browser developers - -This is still highly experimental. Expect bugs! - Please choose the version of Tor Browser you want to build (see note above): %s Your choice: """ ===================================== python/mozbuild/mozbuild/artifacts.py ===================================== @@ -60,6 +60,7 @@ from mozpack.files import FileFinder, JarFinder, TarFinder from mozpack.mozjar import JarReader, JarWriter from mozpack.packager.unpack import UnpackFinder +from mozbuild import tbbutils from mozbuild.artifact_builds import JOB_CHOICES from mozbuild.artifact_cache import ArtifactCache from mozbuild.dirutils import ensureParentDir, mkdir @@ -1795,6 +1796,23 @@ https://firefox-source-docs.mozilla.org/contributing/vcs/mercurial_bundles.h... ) return 1 + def install_from_tor_project_artifacts(self, distdir): + version = self._substs["MOZ_APP_VERSION"] + urls = tbbutils.find_artifact_urls(self._job, version, self._artifact_job) + if not urls: + raise ValueError(f"Unable to fetch list of artifacts for job {self._job}") + for url in urls: + self.log( + logging.INFO, + "artifact", + {"url": url}, + "Installing Tor Project artifact from {url}", + ) + if self.install_from_url(url, distdir): + return 1 + + return 0 + def install_from_recent(self, distdir): hg_pushheads = self._find_pushheads() return self._install_from_hg_pushheads(hg_pushheads, distdir) @@ -1905,7 +1923,7 @@ https://firefox-source-docs.mozilla.org/contributing/vcs/mercurial_bundles.h... if var in os.environ: return self.install_from_task(os.environ[var], distdir) - return self.install_from_recent(distdir) + return self.install_from_tor_project_artifacts(distdir) def clear_cache(self): self.log(logging.INFO, "artifact", {}, "Deleting cached artifacts and caches.") ===================================== python/mozbuild/mozbuild/tbbutils.py ===================================== @@ -14,7 +14,7 @@ def list_files_http(url): links = [] for href in re.findall(r'<a href="([^"]+)"', html): - if href == "../": + if href == "../" or href.startswith(("?", "/")): continue if "tor-expert-bundle-aar" in href: @@ -125,3 +125,45 @@ def get_artifact_path(url, artifact, target, prefix="", log=lambda *args, **kwar matches = filter_files(files_per_os, target.cpu) return f"{url}/{artifact}/{matches[0]}" if matches else None + + +TOR_PROJECT_TOOLCHAINS_URL = ( + "https://nightlies.tbb.torproject.org/nightly-builds/toolchains" +) +TOR_PROJECT_BROWSER_PREFIX = "tb" + +# Mozilla job name prefix -> Tor Project toolchain target. Order matters: more +# specific prefixes must come before the prefixes they start with. +TOR_PROJECT_TOOLCHAIN_TARGETS = ( + ("android-arm", "android-armeabi-v7a"), + ("android-aarch64", "android-arm64-v8a"), + ("android-x86_64", "android-x86_64"), + ("linux64-aarch64", "linux-aarch64"), + ("linux64", "linux-x86_64"), + ("macosx64-aarch64", "macos-aarch64"), + ("macosx64", "macos-x86_64"), + ("win32", "windows-i686"), + ("win64", "windows-x86_64"), +) + + +def get_artifacts_dir_url(job, version): + for prefix, target in TOR_PROJECT_TOOLCHAIN_TARGETS: + if job.startswith(prefix): + return f"{TOR_PROJECT_TOOLCHAINS_URL}/{TOR_PROJECT_BROWSER_PREFIX}-{version}/{target}" + raise ValueError(f"No Tor Project toolchain artifacts for {version}, {job}") + + +def find_artifact_urls(job, version, artifact_job): + """ + Return the URLs of the artifacts available for ``job`` that + ``artifact_job`` (a mozbuild.artifacts.ArtifactJob) wants to install. + """ + url = get_artifacts_dir_url(job, version) + artifacts = [ + {"name": f"public/build/{name}"} for name in list_files_http(f"{url}/") + ] + return [ + f"{url}/{artifact.rsplit('/', 1)[-1]}" + for artifact in artifact_job.find_candidate_artifacts(artifacts) + ] ===================================== python/mozbuild/mozbuild/test/python.toml ===================================== @@ -137,6 +137,9 @@ subsuite = "mozbuild" ["test_site_dependency_extractor.py"] +["test_tbb_artifacts.py"] +subsuite = "base-browser" + ["test_tbbutils.py"] subsuite = "base-browser" ===================================== python/mozbuild/mozbuild/test/test_tbb_artifacts.py ===================================== @@ -0,0 +1,80 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import tempfile +from unittest import TestCase, mock + +import mozunit + +from mozbuild import tbbutils +from mozbuild.artifacts import Artifacts +from mozbuild.tbbutils import TOR_PROJECT_BROWSER_PREFIX, TOR_PROJECT_TOOLCHAINS_URL + +BASE_URL = ( + f"{TOR_PROJECT_TOOLCHAINS_URL}/{TOR_PROJECT_BROWSER_PREFIX}-140.0/linux-x86_64" +) + + +class TestTorProjectArtifacts(TestCase): + def setUp(self): + self._tmpdir = tempfile.TemporaryDirectory() + self.addCleanup(self._tmpdir.cleanup) + self.log = mock.Mock() + self.artifacts = self._make_artifacts("linux64-opt") + + def _make_artifacts(self, job): + return Artifacts( + tree=None, + substs={"MOZ_APP_VERSION": "140.0"}, + defines={}, + job=job, + log=self.log, + cache_dir=self._tmpdir.name, + git="git", + ) + + def test_install_from_tor_project_artifacts(self): + with mock.patch.object( + tbbutils, + "find_artifact_urls", + return_value=[f"{BASE_URL}/target.tar.xz", f"{BASE_URL}/target.zip"], + ), mock.patch.object( + self.artifacts, "install_from_url", return_value=0 + ) as install_from_url: + self.assertEqual( + self.artifacts.install_from_tor_project_artifacts("dist"), 0 + ) + + self.assertEqual( + install_from_url.call_args_list, + [ + mock.call(f"{BASE_URL}/target.tar.xz", "dist"), + mock.call(f"{BASE_URL}/target.zip", "dist"), + ], + ) + + def test_install_from_tor_project_artifacts_stops_on_failure(self): + with mock.patch.object( + tbbutils, + "find_artifact_urls", + return_value=[f"{BASE_URL}/a.tar.xz", f"{BASE_URL}/b.tar.xz"], + ), mock.patch.object( + self.artifacts, "install_from_url", return_value=1 + ) as install_from_url: + self.assertEqual( + self.artifacts.install_from_tor_project_artifacts("dist"), 1 + ) + self.assertEqual(install_from_url.call_count, 1) + + def test_install_from_tor_project_artifacts_no_artifacts(self): + with mock.patch.object( + tbbutils, "find_artifact_urls", return_value=[] + ), mock.patch.object(self.artifacts, "install_from_url") as install_from_url: + with self.assertRaises(ValueError): + self.artifacts.install_from_tor_project_artifacts("dist") + install_from_url.assert_not_called() + + +if __name__ == "__main__": + mozunit.main() ===================================== python/mozbuild/mozbuild/test/test_tbbutils.py ===================================== @@ -4,9 +4,14 @@ from unittest.mock import MagicMock, patch import mozunit +from mozbuild.artifacts import LinuxArtifactJob from mozbuild.tbbutils import ( + TOR_PROJECT_BROWSER_PREFIX, + TOR_PROJECT_TOOLCHAINS_URL, + find_artifact_urls, get_artifact_index, get_artifact_path, + get_artifacts_dir_url, list_files_http, ) @@ -140,6 +145,8 @@ class TestListFilesHttp(unittest.TestCase): html = b""" <html><body> <a href="../">Parent</a> + <a href="?C=N;O=D">Name</a> + <a href="/nightly-builds/toolchains/">Up</a> <a href="file1.zip">file1</a> <a href="file2.zip">file2</a> </body></html> @@ -173,5 +180,58 @@ class TestListFilesHttp(unittest.TestCase): ) +class TestTorProjectArtifacts(unittest.TestCase): + def test_get_artifacts_dir_url_for_each_job(self): + expected_targets = { + "android-arm-opt": "android-armeabi-v7a", + "android-aarch64-opt": "android-arm64-v8a", + "android-x86_64-debug": "android-x86_64", + "linux64-opt": "linux-x86_64", + "linux64-aarch64-opt": "linux-aarch64", + "macosx64-opt": "macos-x86_64", + "macosx64-aarch64-debug": "macos-aarch64", + "win32-opt": "windows-i686", + "win64-debug": "windows-x86_64", + } + for job, target in expected_targets.items(): + with self.subTest(job=job): + self.assertEqual( + get_artifacts_dir_url(job, "140.0"), + f"{TOR_PROJECT_TOOLCHAINS_URL}/{TOR_PROJECT_BROWSER_PREFIX}-140.0/{target}", + ) + + def test_get_artifacts_dir_url_unknown_job(self): + with self.assertRaises(ValueError): + get_artifacts_dir_url("freebsd64-opt", "140.0") + + @patch("mozbuild.tbbutils.list_files_http") + def test_find_artifact_urls(self, mock_list_files_http): + mock_list_files_http.return_value = [ + "mozharness.zip", + "target.common.tests.tar.zst", + "target.mochitest.tests.tar.zst", + "target.tar.xz", + "target.xpt_artifacts.zip", + ] + + urls = find_artifact_urls("linux64-opt", "140.0", LinuxArtifactJob()) + + base = f"{TOR_PROJECT_TOOLCHAINS_URL}/{TOR_PROJECT_BROWSER_PREFIX}-140.0/linux-x86_64" + mock_list_files_http.assert_called_once_with(f"{base}/") + self.assertEqual( + urls, + [ + f"{base}/target.common.tests.tar.zst", + f"{base}/target.tar.xz", + f"{base}/target.xpt_artifacts.zip", + ], + ) + + @patch("mozbuild.tbbutils.list_files_http", return_value=["target.tar.xz"]) + def test_find_artifact_urls_missing_tests(self, _): + with self.assertRaises(ValueError): + find_artifact_urls("linux64-opt", "140.0", LinuxArtifactJob()) + + if __name__ == "__main__": mozunit.main() View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/bf25a48... -- View it on GitLab: https://gitlab.torproject.org/tpo/applications/tor-browser/-/compare/bf25a48... You're receiving this email because of your account on gitlab.torproject.org. Manage all notifications: https://gitlab.torproject.org/-/profile/notifications | Help: https://gitlab.torproject.org/help
participants (1)
-
brizental (@brizental)