summaryrefslogtreecommitdiffstats
path: root/comm/taskcluster/comm_taskgraph/util
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/util
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/util')
-rw-r--r--comm/taskcluster/comm_taskgraph/util/__init__.py15
-rw-r--r--comm/taskcluster/comm_taskgraph/util/docker.py25
-rw-r--r--comm/taskcluster/comm_taskgraph/util/hash.py76
3 files changed, 116 insertions, 0 deletions
diff --git a/comm/taskcluster/comm_taskgraph/util/__init__.py b/comm/taskcluster/comm_taskgraph/util/__init__.py
new file mode 100644
index 0000000000..71f5dc9cd0
--- /dev/null
+++ b/comm/taskcluster/comm_taskgraph/util/__init__.py
@@ -0,0 +1,15 @@
+# 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/.
+
+
+def strip_comm_prefix(relpath):
+ """
+ Returns relpath with 'comm/' prefix removed.
+ :param string relpath: relative path
+ :return string: stripped path
+ """
+ if relpath[:5] == "comm/":
+ return relpath[5:]
+ else:
+ return relpath
diff --git a/comm/taskcluster/comm_taskgraph/util/docker.py b/comm/taskcluster/comm_taskgraph/util/docker.py
new file mode 100644
index 0000000000..07971f3f28
--- /dev/null
+++ b/comm/taskcluster/comm_taskgraph/util/docker.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# 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 gecko_taskgraph.util import docker as utildocker
+
+from .. import COMM
+
+logger = logging.getLogger(__name__)
+
+COMM_IMAGE_DIR = os.path.join(COMM, "taskcluster", "docker")
+
+
+def register():
+ logger.info("Registering comm docker image definition path.")
+ utildocker.image_paths.register(
+ "comm/taskcluster/ci/docker-image/docker-image.yml", COMM_IMAGE_DIR
+ )
+
+
+register()
diff --git a/comm/taskcluster/comm_taskgraph/util/hash.py b/comm/taskcluster/comm_taskgraph/util/hash.py
new file mode 100644
index 0000000000..d372a0192a
--- /dev/null
+++ b/comm/taskcluster/comm_taskgraph/util/hash.py
@@ -0,0 +1,76 @@
+# 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 hashlib
+
+import taskgraph.util.path as util_path
+
+from gecko_taskgraph.util.hash import get_file_finder, hash_path
+
+
+def split_patterns_list(patterns):
+ """
+ Give a list of path patterns and return two lists. rv[0] corresponds to files from the
+ GECKO repository, rv[1] corresponds to COMM.
+ The pattern list for the COMM repository will have *not* the 'comm/' prefix stripped.
+ """
+ return [
+ [p for p in patterns if not p.startswith("comm/")],
+ [p for p in patterns if p.startswith("comm/")],
+ ]
+
+
+def prefix_paths(prefix, paths):
+ """
+ Prepend a prefix to a list of paths.
+ """
+ return [util_path.join(prefix, p) for p in paths]
+
+
+def process_found(found_gen, prefix=None):
+ """
+ Transform the results from finder.find(pattern) into a list of files.
+ If prefix is given, prepend it to results.
+ """
+ for filename, fileobj in found_gen:
+ if prefix:
+ yield util_path.join(prefix, filename)
+ else:
+ yield filename
+
+
+def hash_paths_extended(base_path, patterns):
+ """
+ Works like gecko_taskgraph.util.hash.hash_paths, except it is able to account for Thunderbird
+ source code being part of a separate repository.
+ Two file finders are created if necessary.
+ """
+ gecko_patterns, comm_patterns = split_patterns_list(patterns)
+ gecko_finder = get_file_finder(base_path)
+ comm_finder = get_file_finder(util_path.join(base_path, "comm"))
+
+ h = hashlib.sha256()
+ files = []
+ for (patterns, finder, prefix) in [
+ (gecko_patterns, gecko_finder, None),
+ (comm_patterns, comm_finder, "comm/"),
+ ]:
+ for pattern in patterns:
+ if prefix:
+ pattern = pattern.lstrip(prefix)
+ found = list(process_found(finder.find(pattern), prefix))
+ if found:
+ files.extend(found)
+ else:
+ raise Exception("%s did not match anything" % pattern)
+ for path in sorted(files):
+ if path.endswith((".pyc", ".pyd", ".pyo")):
+ continue
+ h.update(
+ "{} {}\n".format(
+ hash_path(util_path.abspath(util_path.join(base_path, path))),
+ util_path.normsep(path),
+ ).encode("utf-8")
+ )
+ return h.hexdigest()