blob: ae4f0203aef3252dd668a4d83b528cfe15e3fca2 [file] [log] [blame]
Hal Canary271d4952017-02-15 11:21:32 -05001#!/usr/bin/env python
Hal Canary03a7f5f2017-02-10 09:06:38 -05002
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 Canary271d4952017-02-15 11:21:32 -05008import multiprocessing
9import os
Hal Canary02eefbe2019-06-26 13:54:14 -040010import re
Hal Canary271d4952017-02-15 11:21:32 -050011import subprocess
12import sys
Hal Canary03a7f5f2017-02-10 09:06:38 -050013
Hal Canaryd64756e2017-04-05 15:12:45 -040014'''
15If called with arguments, this script will verify that those headers are
16self-sufficient and idempotent.
17
18Otherwise, test all checked-in headers except for those in the ignore list.
19'''
Hal Canary03a7f5f2017-02-10 09:06:38 -050020
Hal Canary02eefbe2019-06-26 13:54:14 -040021ignore = re.compile('|'.join([
22 r'debugger/QT/.*',
23 r'example/.*',
24 r'experimental/.*',
25 r'include/config/.*',
Hal Canary02eefbe2019-06-26 13:54:14 -040026 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 Canary271d4952017-02-15 11:21:32 -050063
Hal Canary271d4952017-02-15 11:21:32 -050064
65# test header for self-sufficiency and idempotency.
66# Returns a string containing errors, or None iff there are no errors.
67def compile_header(header):
Hal Canary02eefbe2019-06-26 13:54:14 -040068 cmd = ['c++', '--std=c++14', '-I.', '-o', '/dev/null', '-c', '-x', 'c++', '-']
Hal Canary271d4952017-02-15 11:21:32 -050069 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 Canary02eefbe2019-06-26 13:54:14 -040078
Hal Canaryd64756e2017-04-05 15:12:45 -040079# for h in headers:
80# compile_header(h)
81# ...Except use a multiprocessing pool.
82# Exit at first error.
83def compile_headers(headers):
Hal Canary271d4952017-02-15 11:21:32 -050084 class N: good = True
Hal Canaryd64756e2017-04-05 15:12:45 -040085 # N.good is a global scoped to this function to make a print_and_exit_if() a closure
Hal Canary271d4952017-02-15 11:21:32 -050086 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 Canaryd64756e2017-04-05 15:12:45 -040092 for path in headers:
93 assert os.path.exists(path)
94 pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if)
Hal Canary271d4952017-02-15 11:21:32 -050095 pool.close()
96 pool.join()
97 if N.good:
98 sys.stdout.write('all good :)\n')
99 else:
100 exit(1)
101
Hal Canaryd64756e2017-04-05 15:12:45 -0400102
103def 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 Canary02eefbe2019-06-26 13:54:14 -0400111 if path.endswith('.h') and not ignore.match(path)]
Hal Canaryd64756e2017-04-05 15:12:45 -0400112 compile_headers(paths)
113
114
Hal Canary271d4952017-02-15 11:21:32 -0500115if __name__ == '__main__':
Hal Canaryd64756e2017-04-05 15:12:45 -0400116 main(sys.argv)
Hal Canary271d4952017-02-15 11:21:32 -0500117