52337de95c
PS2 adds a rewrite for Skia #include <...> to #include "...", letting them be otherwise rewritten and sorted too. (We do need one exception for the Vulkan headers, which will otherwise be rewritten to always point to our own.) I don't think it's particularly important to favor "" or <>, but picking one keeps things consistent. PS3 adds a missing SkMutex.h include. PS4 fixes a terrible readability problem. Change-Id: Id9fe752727ef30e802b1daf755ee2ed15e267577 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229742 Commit-Queue: Mike Klein <mtklein@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: Mike Klein <mtklein@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
84 lines
2.5 KiB
Python
84 lines
2.5 KiB
Python
#!/usr/bin/python2
|
|
#
|
|
# Copyright 2019 Google Inc.
|
|
#
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
# found in the LICENSE file.
|
|
|
|
import os
|
|
|
|
roots = [
|
|
'bench',
|
|
'dm',
|
|
'docs',
|
|
'example',
|
|
'experimental',
|
|
'fuzz',
|
|
'gm',
|
|
'include',
|
|
'modules',
|
|
'platform_tools/android/apps',
|
|
'samplecode',
|
|
'src',
|
|
'tests',
|
|
'third_party/etc1',
|
|
'third_party/gif',
|
|
'tools'
|
|
]
|
|
|
|
# Don't want to always force our local Vulkan headers.
|
|
angle_bracket_whitelist = ['vulkan/']
|
|
|
|
# Map short name -> absolute path for all Skia headers.
|
|
headers = {}
|
|
for root in roots:
|
|
for path, _, files in os.walk(root):
|
|
for file_name in files:
|
|
if file_name.endswith('.h'):
|
|
if file_name in headers:
|
|
print path, file_name, headers[file_name]
|
|
assert file_name not in headers
|
|
headers[file_name] = os.path.abspath(os.path.join(path, file_name))
|
|
|
|
# Rewrite any #includes relative to Skia's top-level directory.
|
|
for root in roots:
|
|
for path, _, files in os.walk(root):
|
|
if 'generated' in path:
|
|
continue
|
|
for file_name in files:
|
|
if (file_name.endswith('.h') or
|
|
file_name.endswith('.c') or
|
|
file_name.endswith('.m') or
|
|
file_name.endswith('.mm') or
|
|
file_name.endswith('.inc') or
|
|
file_name.endswith('.fp') or
|
|
file_name.endswith('.cc') or
|
|
file_name.endswith('.cpp')):
|
|
# Read the whole file into memory.
|
|
file_path = os.path.join(path, file_name)
|
|
lines = open(file_path).readlines()
|
|
|
|
# Write it back out again line by line with substitutions for #includes.
|
|
with open(file_path, 'w') as output:
|
|
includes = []
|
|
|
|
for line in lines:
|
|
rewritten = line
|
|
if not any(token in line for token in angle_bracket_whitelist):
|
|
rewritten = rewritten.replace('<', '"').replace('>', '"')
|
|
parts = rewritten.split('"')
|
|
if (len(parts) == 3
|
|
and '#' in parts[0]
|
|
and 'include' in parts[0]
|
|
and os.path.basename(parts[1]) in headers):
|
|
header = headers[os.path.basename(parts[1])]
|
|
includes.append(parts[0] +
|
|
'"%s"' % os.path.relpath(header, '.') +
|
|
parts[2])
|
|
else:
|
|
for inc in sorted(includes):
|
|
print >>output, inc.strip('\n')
|
|
includes = []
|
|
print >>output, line.strip('\n')
|
|
|