blob: c23f87939228683bc70fb9ca837e9447d8e8b1f8 [file] [log] [blame]
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# based on an almost identical script by: (Jyrki Alakuijala)
"""Prints out include dependencies in chrome.
Since it ignores defines, it gives just a rough estimation of file size.
tools/ -Iout/Default/gen chrome/browser/ui/browser.h
import argparse
import os
import re
import sys
# Created by copying the command line for, replacing
# spaces with newlines, and dropping everything except -F and -I switches.
# TODO(port): Add windows, linux directories.
def Walk(include_dirs, seen, filename, parent, indent):
"""Returns the size of |filename| plus the size of all files included by
|filename| and prints the include tree of |filename| to stdout. Every file
is visited at most once.
total_bytes = 0
# .proto(devel) filename translation
if filename.endswith('.pb.h'):
basename = filename[:-5]
if os.path.exists(basename + '.proto'):
filename = basename + '.proto'
print 'could not find ', filename
# Show and count files only once.
if filename in seen:
return total_bytes
# Display the paths.
print ' ' * indent + filename
# Skip system includes.
if filename[0] == '<':
return total_bytes
# Find file in all include paths.
resolved_filename = filename
for root in INCLUDE_PATHS + [os.path.dirname(parent)] + include_dirs:
if os.path.exists(os.path.join(root, filename)):
resolved_filename = os.path.join(root, filename)
# Recurse.
if os.path.exists(resolved_filename):
lines = open(resolved_filename).readlines()
print ' ' * (indent + 2) + "-- not found"
lines = []
for line in lines:
line = line.strip()
match = re.match(r'#include\s+(\S+).*', line)
if match:
include =
if include.startswith('"'):
include = include[1:-1]
total_bytes += Walk(
include_dirs, seen, include, resolved_filename, indent + 2)
elif line.startswith('import '):
total_bytes += Walk(
include_dirs, seen, line.split('"')[1], resolved_filename, indent + 2)
return total_bytes + len("".join(lines))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-I', action='append', dest='include_dirs')
options = parser.parse_args(sys.argv[1:])
if not options.include_dirs:
options.include_dirs = []
bytes = Walk(options.include_dirs, set(), options.source_file, '', 0)
print float(bytes) / (1 << 20), "megabytes of chrome source"
if __name__ == '__main__':