blob: 8ecb76b78135074ed3b5e4ea3c18f4bd26854247 [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/.*',
26 r'include/core/SkPostConfig\.h',
27 r'include/gpu/mtl/.*',
28 r'include/gpu/vk/.*',
29 r'include/ports/SkFontMgr_android\.h',
30 r'include/ports/SkFontMgr_fontconfig\.h',
31 r'include/ports/SkFontMgr_fuchsia\.h',
32 r'include/ports/SkTypeface_win\.h',
33 r'include/private/.*_impl\.h',
34 r'include/private/.*_neon\.h',
35 r'include/private/.*_sse\.h',
36 r'include/third_party/vulkan/.*',
37 r'include/utils/mac/SkCGUtils\.h',
38 r'include/views/SkOSWindow_.*\.h',
39 r'modules/.*',
40 r'platform_tools/.*',
41 r'src/c/sk_c_from_to\.h',
42 r'src/core/.*Template\.h',
43 r'src/core/SkBitmapProcState_.*\.h',
44 r'src/core/SkLinearBitmapPipeline\.h',
45 r'src/core/SkLinearBitmapPipeline_.*\.h',
46 r'src/gpu/mtl/.*',
47 r'src/gpu/vk/.*',
48 r'src/opts/.*_SSE2\.h',
49 r'src/opts/.*_SSSE3\.h',
50 r'src/opts/.*_neon\.h',
51 r'src/opts/.*_sse\.h',
52 r'src/opts/Sk4px_.*\.h',
53 r'src/ports/.*',
54 r'src/utils/.*_win\.h',
55 r'src/utils/win/.*',
56 r'src/views/.*',
57 r'third_party/.*',
58 r'tools/fiddle/.*',
59 r'tools/gpu/vk/.*',
60 r'tools/mdbviz/.*',
61 r'tools/sk_app/.*',
62 r'tools/viewer/.*',
63 ]))
Hal Canary271d4952017-02-15 11:21:32 -050064
Hal Canary271d4952017-02-15 11:21:32 -050065
66# test header for self-sufficiency and idempotency.
67# Returns a string containing errors, or None iff there are no errors.
68def compile_header(header):
Hal Canary02eefbe2019-06-26 13:54:14 -040069 cmd = ['c++', '--std=c++14', '-I.', '-o', '/dev/null', '-c', '-x', 'c++', '-']
Hal Canary271d4952017-02-15 11:21:32 -050070 proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
71 stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
72 proc.stdin.write('#include "%s"\n#include "%s"\n' % (header, header))
73 proc.stdin.close()
74 errors = proc.stdout.read().strip()
75 if proc.wait() != 0 or len(errors) > 0:
76 return '\n\033[7m ERROR: %s \033[0m\n%s\n\n' % (header, errors)
77 return None
78
Hal Canary02eefbe2019-06-26 13:54:14 -040079
Hal Canaryd64756e2017-04-05 15:12:45 -040080# for h in headers:
81# compile_header(h)
82# ...Except use a multiprocessing pool.
83# Exit at first error.
84def compile_headers(headers):
Hal Canary271d4952017-02-15 11:21:32 -050085 class N: good = True
Hal Canaryd64756e2017-04-05 15:12:45 -040086 # 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 -050087 pool = multiprocessing.Pool()
88 def print_and_exit_if(r):
89 if r is not None:
90 sys.stdout.write(r)
91 N.good = False
92 pool.terminate()
Hal Canaryd64756e2017-04-05 15:12:45 -040093 for path in headers:
94 assert os.path.exists(path)
95 pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if)
Hal Canary271d4952017-02-15 11:21:32 -050096 pool.close()
97 pool.join()
98 if N.good:
99 sys.stdout.write('all good :)\n')
100 else:
101 exit(1)
102
Hal Canaryd64756e2017-04-05 15:12:45 -0400103
104def main(argv):
105 skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
106 if len(argv) > 1:
107 paths = [os.path.relpath(os.path.abspath(arg), skia_dir) for arg in argv[1:]]
108 os.chdir(skia_dir)
109 else:
110 os.chdir(skia_dir)
111 paths = [path for path in subprocess.check_output(['git', 'ls-files']).splitlines()
Hal Canary02eefbe2019-06-26 13:54:14 -0400112 if path.endswith('.h') and not ignore.match(path)]
Hal Canaryd64756e2017-04-05 15:12:45 -0400113 compile_headers(paths)
114
115
Hal Canary271d4952017-02-15 11:21:32 -0500116if __name__ == '__main__':
Hal Canaryd64756e2017-04-05 15:12:45 -0400117 main(sys.argv)
Hal Canary271d4952017-02-15 11:21:32 -0500118