diff options
author | Hal Canary <halcanary@google.com> | 2017-04-05 15:12:45 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-14 15:37:07 +0000 |
commit | d64756e66e65f1a8ec500819d22bbdd1c96fa28d (patch) | |
tree | e6434e4bad8390335e7dfe5fa58259e62bbdbf1f | |
parent | 8530211fbfd31922b55122d7bc7b28670729037d (diff) |
tools/check-headers-self-sufficient: optionally test one file at a time
Change-Id: Ie7703e9b6abb7229cd8c2dbcdf305fa4240f416c
Reviewed-on: https://skia-review.googlesource.com/11385
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
-rwxr-xr-x | tools/check-headers-self-sufficient | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/tools/check-headers-self-sufficient b/tools/check-headers-self-sufficient index 0513aeff47..294132ecff 100755 --- a/tools/check-headers-self-sufficient +++ b/tools/check-headers-self-sufficient @@ -11,6 +11,12 @@ import os import subprocess import sys +''' +If called with arguments, this script will verify that those headers are +self-sufficient and idempotent. + +Otherwise, test all checked-in headers except for those in the ignore list. +''' public_header_args = [ '-Iinclude/core', @@ -130,20 +136,22 @@ def compile_header(header): return '\n\033[7m ERROR: %s \033[0m\n%s\n\n' % (header, errors) return None -def main(): +# for h in headers: +# compile_header(h) +# ...Except use a multiprocessing pool. +# Exit at first error. +def compile_headers(headers): class N: good = True - # N.good is a global scoped to main() to make a print_and_exit_if() a closure + # N.good is a global scoped to this function to make a print_and_exit_if() a closure pool = multiprocessing.Pool() def print_and_exit_if(r): if r is not None: sys.stdout.write(r) N.good = False pool.terminate() - - os.chdir(os.path.join(os.path.dirname(__file__), os.pardir)) - for path in subprocess.check_output(['git', 'ls-files']).splitlines(): - if path.endswith('.h') and not any(fnmatch.fnmatch(path, pattern) for pattern in ignore): - pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if) + for path in headers: + assert os.path.exists(path) + pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if) pool.close() pool.join() if N.good: @@ -151,6 +159,20 @@ def main(): else: exit(1) + +def main(argv): + skia_dir = os.path.join(os.path.dirname(__file__), os.pardir) + if len(argv) > 1: + paths = [os.path.relpath(os.path.abspath(arg), skia_dir) for arg in argv[1:]] + os.chdir(skia_dir) + else: + os.chdir(skia_dir) + paths = [path for path in subprocess.check_output(['git', 'ls-files']).splitlines() + if path.endswith('.h') + and not any(fnmatch.fnmatch(path, pattern) for pattern in ignore)] + compile_headers(paths) + + if __name__ == '__main__': - main() + main(sys.argv) |