diff options
author | Mukilan Thiyagarajan <mukilan@igalia.com> | 2024-06-18 13:09:38 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-18 07:39:38 +0000 |
commit | 42b09d483fbcc79345844d34b88b3ff4ae7a9735 (patch) | |
tree | 4eff18dafc0e638490ee212fe82079f374fb6e31 | |
parent | 57b64d8123535858f96796602906b4d02c7d4e4a (diff) | |
download | servo-42b09d483fbcc79345844d34b88b3ff4ae7a9735.tar.gz servo-42b09d483fbcc79345844d34b88b3ff4ae7a9735.zip |
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 <mukilan@igalia.com>
-rw-r--r-- | python/tidy/tidy.py | 23 | ||||
-rw-r--r-- | 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", |