summaryrefslogtreecommitdiffstats
path: root/comm/taskcluster/comm_taskgraph/loader
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /comm/taskcluster/comm_taskgraph/loader
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'comm/taskcluster/comm_taskgraph/loader')
-rw-r--r--comm/taskcluster/comm_taskgraph/loader/__init__.py3
-rw-r--r--comm/taskcluster/comm_taskgraph/loader/merge.py29
-rw-r--r--comm/taskcluster/comm_taskgraph/loader/reference.py93
3 files changed, 125 insertions, 0 deletions
diff --git a/comm/taskcluster/comm_taskgraph/loader/__init__.py b/comm/taskcluster/comm_taskgraph/loader/__init__.py
new file mode 100644
index 0000000000..6fbe8159b2
--- /dev/null
+++ b/comm/taskcluster/comm_taskgraph/loader/__init__.py
@@ -0,0 +1,3 @@
+# 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/.
diff --git a/comm/taskcluster/comm_taskgraph/loader/merge.py b/comm/taskcluster/comm_taskgraph/loader/merge.py
new file mode 100644
index 0000000000..00b600cd0d
--- /dev/null
+++ b/comm/taskcluster/comm_taskgraph/loader/merge.py
@@ -0,0 +1,29 @@
+# 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 gecko_taskgraph.loader.transform import loader as transform_loader
+
+from comm_taskgraph.loader.reference import loader as reference_loader
+
+
+def loader(kind, path, config, params, loaded_tasks):
+ """
+ Look up jobs via reference loader at reference-base-path using the list
+ reference-jobs-from, followed by jobs-from.
+
+ This loader has been tested with "fetch" jobs successfully. Anything else
+ is likely to have bugs.
+ """
+ # Make a copy of config for reference_loader. Use pop here to remove the
+ # fields that aren't used by the transform loader
+ reference_config = {
+ "kind-dependencies": config.get("kind-dependencies", None),
+ "reference-base-path": config.pop("reference-base-path"),
+ "reference-jobs": config.pop("reference-jobs", None),
+ }
+ for job in reference_loader(kind, path, reference_config, params, loaded_tasks):
+ yield job
+
+ for job in transform_loader(kind, path, config, params, loaded_tasks):
+ yield job
diff --git a/comm/taskcluster/comm_taskgraph/loader/reference.py b/comm/taskcluster/comm_taskgraph/loader/reference.py
new file mode 100644
index 0000000000..cb4d8f0565
--- /dev/null
+++ b/comm/taskcluster/comm_taskgraph/loader/reference.py
@@ -0,0 +1,93 @@
+# 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/.
+
+import logging
+import os
+
+from taskgraph.util.python_path import find_object
+from taskgraph.util.schema import resolve_keyed_by
+from taskgraph.util.yaml import load_yaml
+
+logger = logging.getLogger(__name__)
+
+
+def _get_aliases(kind, job, project):
+ aliases = {job["name"]}
+
+ if kind == "toolchain":
+ if job["run"].get("toolchain-alias"):
+ resolve_keyed_by(
+ job["run"],
+ "toolchain-alias",
+ item_name=f"{kind}-{job['name']}",
+ project=project,
+ )
+ aliaslist = job["run"].get("toolchain-alias")
+ if aliaslist is not None:
+ if isinstance(aliaslist, str):
+ aliaslist = [aliaslist]
+ for alias in aliaslist:
+ aliases.add(alias)
+
+ return aliases
+
+
+def _expand_aliases(kind, inputs, project):
+ """Given the list of all "reference-jobs" pulled in from upstream, return a
+ set with all job names and aliases.
+ For example "linux64-clang" is an alias of "linux64-clang-13", and both
+ of those names will be included in the returned set."""
+ rv = set()
+ for input_job in inputs:
+ for alias in _get_aliases(kind, input_job, project):
+ rv.add(alias)
+ return rv
+
+
+def _get_loader(path, config):
+ try:
+ _loader = config["loader"]
+ except KeyError:
+ raise KeyError("{!r} does not define `loader`".format(path))
+ return find_object(_loader)
+
+
+def loader(kind, path, config, params, loaded_tasks):
+ """
+ Loads selected jobs from a different taskgraph hierarchy.
+
+ This loads jobs of the given kind from the taskgraph rooted at `base-path`,
+ and includes all the jobs with names or aliases matching the names in the
+ `jobs` key.
+ """
+ base_path = config.pop("reference-base-path")
+ sub_path = os.path.join(base_path, kind)
+
+ logger.debug("Reference loader: load tasks from {}".format(sub_path))
+ sub_config = load_yaml(sub_path, "kind.yml")
+ _loader = _get_loader(sub_path, sub_config)
+ inputs = _loader(kind, sub_path, sub_config, params, loaded_tasks)
+
+ jobs = config.pop("reference-jobs", None)
+
+ config.update(sub_config)
+ project = params["project"]
+
+ if jobs is not None:
+ jobs = set(jobs)
+
+ found_reference_jobs = [job for job in inputs if (_get_aliases(kind, job, project) & jobs)]
+
+ # Check for jobs listed as a reference job in Thunderbird's config
+ # that do not exist in upstream.
+ reference_alias_names = _expand_aliases(kind, found_reference_jobs, project)
+ if reference_alias_names >= jobs:
+ return found_reference_jobs
+ else:
+ missing_jobs = jobs - reference_alias_names
+ raise Exception(
+ "Reference jobs not found in kind {}: {}".format(kind, ", ".join(missing_jobs))
+ )
+ else:
+ return inputs