From 42b09d483fbcc79345844d34b88b3ff4ae7a9735 Mon Sep 17 00:00:00 2001 From: Mukilan Thiyagarajan Date: Tue, 18 Jun 2024 13:09:38 +0530 Subject: mach: fix test-tidy to not skip `Cargo.lock` (#32540) PR #32465 broke the lint because it initializes FileList with a file name (./Cargo.lock). This causes it to always return an empty list when the `only_changed_files` parameter is `False` since `os.walk` requires a directory and not a file. Fixes #32530. Signed-off-by: Mukilan Thiyagarajan --- python/tidy/tidy.py | 23 ++++++++++++++--------- servo-tidy.toml | 1 + 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/python/tidy/tidy.py b/python/tidy/tidy.py index e4095b15ed1..2129cd05114 100644 --- a/python/tidy/tidy.py +++ b/python/tidy/tidy.py @@ -130,6 +130,18 @@ def progress_wrapper(iterator): yield thing +def git_changes_since_last_merge(path): + args = ["git", "log", "-n1", "--committer", "noreply@github.com", "--format=%H"] + last_merge = subprocess.check_output(args, universal_newlines=True).strip() + if not last_merge: + return + + args = ["git", "diff", "--name-only", last_merge, path] + file_list = normilize_paths(subprocess.check_output(args, universal_newlines=True).splitlines()) + + return file_list + + class FileList(object): def __init__(self, directory, only_changed_files=False, exclude_dirs=[], progress=True): self.directory = directory @@ -146,14 +158,7 @@ class FileList(object): yield os.path.join(root, f) def _git_changed_files(self): - args = ["git", "log", "-n1", "--committer", "noreply@github.com", "--format=%H"] - last_merge = subprocess.check_output(args, universal_newlines=True).strip() - if not last_merge: - return - - args = ["git", "diff", "--name-only", last_merge, self.directory] - file_list = normilize_paths(subprocess.check_output(args, universal_newlines=True).splitlines()) - + file_list = git_changes_since_last_merge(self.directory) for f in file_list: if not any(os.path.join('.', os.path.dirname(f)).startswith(path) for path in self.excluded): yield os.path.join('.', f) @@ -328,7 +333,7 @@ def check_flake8(file_name, contents): def check_cargo_lock_file(only_changed_files: bool): - if not list(FileList("./Cargo.lock", only_changed_files=only_changed_files, progress=False)): + if only_changed_files and not list(git_changes_since_last_merge("./Cargo.lock")): print("\r ➤ Skipping `Cargo.lock` lint checks, because it is unchanged.") return diff --git a/servo-tidy.toml b/servo-tidy.toml index 46db6d037ed..8249772b143 100644 --- a/servo-tidy.toml +++ b/servo-tidy.toml @@ -21,6 +21,7 @@ rand = [ # Ignored packages with duplicated versions packages = [ "bitflags", + "cfg_aliases", "cookie", "futures", "libloading", -- cgit v1.2.3