Commit 10ce4ee0 authored by brizental's avatar brizental
Browse files

fixup! BB 43564: Modify ./mach bootstrap for Base Browser

parent 98a01dbd
Loading
Loading
Loading
Loading
+1 −3
Changes for build/moz.configure/bootstrap.configure: 1 added line, 3 removed lines.
Original line number Diff line number Diff line
@@ -205,9 +205,7 @@ def bootstrap_path(path, **kwargs):
            if not target.tor_browser_build_alias:
                return False

            artifact = mozbuild.tbbutils.get_artifact_name(
                path_parts[0], target, tasks.prefix
            )
            artifact = mozbuild.tbbutils.get_artifact_name(path_parts[0], tasks.prefix)
            if not artifact:
                log.info("%s is not mapped to a tbb artifact", path_parts[0])
                return False
+9 −4
Changes for python/mozbuild/mozbuild/tbbutils.py: 9 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ ARTIFACT_NAME_MAP = {
}


def get_artifact_name(original_artifact_name, target, host):
def get_artifact_name(original_artifact_name, host):
    # These are not build artifacts, they are pre-built artifacts to be added to the final build,
    # therefore this check can come before the host check.
    if original_artifact_name in TOR_BROWSER_BUILD_ARTIFACTS:
@@ -72,7 +72,7 @@ def get_artifact_path(url, artifact, target, prefix=""):
    def filter_files(files, keyword):
        return [file for file in files if keyword in file]

    artifact_files = filter_files(files, artifact)
    artifact_files = [file for file in files if file.startswith(artifact)]

    if len(artifact_files) == 1:
        return f"{url}/{path}/{artifact_files[0]}"
@@ -80,8 +80,13 @@ def get_artifact_path(url, artifact, target, prefix=""):
    files_per_os = filter_files(artifact_files, target.tor_browser_build_alias)

    # If there are files in the folder, but they don't have the OS in the name
    # it means we can get any of them because they can be used to build for any OS.
    # So let's just get the first one.
    # it probably means we can get any of them because they can be used to build
    # for any OS. So let's just get the first one.
    #
    # Note: It could be the case that the artifact _is_ OS dependant, but there
    # just are no files for the OS we are looking for. In that case, this will
    # return an incorrect artifact. This should not happen often though and is
    # something we cannot address until artifact names are standardized on tbb.
    if len(files_per_os) == 0:
        return f"{url}/{artifact}/{artifact_files[0]}"

+3 −0
Changes for python/mozbuild/mozbuild/test/python.toml: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -111,6 +111,9 @@ subsuite = "mozbuild"

["test_rewrite_mozbuild.py"]

["test_tbbutils.py"]
subsuite = "base-browser"

["test_telemetry.py"]

["test_telemetry_settings.py"]
+133 −0
Changes for python/mozbuild/mozbuild/test/test_tbbutils.py: 133 added lines, 0 removed lines.
Original line number Diff line number Diff line
import unittest
from types import SimpleNamespace
from unittest.mock import MagicMock, patch

import mozunit

from mozbuild.tbbutils import get_artifact_path, list_files_http


class TestGetArtifactName(unittest.TestCase):
    def setUp(self):
        self.artifact = "artifact"
        self.host = "linux64"

    @patch("mozbuild.tbbutils.TOR_BROWSER_BUILD_ARTIFACTS", new=["artifact"])
    def test_artifact_in_tbb_artifacts(self):
        from mozbuild.tbbutils import get_artifact_name

        result = get_artifact_name(self.artifact, self.host)
        self.assertEqual(result, self.artifact)

    @patch("mozbuild.tbbutils.ARTIFACT_NAME_MAP", new={"artifact": "tcafitra"})
    def test_host_is_not_linux64(self):
        from mozbuild.tbbutils import get_artifact_name

        result = get_artifact_name(self.artifact, "linux64-aarch64")
        self.assertIsNone(result)

    @patch("mozbuild.tbbutils.ARTIFACT_NAME_MAP", new={"artifact": "tcafitra"})
    def test_mapped_artifact(self):
        from mozbuild.tbbutils import get_artifact_name

        result = get_artifact_name(self.artifact, self.host)
        self.assertEqual(result, self.artifact[::-1])


class TestGetArtifactPath(unittest.TestCase):
    def setUp(self):
        self.url = "http://example.com"
        self.artifact = "artifact"
        # This is just an example target which is valid. But it doesn't make
        # any difference and could be anything for these tests.
        self.target = SimpleNamespace(tor_browser_build_alias="linux", cpu="x86_64")

    @patch("mozbuild.tbbutils.list_files_http")
    def test_no_files_returns_none(self, mock_list_files):
        mock_list_files.return_value = []
        result = get_artifact_path(self.url, self.artifact, self.target)
        self.assertIsNone(result)

    @patch("mozbuild.tbbutils.list_files_http")
    def test_single_artifact_match(self, mock_list_files):
        mock_list_files.return_value = ["artifact-1.zip"]
        result = get_artifact_path(self.url, self.artifact, self.target)
        self.assertEqual(result, f"{self.url}/{self.artifact}/artifact-1.zip")

    @patch("mozbuild.tbbutils.list_files_http")
    def test_artifact_without_os_returns_first(self, mock_list_files):
        mock_list_files.return_value = ["artifact-1.zip", "artifact-2.zip"]
        result = get_artifact_path(self.url, self.artifact, self.target)
        self.assertTrue(result.startswith(f"{self.url}/{self.artifact}/"))
        self.assertIn("artifact-", result)

    @patch("mozbuild.tbbutils.list_files_http")
    def test_artifact_with_os_match(self, mock_list_files):
        mock_list_files.return_value = [
            "artifact-windows.zip",
            "artifact-linux.zip",
        ]
        result = get_artifact_path(self.url, self.artifact, self.target)
        self.assertEqual(result, f"{self.url}/{self.artifact}/artifact-linux.zip")

    @patch("mozbuild.tbbutils.list_files_http")
    def test_artifact_with_cpu_match(self, mock_list_files):
        mock_list_files.return_value = [
            "artifact-linux-arm.zip",
            "artifact-linux-x86_64.zip",
        ]
        result = get_artifact_path(self.url, self.artifact, self.target)
        self.assertEqual(
            result, f"{self.url}/{self.artifact}/artifact-linux-x86_64.zip"
        )

    @patch("mozbuild.tbbutils.list_files_http")
    def test_artifact_with_prefix(self, mock_list_files):
        mock_list_files.return_value = ["artifact-1.zip"]

        prefix = "prefix"
        result = get_artifact_path(self.url, self.artifact, self.target, prefix=prefix)
        self.assertEqual(result, f"{self.url}/{prefix}/artifact-1.zip")
        mock_list_files.assert_called_with(f"{self.url}/{prefix}?C=M;O=D")


class TestListFilesHttp(unittest.TestCase):
    def setUp(self):
        self.url = "http://example.com"

    @patch("mozbuild.tbbutils.urlopen")
    def test_non_200_status_returns_empty(self, mock_urlopen):
        mock_resp = MagicMock()
        mock_resp.status = 404
        mock_resp.read.return_value = b""
        mock_urlopen.return_value.__enter__.return_value = mock_resp

        result = list_files_http(self.url)
        self.assertEqual(result, [])

    @patch("mozbuild.tbbutils.urlopen")
    def test_exception_returns_empty(self, mock_urlopen):
        mock_urlopen.side_effect = Exception("network error")
        result = list_files_http(self.url)
        self.assertEqual(result, [])

    @patch("mozbuild.tbbutils.urlopen")
    def test_regular_links(self, mock_urlopen):
        html = b"""
        <html><body>
        <a href="../">Parent</a>
        <a href="file1.zip">file1</a>
        <a href="file2.zip">file2</a>
        </body></html>
        """
        mock_resp = MagicMock()
        mock_resp.status = 200
        mock_resp.read.return_value = html
        mock_urlopen.return_value.__enter__.return_value = mock_resp

        result = list_files_http(self.url)
        self.assertEqual(result, ["file1.zip", "file2.zip"])


if __name__ == "__main__":
    mozunit.main()