Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 2 | |
| 3 | # Copyright 2017 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 8 | import multiprocessing |
| 9 | import os |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 10 | import re |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 11 | import subprocess |
| 12 | import sys |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 13 | |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 14 | ''' |
| 15 | If called with arguments, this script will verify that those headers are |
| 16 | self-sufficient and idempotent. |
| 17 | |
| 18 | Otherwise, test all checked-in headers except for those in the ignore list. |
| 19 | ''' |
Hal Canary | 03a7f5f | 2017-02-10 09:06:38 -0500 | [diff] [blame] | 20 | |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 21 | ignore = re.compile('|'.join([ |
| 22 | r'debugger/QT/.*', |
| 23 | r'example/.*', |
| 24 | r'experimental/.*', |
| 25 | r'include/config/.*', |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 26 | r'include/gpu/mtl/.*', |
| 27 | r'include/gpu/vk/.*', |
| 28 | r'include/ports/SkFontMgr_android\.h', |
| 29 | r'include/ports/SkFontMgr_fontconfig\.h', |
| 30 | r'include/ports/SkFontMgr_fuchsia\.h', |
| 31 | r'include/ports/SkTypeface_win\.h', |
| 32 | r'include/private/.*_impl\.h', |
| 33 | r'include/private/.*_neon\.h', |
| 34 | r'include/private/.*_sse\.h', |
| 35 | r'include/third_party/vulkan/.*', |
| 36 | r'include/utils/mac/SkCGUtils\.h', |
| 37 | r'include/views/SkOSWindow_.*\.h', |
| 38 | r'modules/.*', |
| 39 | r'platform_tools/.*', |
| 40 | r'src/c/sk_c_from_to\.h', |
| 41 | r'src/core/.*Template\.h', |
| 42 | r'src/core/SkBitmapProcState_.*\.h', |
| 43 | r'src/core/SkLinearBitmapPipeline\.h', |
| 44 | r'src/core/SkLinearBitmapPipeline_.*\.h', |
| 45 | r'src/gpu/mtl/.*', |
| 46 | r'src/gpu/vk/.*', |
| 47 | r'src/opts/.*_SSE2\.h', |
| 48 | r'src/opts/.*_SSSE3\.h', |
| 49 | r'src/opts/.*_neon\.h', |
| 50 | r'src/opts/.*_sse\.h', |
| 51 | r'src/opts/Sk4px_.*\.h', |
| 52 | r'src/ports/.*', |
| 53 | r'src/utils/.*_win\.h', |
| 54 | r'src/utils/win/.*', |
| 55 | r'src/views/.*', |
| 56 | r'third_party/.*', |
| 57 | r'tools/fiddle/.*', |
| 58 | r'tools/gpu/vk/.*', |
| 59 | r'tools/mdbviz/.*', |
| 60 | r'tools/sk_app/.*', |
| 61 | r'tools/viewer/.*', |
| 62 | ])) |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 63 | |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 64 | |
| 65 | # test header for self-sufficiency and idempotency. |
| 66 | # Returns a string containing errors, or None iff there are no errors. |
| 67 | def compile_header(header): |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 68 | cmd = ['c++', '--std=c++14', '-I.', '-o', '/dev/null', '-c', '-x', 'c++', '-'] |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 69 | proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, |
| 70 | stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 71 | proc.stdin.write('#include "%s"\n#include "%s"\n' % (header, header)) |
| 72 | proc.stdin.close() |
| 73 | errors = proc.stdout.read().strip() |
| 74 | if proc.wait() != 0 or len(errors) > 0: |
| 75 | return '\n\033[7m ERROR: %s \033[0m\n%s\n\n' % (header, errors) |
| 76 | return None |
| 77 | |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 78 | |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 79 | # for h in headers: |
| 80 | # compile_header(h) |
| 81 | # ...Except use a multiprocessing pool. |
| 82 | # Exit at first error. |
| 83 | def compile_headers(headers): |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 84 | class N: good = True |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 85 | # N.good is a global scoped to this function to make a print_and_exit_if() a closure |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 86 | pool = multiprocessing.Pool() |
| 87 | def print_and_exit_if(r): |
| 88 | if r is not None: |
| 89 | sys.stdout.write(r) |
| 90 | N.good = False |
| 91 | pool.terminate() |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 92 | for path in headers: |
| 93 | assert os.path.exists(path) |
| 94 | pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if) |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 95 | pool.close() |
| 96 | pool.join() |
| 97 | if N.good: |
| 98 | sys.stdout.write('all good :)\n') |
| 99 | else: |
| 100 | exit(1) |
| 101 | |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 102 | |
| 103 | def main(argv): |
| 104 | skia_dir = os.path.join(os.path.dirname(__file__), os.pardir) |
| 105 | if len(argv) > 1: |
| 106 | paths = [os.path.relpath(os.path.abspath(arg), skia_dir) for arg in argv[1:]] |
| 107 | os.chdir(skia_dir) |
| 108 | else: |
| 109 | os.chdir(skia_dir) |
| 110 | paths = [path for path in subprocess.check_output(['git', 'ls-files']).splitlines() |
Hal Canary | 02eefbe | 2019-06-26 13:54:14 -0400 | [diff] [blame] | 111 | if path.endswith('.h') and not ignore.match(path)] |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 112 | compile_headers(paths) |
| 113 | |
| 114 | |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 115 | if __name__ == '__main__': |
Hal Canary | d64756e | 2017-04-05 15:12:45 -0400 | [diff] [blame] | 116 | main(sys.argv) |
Hal Canary | 271d495 | 2017-02-15 11:21:32 -0500 | [diff] [blame] | 117 | |