tor-browser

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

repackage_signing.py (5650B)


      1 # This Source Code Form is subject to the terms of the Mozilla Public
      2 # License, v. 2.0. If a copy of the MPL was not distributed with this
      3 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      4 """
      5 Transform the repackage signing task into an actual task description.
      6 """
      7 
      8 import os
      9 
     10 from taskgraph.transforms.base import TransformSequence
     11 from taskgraph.util.dependencies import get_primary_dependency
     12 from taskgraph.util.schema import Schema
     13 from voluptuous import Optional
     14 
     15 from gecko_taskgraph.transforms.task import task_description_schema
     16 from gecko_taskgraph.util.attributes import copy_attributes_from_dependent_job
     17 from gecko_taskgraph.util.scriptworker import get_signing_type_per_platform
     18 
     19 repackage_signing_description_schema = Schema({
     20    Optional("label"): str,
     21    Optional("attributes"): task_description_schema["attributes"],
     22    Optional("dependencies"): task_description_schema["dependencies"],
     23    Optional("task-from"): task_description_schema["task-from"],
     24    Optional("treeherder"): task_description_schema["treeherder"],
     25    Optional("shipping-product"): task_description_schema["shipping-product"],
     26    Optional("shipping-phase"): task_description_schema["shipping-phase"],
     27    Optional("run-on-repo-type"): task_description_schema["run-on-repo-type"],
     28 })
     29 
     30 SIGNING_FORMATS = {
     31    "target.installer.exe": ["gcp_prod_autograph_authenticode_202412_stub"],
     32    "target.stub-installer.exe": ["gcp_prod_autograph_authenticode_202412_stub"],
     33    "target.installer.msi": ["gcp_prod_autograph_authenticode_202412"],
     34    "target.installer.msix": ["gcp_prod_autograph_authenticode_202412"],
     35 }
     36 
     37 transforms = TransformSequence()
     38 
     39 
     40 @transforms.add
     41 def remove_name(config, jobs):
     42    for job in jobs:
     43        if "name" in job:
     44            del job["name"]
     45        yield job
     46 
     47 
     48 transforms.add_validate(repackage_signing_description_schema)
     49 
     50 
     51 @transforms.add
     52 def make_repackage_signing_description(config, jobs):
     53    for job in jobs:
     54        dep_job = get_primary_dependency(config, job)
     55        assert dep_job
     56 
     57        attributes = copy_attributes_from_dependent_job(dep_job)
     58        locale = attributes.get("locale", dep_job.attributes.get("locale"))
     59        attributes["repackage_type"] = "repackage-signing"
     60 
     61        treeherder = job.get("treeherder", {})
     62        treeherder.setdefault("symbol", "rs(B)")
     63        dep_th_platform = dep_job.task.get("extra", {}).get("treeherder-platform")
     64        treeherder.setdefault("platform", dep_th_platform)
     65        treeherder.setdefault(
     66            "tier", dep_job.task.get("extra", {}).get("treeherder", {}).get("tier", 1)
     67        )
     68        treeherder.setdefault("kind", "build")
     69 
     70        if locale:
     71            treeherder["symbol"] = f"rs({locale})"
     72 
     73        if config.kind == "repackage-signing-msi":
     74            treeherder["symbol"] = "MSIs({})".format(locale or "N")
     75 
     76        elif config.kind in (
     77            "repackage-signing-msix",
     78            "repackage-signing-shippable-l10n-msix",
     79        ):
     80            # Like "MSIXs(Bs-multi)".
     81            treeherder["symbol"] = "MSIXs({})".format(
     82                dep_job.task.get("extra", {}).get("treeherder", {}).get("symbol", "B")
     83            )
     84 
     85        label = job["label"]
     86 
     87        dep_kind = dep_job.kind
     88        if "l10n" in dep_kind:
     89            dep_kind = "repackage"
     90 
     91        dependencies = {dep_kind: dep_job.label}
     92 
     93        signing_dependencies = dep_job.dependencies
     94        # This is so we get the build task etc in our dependencies to have better beetmover
     95        # support.  But for multi-locale MSIX packages, we don't want the signing task to directly
     96        # depend on the langpack tasks.
     97        dependencies.update({
     98            k: v
     99            for k, v in signing_dependencies.items()
    100            if k != "docker-image"
    101            and not k.startswith("shippable-l10n-signing-linux64")
    102        })
    103 
    104        description = (
    105            "Signing of repackaged artifacts for locale '{locale}' for build '"
    106            "{build_platform}/{build_type}'".format(
    107                locale=attributes.get("locale", "en-US"),
    108                build_platform=attributes.get("build_platform"),
    109                build_type=attributes.get("build_type"),
    110            )
    111        )
    112 
    113        build_platform = dep_job.attributes.get("build_platform")
    114        is_shippable = dep_job.attributes.get("shippable")
    115        signing_type = get_signing_type_per_platform(
    116            build_platform, is_shippable, config
    117        )
    118 
    119        upstream_artifacts = []
    120        for artifact in sorted(dep_job.attributes.get("release_artifacts")):
    121            basename = os.path.basename(artifact)
    122            if basename in SIGNING_FORMATS:
    123                upstream_artifacts.append({
    124                    "taskId": {"task-reference": f"<{dep_kind}>"},
    125                    "taskType": "repackage",
    126                    "paths": [artifact],
    127                    "formats": SIGNING_FORMATS[os.path.basename(artifact)],
    128                })
    129 
    130        task = {
    131            "label": label,
    132            "description": description,
    133            "worker-type": "linux-signing" if is_shippable else "linux-depsigning",
    134            "worker": {
    135                "implementation": "scriptworker-signing",
    136                "signing-type": signing_type,
    137                "upstream-artifacts": upstream_artifacts,
    138            },
    139            "dependencies": dependencies,
    140            "attributes": attributes,
    141            "run-on-repo-type": job.get("run-on-repo-type", ["git", "hg"]),
    142            "run-on-projects": dep_job.attributes.get("run_on_projects"),
    143            "optimization": dep_job.optimization,
    144            "treeherder": treeherder,
    145        }
    146 
    147        yield task