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"""
5Generate labels for tasks without names, consistently.
6Uses attributes from `primary-dependency`.
7"""
8
9
10from gecko_taskgraph.transforms.base import TransformSequence
11
12
13transforms = TransformSequence()
14
15
16@transforms.add
17def make_label(config, jobs):
18    """Generate a sane label for a new task constructed from a dependency
19    Using attributes from the dependent job and the current task kind"""
20    for job in jobs:
21        dep_job = job["primary-dependency"]
22        attr = dep_job.attributes.get
23
24        if attr("locale", job.get("locale")):
25            template = "{kind}-{locale}-{build_platform}/{build_type}"
26        elif attr("l10n_chunk"):
27            template = "{kind}-{build_platform}-{l10n_chunk}/{build_type}"
28        elif config.kind.startswith("release-eme-free") or config.kind.startswith(
29            "release-partner-repack"
30        ):
31            suffix = job.get("extra", {}).get("repack_suffix", None) or job.get(
32                "extra", {}
33            ).get("repack_id", None)
34            template = "{kind}-{build_platform}"
35            if suffix:
36                template += "-{}".format(suffix.replace("/", "-"))
37        else:
38            template = "{kind}-{build_platform}/{build_type}"
39        job["label"] = template.format(
40            kind=config.kind,
41            build_platform=attr("build_platform"),
42            build_type=attr("build_type"),
43            locale=attr("locale", job.get("locale", "")),  # Locale can be absent
44            l10n_chunk=attr("l10n_chunk", ""),  # Can be empty
45        )
46
47        yield job
48