• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
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
8import multiprocessing
9import os
10import re
11import subprocess
12import sys
13
14'''
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'''
20
21ignore = 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    ]))
64
65
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):
69    cmd = ['c++', '--std=c++14', '-I.', '-o', '/dev/null', '-c', '-x', 'c++', '-']
70    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
79
80#     for h in headers:
81#         compile_header(h)
82# ...Except use a multiprocessing pool.
83# Exit at first error.
84def compile_headers(headers):
85    class N: good = True
86    # N.good is a global scoped to this function to make a print_and_exit_if() a closure
87    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()
93    for path in headers:
94        assert os.path.exists(path)
95        pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if)
96    pool.close()
97    pool.join()
98    if N.good:
99        sys.stdout.write('all good :)\n')
100    else:
101        exit(1)
102
103
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()
112                 if path.endswith('.h') and not ignore.match(path)]
113    compile_headers(paths)
114
115
116if __name__ == '__main__':
117    main(sys.argv)
118
119