2019-09-24 10:52:05 +00:00
|
|
|
# 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/.
|
|
|
|
"""
|
|
|
|
Apply some defaults and minor modifications to the single_dep jobs.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from taskgraph.transforms.base import TransformSequence
|
2019-11-26 15:20:35 +00:00
|
|
|
from taskgraph.util.schema import resolve_keyed_by
|
2019-09-24 10:52:05 +00:00
|
|
|
from taskgraph.util.treeherder import inherit_treeherder_from_dep, join_symbol
|
|
|
|
|
2021-04-22 19:34:51 +00:00
|
|
|
from fenix_taskgraph.util.scriptworker import generate_beetmover_upstream_artifacts
|
|
|
|
|
2019-09-24 10:52:05 +00:00
|
|
|
|
|
|
|
transforms = TransformSequence()
|
|
|
|
|
|
|
|
|
|
|
|
@transforms.add
|
|
|
|
def build_name_and_attributes(config, tasks):
|
|
|
|
for task in tasks:
|
2019-12-05 04:14:58 +00:00
|
|
|
task["dependencies"] = {
|
2022-03-11 23:23:38 +00:00
|
|
|
dep_key: dep.label for dep_key, dep in _get_all_deps(task).items()
|
2019-12-05 04:14:58 +00:00
|
|
|
}
|
|
|
|
primary_dep = task["primary-dependency"]
|
|
|
|
copy_of_attributes = primary_dep.attributes.copy()
|
2021-04-22 19:34:51 +00:00
|
|
|
task.setdefault("attributes", {}).update(copy_of_attributes)
|
2019-09-24 10:52:05 +00:00
|
|
|
# run_on_tasks_for is set as an attribute later in the pipeline
|
2022-03-11 23:23:38 +00:00
|
|
|
task.setdefault("run-on-tasks-for", copy_of_attributes["run_on_tasks_for"])
|
2019-12-05 04:14:58 +00:00
|
|
|
task["name"] = _get_dependent_job_name_without_its_kind(primary_dep)
|
2019-09-24 10:52:05 +00:00
|
|
|
|
|
|
|
yield task
|
|
|
|
|
|
|
|
|
|
|
|
def _get_dependent_job_name_without_its_kind(dependent_job):
|
2022-03-11 23:23:38 +00:00
|
|
|
return dependent_job.label[len(dependent_job.kind) + 1 :]
|
2019-09-24 10:52:05 +00:00
|
|
|
|
|
|
|
|
2019-12-05 04:14:58 +00:00
|
|
|
def _get_all_deps(task):
|
|
|
|
if task.get("dependent-tasks"):
|
|
|
|
return task["dependent-tasks"]
|
|
|
|
|
|
|
|
return {task["primary-dependency"].kind: task["primary-dependency"]}
|
|
|
|
|
|
|
|
|
2019-11-26 15:20:35 +00:00
|
|
|
@transforms.add
|
|
|
|
def resolve_keys(config, tasks):
|
|
|
|
for task in tasks:
|
|
|
|
resolve_keyed_by(
|
|
|
|
task,
|
|
|
|
"treeherder.job-symbol",
|
|
|
|
item_name=task["name"],
|
|
|
|
**{
|
2022-03-11 23:23:38 +00:00
|
|
|
"build-type": task["attributes"]["build-type"],
|
|
|
|
"level": config.params["level"],
|
2019-11-26 15:20:35 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
yield task
|
|
|
|
|
|
|
|
|
2019-09-24 10:52:05 +00:00
|
|
|
@transforms.add
|
|
|
|
def build_upstream_artifacts(config, tasks):
|
|
|
|
for task in tasks:
|
2019-12-05 04:14:58 +00:00
|
|
|
worker_definition = {
|
|
|
|
"upstream-artifacts": [],
|
|
|
|
}
|
|
|
|
|
2021-04-22 19:34:51 +00:00
|
|
|
if "artifact_map" in task["attributes"]:
|
|
|
|
# Beetmover tasks use declarative artifacts.
|
|
|
|
locale = task["attributes"].get("locale")
|
|
|
|
build_type = task["attributes"]["build-type"]
|
2022-03-11 23:23:38 +00:00
|
|
|
worker_definition[
|
|
|
|
"upstream-artifacts"
|
|
|
|
] = generate_beetmover_upstream_artifacts(config, task, build_type, locale)
|
2021-04-22 19:34:51 +00:00
|
|
|
else:
|
|
|
|
for dep in _get_all_deps(task).values():
|
2022-03-11 23:23:38 +00:00
|
|
|
paths = sorted(
|
|
|
|
[
|
|
|
|
apk_metadata["name"]
|
|
|
|
for apk_metadata in dep.attributes.get("apks", {}).values()
|
|
|
|
]
|
|
|
|
)
|
2021-04-22 19:34:51 +00:00
|
|
|
if paths:
|
2022-03-11 23:23:38 +00:00
|
|
|
worker_definition["upstream-artifacts"].append(
|
|
|
|
{
|
|
|
|
"taskId": {"task-reference": "<{}>".format(dep.kind)},
|
|
|
|
"taskType": dep.kind,
|
|
|
|
"paths": paths,
|
|
|
|
}
|
|
|
|
)
|
2021-04-22 19:34:51 +00:00
|
|
|
|
|
|
|
task.setdefault("worker", {}).update(worker_definition)
|
2019-09-24 10:52:05 +00:00
|
|
|
yield task
|
|
|
|
|
|
|
|
|
|
|
|
@transforms.add
|
|
|
|
def build_treeherder_definition(config, tasks):
|
|
|
|
for task in tasks:
|
|
|
|
dep = task.pop("primary-dependency")
|
|
|
|
|
|
|
|
task.setdefault("treeherder", {}).update(inherit_treeherder_from_dep(task, dep))
|
|
|
|
job_group = dep.task["extra"]["treeherder"].get("groupSymbol", "?")
|
|
|
|
job_symbol = task["treeherder"].pop("job-symbol")
|
|
|
|
full_symbol = join_symbol(job_group, job_symbol)
|
|
|
|
task["treeherder"]["symbol"] = full_symbol
|
|
|
|
|
|
|
|
yield task
|
2019-12-05 04:14:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
@transforms.add
|
|
|
|
def remove_dependent_tasks(config, tasks):
|
|
|
|
for task in tasks:
|
|
|
|
try:
|
|
|
|
del task["dependent-tasks"]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
yield task
|