summaryrefslogtreecommitdiffstats
path: root/taskcluster/gecko_taskgraph/transforms/attribution.py
blob: 42d0f20f7934ea5a7e6f14accf4a54cd12e4a093 (plain)
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
# 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.schema import resolve_keyed_by

transforms = TransformSequence()
resolve_keyed_by_transforms = TransformSequence()


@resolve_keyed_by_transforms.add
def attribution_keyed_by(config, jobs):
    keyed_by_fields = (
        "fetches",
        "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 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_name, dep_label = next(iter(job["dependencies"].items()))
        dep_task = config.kind_dependencies_tasks[dep_label]
        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_name].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 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:
        if "macosx" in job["attributes"]["build_platform"]:
            # Last argument of command should be the attribution data
            command = job["run"]["command"]
            attribution_arg = command[-1]
            # Attribution length should be aligned with ATTR_CODE_MAX_LENGTH
            #   from browser/components/attribution/AttributionCode.sys
            while len(attribution_arg) < 1010:
                attribution_arg += "\t"
            # Wrap attribution value in quotes to prevent run-task from removing tabs
            command[-1] = "'" + attribution_arg + "'"
            job["run"]["command"] = " ".join(command)
        yield job