Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/taskgraph/util/hash.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
17 changes: 15 additions & 2 deletions test/test_transforms_run_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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

Expand Down
Loading