blob: 294132ecff87cec0d0ad3c36af2a85fdb0585b25 [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 fnmatch
9import multiprocessing
10import os
11import 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 Canary271d4952017-02-15 11:21:32 -050021public_header_args = [
22 '-Iinclude/core',
23 '-Iinclude/config',
24 '-Iinclude/android',
25 '-Iinclude/codec',
26 '-Iinclude/effects',
27 '-Iinclude/gpu',
28 '-Iinclude/gpu/gl',
29 '-Iinclude/pathops',
30 '-Iinclude/ports',
31 '-Iinclude/private',
32 '-Iinclude/svg',
33 '-Iinclude/utils',
34 '-Iinclude/utils/mac',
35 '-Iinclude/views',
36]
37
38all_header_args = [
39 '-Iinclude/core',
40 '-Iinclude/config',
41 '-Iinclude/android',
42 '-Iinclude/c',
43 '-Iinclude/codec',
44 '-Iinclude/effects',
45 '-Iinclude/gpu',
46 '-Iinclude/gpu/gl',
47 '-Iinclude/pathops',
48 '-Iinclude/ports',
49 '-Iinclude/private',
50 '-Iinclude/svg',
51 '-Iinclude/utils',
52 '-Iinclude/utils/mac',
53 '-Iinclude/views',
54 '-Isrc/codec',
55 '-Isrc/core',
56 '-Isrc/effects',
57 '-Isrc/effects/gradients',
58 '-Isrc/fonts',
59 '-Isrc/gpu',
60 '-Isrc/image',
61 '-Isrc/images',
62 '-Isrc/lazy',
63 '-Isrc/opts',
64 '-Isrc/pathops',
65 '-Isrc/ports',
66 '-Isrc/sfnt',
67 '-Isrc/sksl',
68 '-Isrc/utils',
69 '-Isrc/utils/win',
70 '-Isrc/xml',
71 '-Igm',
72 '-Itests',
73 '-Itools',
74 '-Itools/debugger',
75 '-Itools/flags',
76 '-Itools/gpu',
77 '-Itools/timer',
78 '-Ithird_party/etc1',
79 '-Ithird_party/externals/jsoncpp/include',
80 '-Ithird_party/externals/libjpeg-turbo',
81 '-Ithird_party/externals/sfntly/cpp/src',
82 '-Ithird_party/externals/zlib',
83 '-Ithird_party/gif',
84]
85
86ignore = [
87 '*/lex.*.h',
88 '*/osmesa_wrapper.h',
89 'debugger/QT/*',
90 'example/*',
91 'experimental/*',
92 'include/config/*',
93 'include/core/SkPostConfig.h',
94 'include/gpu/vk/*',
95 'include/ports/SkFontMgr_android.h',
96 'include/ports/SkFontMgr_fontconfig.h',
97 'include/ports/SkTypeface_win.h',
98 'include/private/*_impl.h',
99 'include/utils/mac/SkCGUtils.h',
100 'include/views/SkOSWindow_*.h',
101 'src/c/sk_c_from_to.h',
102 'src/core/*Template.h',
103 'src/core/SkBitmapProcState_*.h',
104 'src/core/SkFDot6Constants.h',
105 'src/core/SkLinearBitmapPipeline.h',
106 'src/core/SkLinearBitmapPipeline_*.h',
107 'src/core/SkUnPreMultiplyPriv.h',
108 'src/gpu/vk/*.h',
109 'src/opts/*_SSE2.h',
110 'src/opts/*_SSSE3.h',
111 'src/opts/*_neon.h',
112 'src/opts/*_sse.h',
113 'src/opts/Sk4px_*.h',
114 'src/ports/*',
115 'src/utils/*_win.h',
116 'src/utils/win/*',
117 'src/views/*',
118 'third_party/*',
119 'tools/fiddle/*',
120 'tools/viewer/*',
121]
122
123# test header for self-sufficiency and idempotency.
124# Returns a string containing errors, or None iff there are no errors.
125def compile_header(header):
126 args = ([] if fnmatch.fnmatch(header, 'include/c/*') else
127 public_header_args if fnmatch.fnmatch(header, 'include/*') else
128 all_header_args)
129 cmd = ['c++', '--std=c++11'] + args + [ '-o', '/dev/null', '-c', '-x', 'c++', '-']
130 proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
131 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
132 proc.stdin.write('#include "%s"\n#include "%s"\n' % (header, header))
133 proc.stdin.close()
134 errors = proc.stdout.read().strip()
135 if proc.wait() != 0 or len(errors) > 0:
136 return '\n\033[7m ERROR: %s \033[0m\n%s\n\n' % (header, errors)
137 return None
138
Hal Canaryd64756e2017-04-05 15:12:45 -0400139# for h in headers:
140# compile_header(h)
141# ...Except use a multiprocessing pool.
142# Exit at first error.
143def compile_headers(headers):
Hal Canary271d4952017-02-15 11:21:32 -0500144 class N: good = True
Hal Canaryd64756e2017-04-05 15:12:45 -0400145 # 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 -0500146 pool = multiprocessing.Pool()
147 def print_and_exit_if(r):
148 if r is not None:
149 sys.stdout.write(r)
150 N.good = False
151 pool.terminate()
Hal Canaryd64756e2017-04-05 15:12:45 -0400152 for path in headers:
153 assert os.path.exists(path)
154 pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if)
Hal Canary271d4952017-02-15 11:21:32 -0500155 pool.close()
156 pool.join()
157 if N.good:
158 sys.stdout.write('all good :)\n')
159 else:
160 exit(1)
161
Hal Canaryd64756e2017-04-05 15:12:45 -0400162
163def main(argv):
164 skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
165 if len(argv) > 1:
166 paths = [os.path.relpath(os.path.abspath(arg), skia_dir) for arg in argv[1:]]
167 os.chdir(skia_dir)
168 else:
169 os.chdir(skia_dir)
170 paths = [path for path in subprocess.check_output(['git', 'ls-files']).splitlines()
171 if path.endswith('.h')
172 and not any(fnmatch.fnmatch(path, pattern) for pattern in ignore)]
173 compile_headers(paths)
174
175
Hal Canary271d4952017-02-15 11:21:32 -0500176if __name__ == '__main__':
Hal Canaryd64756e2017-04-05 15:12:45 -0400177 main(sys.argv)
Hal Canary271d4952017-02-15 11:21:32 -0500178