tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

desktop_partner_repacks.py (6917B)


      1 #!/usr/bin/env python
      2 # This Source Code Form is subject to the terms of the Mozilla Public
      3 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
      4 # You can obtain one at http://mozilla.org/MPL/2.0/.
      5 """desktop_partner_repacks.py
      6 
      7 This script manages Desktop partner repacks for beta/release builds.
      8 """
      9 
     10 import os
     11 import sys
     12 
     13 # load modules from parent dir
     14 sys.path.insert(1, os.path.dirname(sys.path[0]))
     15 
     16 from mozharness.base.log import FATAL
     17 from mozharness.base.python import VirtualenvMixin
     18 from mozharness.base.script import BaseScript
     19 from mozharness.mozilla.automation import AutomationMixin
     20 from mozharness.mozilla.secrets import SecretsMixin
     21 
     22 
     23 # DesktopPartnerRepacks {{{1
     24 class DesktopPartnerRepacks(AutomationMixin, BaseScript, VirtualenvMixin, SecretsMixin):
     25    """Manages desktop partner repacks"""
     26 
     27    actions = [
     28        "get-secrets",
     29        "setup",
     30        "repack",
     31        "summary",
     32    ]
     33    config_options = [
     34        [
     35            ["--version", "-v"],
     36            {
     37                "dest": "version",
     38                "help": "Version of Firefox to repack",
     39            },
     40        ],
     41        [
     42            ["--build-number", "-n"],
     43            {
     44                "dest": "build_number",
     45                "help": "Build number of Firefox to repack",
     46            },
     47        ],
     48        [
     49            ["--platform"],
     50            {
     51                "dest": "platform",
     52                "help": "Platform to repack (e.g. linux64, macosx64, ...)",
     53            },
     54        ],
     55        [
     56            ["--partner", "-p"],
     57            {
     58                "dest": "partner",
     59                "help": "Limit repackaging to partners matching this string",
     60            },
     61        ],
     62        [
     63            ["--taskid", "-t"],
     64            {
     65                "dest": "taskIds",
     66                "action": "extend",
     67                "help": "taskId(s) of upstream tasks for vanilla Firefox artifacts",
     68            },
     69        ],
     70        [
     71            ["--limit-locale", "-l"],
     72            {
     73                "dest": "limitLocales",
     74                "action": "append",
     75            },
     76        ],
     77    ]
     78 
     79    def __init__(self):
     80        # fxbuild style:
     81        buildscript_kwargs = {
     82            "all_actions": DesktopPartnerRepacks.actions,
     83            "default_actions": DesktopPartnerRepacks.actions,
     84            "config": {
     85                "log_name": "partner-repacks",
     86                "hashType": "sha512",
     87                "workdir": "partner-repacks",
     88            },
     89        }
     90 
     91        BaseScript.__init__(
     92            self, config_options=self.config_options, **buildscript_kwargs
     93        )
     94 
     95    def _pre_config_lock(self, rw_config):
     96        if os.getenv("REPACK_MANIFESTS_URL"):
     97            self.info(
     98                "Overriding repack_manifests_url to %s"
     99                % os.getenv("REPACK_MANIFESTS_URL")
    100            )
    101            self.config["repack_manifests_url"] = os.getenv("REPACK_MANIFESTS_URL")
    102        if os.getenv("UPSTREAM_TASKIDS"):
    103            self.info("Overriding taskIds with %s" % os.getenv("UPSTREAM_TASKIDS"))
    104            self.config["taskIds"] = os.getenv("UPSTREAM_TASKIDS").split()
    105 
    106        if "version" not in self.config:
    107            self.fatal("Version (-v) not supplied.")
    108        if "build_number" not in self.config:
    109            self.fatal("Build number (-n) not supplied.")
    110        if "repo_file" not in self.config:
    111            self.fatal("repo_file not supplied.")
    112        if "repack_manifests_url" not in self.config:
    113            self.fatal(
    114                "repack_manifests_url not supplied in config or via REPACK_MANIFESTS_URL"
    115            )
    116        if "taskIds" not in self.config:
    117            self.fatal("Need upstream taskIds from command line or in UPSTREAM_TASKIDS")
    118 
    119    def query_abs_dirs(self):
    120        if self.abs_dirs:
    121            return self.abs_dirs
    122        abs_dirs = super().query_abs_dirs()
    123        for directory in abs_dirs:
    124            value = abs_dirs[directory]
    125            abs_dirs[directory] = value
    126        dirs = {}
    127        dirs["abs_repo_dir"] = os.path.join(abs_dirs["abs_work_dir"], ".repo")
    128        dirs["abs_partners_dir"] = os.path.join(abs_dirs["abs_work_dir"], "partners")
    129        for key in dirs.keys():
    130            if key not in abs_dirs:
    131                abs_dirs[key] = dirs[key]
    132        self.abs_dirs = abs_dirs
    133        return self.abs_dirs
    134 
    135    # Actions {{{
    136    def _repo_cleanup(self):
    137        self.rmtree(self.query_abs_dirs()["abs_repo_dir"])
    138        self.rmtree(self.query_abs_dirs()["abs_partners_dir"])
    139 
    140    def _repo_init(self, repo):
    141        partial_env = {
    142            "GIT_SSH_COMMAND": "ssh -oIdentityFile={}".format(self.config["ssh_key"])
    143        }
    144        status = self.run_command(
    145            [
    146                sys.executable,
    147                repo,
    148                "init",
    149                "--no-repo-verify",
    150                "-u",
    151                self.config["repack_manifests_url"],
    152            ],
    153            cwd=self.query_abs_dirs()["abs_work_dir"],
    154            partial_env=partial_env,
    155        )
    156        if status:
    157            return status
    158        return self.run_command(
    159            [sys.executable, repo, "sync", "--current-branch", "--no-tags"],
    160            cwd=self.query_abs_dirs()["abs_work_dir"],
    161            partial_env=partial_env,
    162        )
    163 
    164    def setup(self):
    165        """setup step"""
    166        repo = self.download_file(
    167            self.config["repo_file"],
    168            file_name="repo",
    169            parent_dir=self.query_abs_dirs()["abs_work_dir"],
    170            error_level=FATAL,
    171        )
    172        if not os.path.exists(repo):
    173            self.fatal("Unable to download repo tool.")
    174        self.chmod(repo, 0o755)
    175        self.retry(
    176            self._repo_init,
    177            args=(repo,),
    178            error_level=FATAL,
    179            cleanup=self._repo_cleanup(),
    180            good_statuses=[0],
    181            sleeptime=5,
    182        )
    183 
    184    def repack(self):
    185        """creates the repacks"""
    186        repack_cmd = [
    187            "./mach",
    188            "python",
    189            "python/mozrelease/mozrelease/partner_repack.py",
    190            "-v",
    191            self.config["version"],
    192            "-n",
    193            str(self.config["build_number"]),
    194        ]
    195        if self.config.get("platform"):
    196            repack_cmd.extend(["--platform", self.config["platform"]])
    197        if self.config.get("partner"):
    198            repack_cmd.extend(["--partner", self.config["partner"]])
    199        if self.config.get("taskIds"):
    200            for taskId in self.config["taskIds"]:
    201                repack_cmd.extend(["--taskid", taskId])
    202        if self.config.get("limitLocales"):
    203            for locale in self.config["limitLocales"]:
    204                repack_cmd.extend(["--limit-locale", locale])
    205 
    206        self.run_command(repack_cmd, cwd=os.environ["GECKO_PATH"], halt_on_failure=True)
    207 
    208 
    209 # main {{{
    210 if __name__ == "__main__":
    211    partner_repacks = DesktopPartnerRepacks()
    212    partner_repacks.run_and_exit()