Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1060)

Unified Diff: tools/generate_includes_cpp.py

Issue 721903002: Cleanup public includes directory. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: &^%%$# Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/views/unix/keysym2ucs.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/generate_includes_cpp.py
diff --git a/tools/generate_includes_cpp.py b/tools/generate_includes_cpp.py
new file mode 100644
index 0000000000000000000000000000000000000000..1a6f117c630a3b922d94217e5a8369063b187647
--- /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()
« no previous file with comments | « src/views/unix/keysym2ucs.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698