skia2/tools/rewrite_includes.py
Mike Klein e11e5c162f AFAICT, only gm/etc1 uses third_party/etc1
The need for -Ithird_party/gif has already been
rewritten away, and we can do the same for etc1.

Change-Id: I97408652682b5ec406647108056e7a1ea6a56c29
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/210131
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
2019-04-24 18:57:58 +00:00

77 lines
2.1 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'
]
# 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:
parts = line.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, '.'))
else:
for inc in sorted(includes):
print >>output, inc
includes = []
print >>output, line.strip('\n')