diff --git a/src/taskgraph/util/hash.py b/src/taskgraph/util/hash.py index 65bf51b7e..66e3bd952 100644 --- a/src/taskgraph/util/hash.py +++ b/src/taskgraph/util/hash.py @@ -38,20 +38,22 @@ def hash_paths(base_path, patterns): found.update(matches) else: raise Exception(f"{pattern} did not match anything") - for path in sorted(found): - h.update( - f"{hash_path(mozpath.abspath(mozpath.join(base_path, path)))} {mozpath.normsep(path)}\n".encode() - ) + for abs_path, path in sorted(found): + h.update(f"{hash_path(abs_path)} {mozpath.normsep(path)}\n".encode()) return h.hexdigest() @functools.lru_cache(maxsize=None) def _find_matching_files(base_path, pattern): - files = _get_all_files(base_path) - return [path for path in files if mozpath.match(path, pattern)] + repo = get_repository(os.getcwd()) + files = _get_all_files(base_path, repo) + return [ + (mozpath.join(repo.path, path), path) + for path in files + if mozpath.match(path, pattern) + ] @functools.lru_cache(maxsize=None) -def _get_all_files(base_path): - repo = get_repository(os.getcwd()) +def _get_all_files(base_path, repo): return repo.get_tracked_files(base_path) diff --git a/test/test_transforms_run_toolchain.py b/test/test_transforms_run_toolchain.py index b42d08d67..6aaffaaa6 100644 --- a/test/test_transforms_run_toolchain.py +++ b/test/test_transforms_run_toolchain.py @@ -2,12 +2,14 @@ Tests for the 'toolchain' transforms. """ +import os.path from pprint import pprint import pytest from taskgraph.transforms.run import make_task_description from taskgraph.util.templates import merge +from taskgraph.util.vcs import GitRepository TASK_DEFAULTS = { "description": "fake description", @@ -33,14 +35,25 @@ def run_task_using(mocker, run_transform): "taskcluster/scripts/toolchain/run.sh", "taskcluster/scripts/toolchain/run.ps1", ] + # fake a repository during the test, which is needed for `_get_all_files` to + # work correctly + mocker.patch( + "taskgraph.util.hash.get_repository", new=lambda path: GitRepository(path) + ) def inner(task): task = merge(TASK_DEFAULTS, task) m = mocker.patch( "taskgraph.transforms.run.toolchain.configure_taskdesc_for_run" ) - run_transform(make_task_description, task) - return m.call_args[0] + repo_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), "data")) + cwd = os.getcwd() + try: + os.chdir(repo_dir) + run_transform(make_task_description, task) + return m.call_args[0] + finally: + os.chdir(cwd) return inner