tools/check-headers-self-sufficient: optionally test one file at a time
authorHal Canary <halcanary@google.com>
Wed, 5 Apr 2017 19:12:45 +0000 (15:12 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Fri, 14 Apr 2017 15:37:07 +0000 (15:37 +0000)
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>

tools/check-headers-self-sufficient

index 0513aeff47455257ac32e6cf421eb1963fcf7acf..294132ecff87cec0d0ad3c36af2a85fdb0585b25 100755 (executable)
@@ -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)