aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar djsollen <djsollen@google.com>2014-11-13 12:52:35 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2014-11-13 12:52:35 -0800
commit0b17d6cb343cb71a3f548a02f0952c3592fc8c87 (patch)
tree0a5577be50cfbd238db7008c7d73f7cc7b9e58a6 /tools
parent04f7e14b385118b8caa3ad7fcb30d64f4c32e677 (diff)
Cleanup public includes directory.
This CL updates various files in the includes directory to ensure that (1) they do not depend on headers in /src and (2) that they minimize their dependence on external headers. To ensure that we don't regress this behavior a new build target has been added to build a single cpp file that contains all* public includes and is compiled with only those directories in the include path. * The exception is those includes that depend on OS specific headers BUG=skia:2941 NOTRY=true Review URL: https://codereview.chromium.org/721903002
Diffstat (limited to 'tools')
-rw-r--r--tools/generate_includes_cpp.py73
1 files changed, 73 insertions, 0 deletions
diff --git a/tools/generate_includes_cpp.py b/tools/generate_includes_cpp.py
new file mode 100644
index 0000000000..1a6f117c63
--- /dev/null
+++ b/tools/generate_includes_cpp.py
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+
+'''
+Copyright 2014 Google Inc.
+
+Use of this source code is governed by a BSD-style license that can be
+found in the LICENSE file.
+'''
+
+import os
+import optparse
+import posixpath
+import re
+
+
+def is_ignored(full_path, ignore_list):
+ for ignore_path in ignore_list:
+ if re.match(full_path, ignore_path, re.I):
+ return True
+ return False
+
+
+def find_header_files(include_dirs, ignore_list):
+ """Return a list of all '.h' files in top_dir.
+
+ Args:
+ include_dirs: Paths to the directories within which to recursively search
+ for files ending in '.h'
+ ignore_list: Paths to both files and directories that are to be excluded
+ from the search for headers
+
+ Returns:
+ A list of all the files inside include_dirs that end in '.h', relative to
+ their respective include_dir that are not explicitly ignored.
+ """
+ headers = []
+ for top_dir in include_dirs:
+ for filename in os.listdir(top_dir):
+ full_path = posixpath.join(top_dir, filename)
+ if is_ignored(full_path, ignore_list):
+ continue
+ elif os.path.isdir(full_path):
+ nested_headers = find_header_files([full_path], ignore_list)
+ for nested_header in nested_headers:
+ headers.append(os.path.join(filename, nested_header))
+ elif filename.endswith('.h'):
+ headers.append(filename)
+ return headers
+
+
+def GenerateIncludeCPP(output_file, include_dirs, ignore_list):
+ headers = find_header_files(include_dirs, ignore_list)
+
+ # Emit resulting source file.
+ with open(os.path.join(os.getcwd(), output_file), "w+") as output:
+ for header in headers:
+ output.write("#include <%s>\n" % header)
+
+
+def main():
+ parser = optparse.OptionParser()
+ parser.add_option("--ignore", action="store", type="string", dest="ignore",
+ help="file to write the processed sources array to.")
+ parser.set_usage("""generate_include_cpp out.cpp include_dir
+ out.cpp: C++ code to be generated.
+ include_dirs: directories to traverse for include files""")
+ (options, args) = parser.parse_args()
+
+ GenerateIncludeCPP(args[0], args[1:], options.ignore.split())
+
+
+if __name__ == "__main__":
+ main()