Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/python | |
| 2 | |
| 3 ''' | |
| 4 Copyright 2014 Google Inc. | |
| 5 | |
| 6 Use of this source code is governed by a BSD-style license that can be | |
| 7 found in the LICENSE file. | |
| 8 ''' | |
|
borenet
2014/11/13 15:13:34
Prefer this format, but not sure it really matters
| |
| 9 | |
| 10 import os | |
| 11 import optparse | |
| 12 | |
|
borenet
2014/11/13 15:13:34
Nit: 2 lines between top-level stuff
djsollen
2014/11/13 15:45:26
Done.
| |
| 13 def is_ignored(full_path, ignore_list): | |
| 14 for ignore_path in ignore_list: | |
| 15 if full_path.endswith(ignore_path): | |
|
borenet
2014/11/13 15:13:34
Aren't some ignore_paths directories? Should this
djsollen
2014/11/13 15:45:26
Nope, we always want exact matches here. the find_
| |
| 16 return True | |
| 17 return False | |
| 18 | |
| 19 def find_header_files(include_dirs, ignore_list): | |
| 20 """Return a list of all '.h' files in top_dir. | |
| 21 | |
| 22 Args: | |
| 23 include_dirs: Paths to the directories within which to recursively search | |
| 24 for files ending in '.h' | |
|
borenet
2014/11/13 15:13:34
Please document ignore_list as well.
djsollen
2014/11/13 15:45:26
Done.
| |
| 25 | |
| 26 Returns: | |
| 27 A list of all the files inside include_dirs that end in '.h', relative to | |
| 28 their respective include_dir. | |
| 29 """ | |
| 30 headers = [] | |
| 31 for top_dir in include_dirs: | |
| 32 for filename in os.listdir(top_dir): | |
| 33 full_path = os.path.join(top_dir, filename) | |
| 34 if is_ignored(full_path, ignore_list): | |
| 35 #print "%s\n" % full_path | |
|
borenet
2014/11/13 15:13:34
Should this stay or go?
djsollen
2014/11/13 15:45:26
Done.
| |
| 36 continue | |
| 37 elif os.path.isdir(full_path): | |
| 38 nested_headers = find_header_files([full_path], ignore_list) | |
| 39 for nested_header in nested_headers: | |
| 40 headers.append(os.path.join(filename, nested_header)) | |
|
borenet
2014/11/13 15:13:34
Optional: this would get faster if you made this f
| |
| 41 elif filename.endswith('.h'): | |
| 42 headers.append(filename) | |
| 43 return headers | |
| 44 | |
| 45 def GenerateIncludeCPP(output_file, include_dirs, ignore_list): | |
| 46 headers = find_header_files(include_dirs, ignore_list) | |
| 47 | |
| 48 # Emit resulting source file. | |
| 49 output = open(os.path.join(os.getcwd(), output_file), "w+") | |
| 50 for header in headers: | |
| 51 output.write("#include <%s>\n" % header) | |
| 52 output.close() | |
|
borenet
2014/11/13 15:13:34
Please use the "with" syntax:
with open(os.path.j
djsollen
2014/11/13 15:45:26
Done.
| |
| 53 | |
| 54 def main(): | |
| 55 parser = optparse.OptionParser() | |
| 56 parser.add_option("--ignore", action="store", type="string", dest="ignore", | |
| 57 help="file to write the processed sources array to.") | |
| 58 parser.set_usage("""generate_include_cpp out.cpp include_dir | |
| 59 out.cpp: C++ code to be generated. | |
| 60 include_dirs: directories to traverse for include files""") | |
| 61 (options, args) = parser.parse_args() | |
| 62 | |
| 63 GenerateIncludeCPP(args[0], args[1:], options.ignore.split()) | |
| 64 | |
| 65 | |
| 66 if __name__ == "__main__": | |
| 67 main() | |
| OLD | NEW |