Check only files checked into Git

We're only interested in files that are committed and pushed to be
included in Mbed TLS, not in any other files that may be lying around.
So ask git for the list of file names.

This script is primarily intended to run on the CI, and there it runs
on a fresh Git checkout plus potentially some other checkouts or
leftovers from a previous part of the CI job. It should also run
reasonably well on developer machines, where there may be various
additional files. In both cases, git is available.

Ad hoc directory exclusions are no longer needed.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2020-05-10 17:18:06 +02:00
parent ffaef81586
commit ce5d854dca

View File

@ -15,6 +15,7 @@ import argparse
import logging import logging
import codecs import codecs
import re import re
import subprocess
import sys import sys
@ -262,14 +263,6 @@ class IntegrityChecker:
self.check_repo_path() self.check_repo_path()
self.logger = None self.logger = None
self.setup_logger(log_file) self.setup_logger(log_file)
self.excluded_directories = [
'.git',
'mbed-os',
]
self.excluded_paths = list(map(os.path.normpath, [
'cov-int',
'examples',
]))
self.issues_to_check = [ self.issues_to_check = [
PermissionIssueTracker(), PermissionIssueTracker(),
EndOfFileNewlineIssueTracker(), EndOfFileNewlineIssueTracker(),
@ -296,21 +289,22 @@ class IntegrityChecker:
console = logging.StreamHandler() console = logging.StreamHandler()
self.logger.addHandler(console) self.logger.addHandler(console)
def prune_branch(self, root, d): @staticmethod
if d in self.excluded_directories: def collect_files():
return True bytes_output = subprocess.check_output(['git', 'ls-files', '-z'])
if os.path.normpath(os.path.join(root, d)) in self.excluded_paths: bytes_filepaths = bytes_output.split(b'\0')[:-1]
return True ascii_filepaths = map(lambda fp: fp.decode('ascii'), bytes_filepaths)
return False # Prepend './' to files in the top-level directory so that
# something like `'/Makefile' in fp` matches in the top-level
# directory as well as in subdirectories.
return [fp if os.path.dirname(fp) else os.path.join(os.curdir, fp)
for fp in ascii_filepaths]
def check_files(self): def check_files(self):
for root, dirs, files in os.walk("."): for issue_to_check in self.issues_to_check:
dirs[:] = sorted(d for d in dirs if not self.prune_branch(root, d)) for filepath in self.collect_files():
for filename in sorted(files): if issue_to_check.should_check_file(filepath):
filepath = os.path.join(root, filename) issue_to_check.check_file_for_issue(filepath)
for issue_to_check in self.issues_to_check:
if issue_to_check.should_check_file(filepath):
issue_to_check.check_file_for_issue(filepath)
def output_issues(self): def output_issues(self):
integrity_return_code = 0 integrity_return_code = 0