Skip to content

Commit

Permalink
mach: fix test-tidy to not skip Cargo.lock (#32540)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mukilan committed Jun 18, 2024
1 parent 57b64d8 commit 42b09d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
23 changes: 14 additions & 9 deletions python/tidy/tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -146,14 +158,7 @@ def _default_walk(self):
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)
Expand Down Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions servo-tidy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rand = [
# Ignored packages with duplicated versions
packages = [
"bitflags",
"cfg_aliases",
"cookie",
"futures",
"libloading",
Expand Down

0 comments on commit 42b09d4

Please sign in to comment.