2017-02-15 16:21:32 +00:00
|
|
|
#!/usr/bin/env python
|
2017-02-10 14:06:38 +00:00
|
|
|
|
|
|
|
# Copyright 2017 Google Inc.
|
|
|
|
#
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
2017-02-15 16:21:32 +00:00
|
|
|
import fnmatch
|
|
|
|
import multiprocessing
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2017-02-10 14:06:38 +00:00
|
|
|
|
2017-04-05 19:12:45 +00:00
|
|
|
'''
|
|
|
|
If called with arguments, this script will verify that those headers are
|
|
|
|
self-sufficient and idempotent.
|
|
|
|
|
|
|
|
Otherwise, test all checked-in headers except for those in the ignore list.
|
|
|
|
'''
|
2017-02-10 14:06:38 +00:00
|
|
|
|
2017-02-15 16:21:32 +00:00
|
|
|
public_header_args = [
|
|
|
|
'-Iinclude/core',
|
|
|
|
'-Iinclude/config',
|
|
|
|
'-Iinclude/android',
|
|
|
|
'-Iinclude/codec',
|
|
|
|
'-Iinclude/effects',
|
|
|
|
'-Iinclude/gpu',
|
|
|
|
'-Iinclude/gpu/gl',
|
|
|
|
'-Iinclude/pathops',
|
|
|
|
'-Iinclude/ports',
|
|
|
|
'-Iinclude/private',
|
|
|
|
'-Iinclude/svg',
|
|
|
|
'-Iinclude/utils',
|
|
|
|
'-Iinclude/utils/mac',
|
|
|
|
'-Iinclude/views',
|
2017-05-04 18:15:40 +00:00
|
|
|
'-Ithird_party/vulkan',
|
2017-02-15 16:21:32 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
all_header_args = [
|
|
|
|
'-Iinclude/core',
|
|
|
|
'-Iinclude/config',
|
|
|
|
'-Iinclude/android',
|
|
|
|
'-Iinclude/c',
|
|
|
|
'-Iinclude/codec',
|
|
|
|
'-Iinclude/effects',
|
|
|
|
'-Iinclude/gpu',
|
|
|
|
'-Iinclude/gpu/gl',
|
|
|
|
'-Iinclude/pathops',
|
|
|
|
'-Iinclude/ports',
|
|
|
|
'-Iinclude/private',
|
|
|
|
'-Iinclude/svg',
|
|
|
|
'-Iinclude/utils',
|
|
|
|
'-Iinclude/utils/mac',
|
|
|
|
'-Iinclude/views',
|
|
|
|
'-Isrc/codec',
|
|
|
|
'-Isrc/core',
|
|
|
|
'-Isrc/effects',
|
|
|
|
'-Isrc/effects/gradients',
|
|
|
|
'-Isrc/fonts',
|
|
|
|
'-Isrc/gpu',
|
|
|
|
'-Isrc/image',
|
|
|
|
'-Isrc/images',
|
|
|
|
'-Isrc/lazy',
|
|
|
|
'-Isrc/opts',
|
|
|
|
'-Isrc/pathops',
|
|
|
|
'-Isrc/ports',
|
|
|
|
'-Isrc/sfnt',
|
2017-07-03 19:11:49 +00:00
|
|
|
'-Isrc/shaders',
|
2017-02-15 16:21:32 +00:00
|
|
|
'-Isrc/sksl',
|
|
|
|
'-Isrc/utils',
|
|
|
|
'-Isrc/utils/win',
|
|
|
|
'-Isrc/xml',
|
|
|
|
'-Igm',
|
|
|
|
'-Itests',
|
|
|
|
'-Itools',
|
|
|
|
'-Itools/debugger',
|
|
|
|
'-Itools/flags',
|
|
|
|
'-Itools/gpu',
|
|
|
|
'-Itools/timer',
|
|
|
|
'-Ithird_party/externals/jsoncpp/include',
|
|
|
|
'-Ithird_party/externals/libjpeg-turbo',
|
|
|
|
'-Ithird_party/externals/sfntly/cpp/src',
|
|
|
|
'-Ithird_party/externals/zlib',
|
|
|
|
'-Ithird_party/gif',
|
2017-05-04 18:15:40 +00:00
|
|
|
'-Ithird_party/vulkan',
|
2017-02-15 16:21:32 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
ignore = [
|
|
|
|
'*/lex.*.h',
|
|
|
|
'*/osmesa_wrapper.h',
|
|
|
|
'debugger/QT/*',
|
|
|
|
'example/*',
|
|
|
|
'experimental/*',
|
|
|
|
'include/config/*',
|
|
|
|
'include/core/SkPostConfig.h',
|
2017-07-03 19:11:49 +00:00
|
|
|
'include/gpu/vk/*',
|
2017-02-15 16:21:32 +00:00
|
|
|
'include/ports/SkFontMgr_android.h',
|
|
|
|
'include/ports/SkFontMgr_fontconfig.h',
|
|
|
|
'include/ports/SkTypeface_win.h',
|
|
|
|
'include/private/*_impl.h',
|
|
|
|
'include/utils/mac/SkCGUtils.h',
|
|
|
|
'include/views/SkOSWindow_*.h',
|
|
|
|
'src/c/sk_c_from_to.h',
|
|
|
|
'src/core/*Template.h',
|
|
|
|
'src/core/SkBitmapProcState_*.h',
|
|
|
|
'src/core/SkFDot6Constants.h',
|
|
|
|
'src/core/SkLinearBitmapPipeline.h',
|
|
|
|
'src/core/SkLinearBitmapPipeline_*.h',
|
|
|
|
'src/core/SkUnPreMultiplyPriv.h',
|
2017-07-03 19:11:49 +00:00
|
|
|
'src/gpu/vk/*',
|
2017-02-15 16:21:32 +00:00
|
|
|
'src/opts/*_SSE2.h',
|
|
|
|
'src/opts/*_SSSE3.h',
|
|
|
|
'src/opts/*_neon.h',
|
|
|
|
'src/opts/*_sse.h',
|
|
|
|
'src/opts/Sk4px_*.h',
|
|
|
|
'src/ports/*',
|
|
|
|
'src/utils/*_win.h',
|
|
|
|
'src/utils/win/*',
|
|
|
|
'src/views/*',
|
|
|
|
'third_party/*',
|
|
|
|
'tools/fiddle/*',
|
|
|
|
'tools/viewer/*',
|
|
|
|
]
|
|
|
|
|
|
|
|
# test header for self-sufficiency and idempotency.
|
|
|
|
# Returns a string containing errors, or None iff there are no errors.
|
|
|
|
def compile_header(header):
|
|
|
|
args = ([] if fnmatch.fnmatch(header, 'include/c/*') else
|
|
|
|
public_header_args if fnmatch.fnmatch(header, 'include/*') else
|
|
|
|
all_header_args)
|
|
|
|
cmd = ['c++', '--std=c++11'] + args + [ '-o', '/dev/null', '-c', '-x', 'c++', '-']
|
|
|
|
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
proc.stdin.write('#include "%s"\n#include "%s"\n' % (header, header))
|
|
|
|
proc.stdin.close()
|
|
|
|
errors = proc.stdout.read().strip()
|
|
|
|
if proc.wait() != 0 or len(errors) > 0:
|
|
|
|
return '\n\033[7m ERROR: %s \033[0m\n%s\n\n' % (header, errors)
|
|
|
|
return None
|
|
|
|
|
2017-04-05 19:12:45 +00:00
|
|
|
# for h in headers:
|
|
|
|
# compile_header(h)
|
|
|
|
# ...Except use a multiprocessing pool.
|
|
|
|
# Exit at first error.
|
|
|
|
def compile_headers(headers):
|
2017-02-15 16:21:32 +00:00
|
|
|
class N: good = True
|
2017-04-05 19:12:45 +00:00
|
|
|
# N.good is a global scoped to this function to make a print_and_exit_if() a closure
|
2017-02-15 16:21:32 +00:00
|
|
|
pool = multiprocessing.Pool()
|
|
|
|
def print_and_exit_if(r):
|
|
|
|
if r is not None:
|
|
|
|
sys.stdout.write(r)
|
|
|
|
N.good = False
|
|
|
|
pool.terminate()
|
2017-04-05 19:12:45 +00:00
|
|
|
for path in headers:
|
|
|
|
assert os.path.exists(path)
|
|
|
|
pool.apply_async(compile_header, args=(path, ), callback=print_and_exit_if)
|
2017-02-15 16:21:32 +00:00
|
|
|
pool.close()
|
|
|
|
pool.join()
|
|
|
|
if N.good:
|
|
|
|
sys.stdout.write('all good :)\n')
|
|
|
|
else:
|
|
|
|
exit(1)
|
|
|
|
|
2017-04-05 19:12:45 +00:00
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
skia_dir = os.path.join(os.path.dirname(__file__), os.pardir)
|
|
|
|
if len(argv) > 1:
|
|
|
|
paths = [os.path.relpath(os.path.abspath(arg), skia_dir) for arg in argv[1:]]
|
|
|
|
os.chdir(skia_dir)
|
|
|
|
else:
|
|
|
|
os.chdir(skia_dir)
|
|
|
|
paths = [path for path in subprocess.check_output(['git', 'ls-files']).splitlines()
|
|
|
|
if path.endswith('.h')
|
|
|
|
and not any(fnmatch.fnmatch(path, pattern) for pattern in ignore)]
|
|
|
|
compile_headers(paths)
|
|
|
|
|
|
|
|
|
2017-02-15 16:21:32 +00:00
|
|
|
if __name__ == '__main__':
|
2017-04-05 19:12:45 +00:00
|
|
|
main(sys.argv)
|
2017-02-15 16:21:32 +00:00
|
|
|
|