File: attribution.py

package info (click to toggle)
firefox 147.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,484 kB
  • sloc: cpp: 7,607,246; javascript: 6,533,185; ansic: 3,775,227; python: 1,415,393; xml: 634,561; asm: 438,951; java: 186,241; sh: 62,752; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (120 lines) | stat: -rw-r--r-- 4,051 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# 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/.

from taskgraph.transforms.base import TransformSequence
from taskgraph.util.dependencies import get_primary_dependency
from taskgraph.util.schema import resolve_keyed_by

from gecko_taskgraph.util.partners import build_macos_attribution_dmg_command

transforms = TransformSequence()
resolve_keyed_by_transforms = TransformSequence()


@resolve_keyed_by_transforms.add
def attribution_keyed_by(config, jobs):
    keyed_by_fields = (
        "attributes.release_artifacts",
        "run.command",
        "properties-with-locale",  # properties-with-locale only exists in the l10n task
    )
    for job in jobs:
        build_platform = {"build-platform": job["attributes"]["build_platform"]}
        for field in keyed_by_fields:
            resolve_keyed_by(item=job, field=field, item_name=field, **build_platform)
        yield job


@transforms.add
def remove_attributes(config, jobs):
    """Remove attributes from parent task that aren't necessary."""
    for job in jobs:
        for attr in (
            "accepted-mar-channel-ids",
            "l10n_chunk",
            "mar-channel-id",
            "repackage_type",
            "required_signoffs",
            "shippable",
            "signed",
            "stub-installer",
            "update-channel",
        ):
            if attr in job["attributes"]:
                del job["attributes"][attr]
        yield job


@transforms.add
def stub_installer(config, jobs):
    """Not all windows builds come with a stub installer (only win32, and not
    on esr), so conditionally add it here based on our dependency's
    stub-installer attribute."""
    for job in jobs:
        dep_task = get_primary_dependency(config, job)
        assert dep_task

        if dep_task.attributes.get("stub-installer"):
            locale = job["attributes"].get("locale")
            if locale:
                artifact = f"{locale}/target.stub-installer.exe"
            else:
                artifact = "target.stub-installer.exe"

            job["fetches"][dep_task.kind].append(artifact)
            job["run"]["command"] += [
                "--input",
                "/builds/worker/fetches/target.stub-installer.exe",
            ]
            job["attributes"]["release_artifacts"].append(
                "public/build/target.stub-installer.exe"
            )
        yield job


@transforms.add
def set_treeherder(config, jobs):
    for job in jobs:
        th = job.setdefault("treeherder", {})
        attrs = job["attributes"]

        th["platform"] = f"{attrs['build_platform']}/{attrs['build_type']}"
        th["symbol"] = th["symbol"].format(**attrs)
        yield job


@transforms.add
def set_locale_label(config, jobs):
    for job in jobs:
        attrs = job["attributes"]
        if locale := attrs.get("locale"):
            platform, ship_type = attrs["build_platform"].rsplit("-", 1)
            job["label"] = (
                f"attribution-{platform}-{locale}-{ship_type}/{attrs['build_type']}"
            )

        yield job


@transforms.add
def mac_attribution(config, jobs):
    """Adds \t padding to the mac attribution data. Implicitly assumes that the
    attribution data is the last thing in job.run.command
    """
    for job in jobs:
        dlsource = job.pop("dlsource")
        if "macosx" in job["attributes"]["build_platform"]:
            job["run"]["command"] = build_macos_attribution_dmg_command(
                "/builds/worker/fetches/dmg/dmg",
                [
                    {
                        "input": "/builds/worker/fetches/target.dmg",
                        "output": "/builds/worker/artifacts/target.dmg",
                        "attribution": f"dlsource={dlsource}",
                    }
                ],
            )
            job["fetches"].setdefault("toolchain", []).append("linux64-libdmg")

        yield job