From: Bobby R. Bruce Date: Thu, 28 Jan 2021 05:44:31 +0000 (-0800) Subject: util,python: Fix Pre-commit hooks to ignore non-source files X-Git-Tag: develop-gem5-snapshot~169 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=86222736e60b4e2783dcf6c7c0e0963066ec3729;p=gem5.git util,python: Fix Pre-commit hooks to ignore non-source files Previously if binary blobs were modified the pre-commit hook attempted to run style-checks on the binary, causing an error when attempting to decode to utf-8. This commit runs a check on each file to ensure it has a valid source-code extension prior to running style checks. If a file does not have a valid extension style checks are not run. Change-Id: Id1263cac0d6c190ad1a3d67720b3f373e0e42234 Issue-on: https://gem5.atlassian.net/browse/GEM5-903 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39795 Reviewed-by: Jason Lowe-Power Maintainer: Jason Lowe-Power Tested-by: kokoro --- diff --git a/util/style/style.py b/util/style/style.py index e765a92da..1a5e94bdc 100644 --- a/util/style/style.py +++ b/util/style/style.py @@ -86,6 +86,15 @@ def _re_ignore(expr): return rex.match(fname) return match_re +def _re_only(expr): + """Helper function to create regular expressions to only keep + matcher functions""" + + rex = re.compile(expr) + def match_re(fname): + return not rex.match(fname) + return match_re + # This list contains a list of functions that are called to determine # if a file should be excluded from the style matching rules or # not. The functions are called with the file name relative to the @@ -97,11 +106,10 @@ style_ignores = [ _re_ignore("^ext/"), # Ignore test data, as they are not code _re_ignore("^tests/(?:quick|long)/"), - # Ignore RISC-V assembly tests as they are maintained in an external - # project that does not follow the gem5 coding convention - _re_ignore("tests/test-progs/asmtest/src/riscv/"), - # Ignore RISC-V assembly dump files - _re_ignore("tests/test-progs/asmtest/dump/riscv/") + # Only include Scons files and those with extensions that suggest source + # code + _re_only("^((.*\/)?(SConscript|SConstruct)|" + ".*\.(c|h|cc|hh|cpp|hpp|py|isa|proto))$") ] def check_ignores(fname):