OLD | NEW |
---|---|
(Empty) | |
1 from __future__ import print_function | |
2 | |
3 import time | |
4 start = time.clock() | |
5 | |
6 import os | |
7 import argparse | |
8 import sys | |
9 | |
10 def main(): | |
11 """Main function.""" | |
12 | |
13 parser = argparse.ArgumentParser( | |
14 description="Generates a table of idl name to source code path.") | |
15 | |
16 parser.add_argument("--blink-source-directory", required=True, | |
abarth-chromium
2013/04/25 14:14:24
Please don't use the word "blink" in source code.
| |
17 help="The directory that contains the Blink source.") | |
18 parser.add_argument("--idl-list-file", required=True, | |
19 help="The file that contains the list of idl files.") | |
20 parser.add_argument("--output-file", required=True, | |
21 help="The file to write the output table to.") | |
22 | |
23 args = parser.parse_args() | |
24 | |
25 # print("args.blink_source_directory = " + args.blink_source_directory) | |
26 # print("args.idl_list_file = " + args.idl_list_file) | |
27 # print("args.output_file = " + args.output_file) | |
28 | |
29 # Find the WebCore directory | |
abarth-chromium
2013/04/25 14:14:24
There is no such thing as WebCore.
| |
30 webkit_source = os.path.abspath(args.blink_source_directory) | |
abarth-chromium
2013/04/25 14:14:24
Please don't use the word "webkit" in new source c
| |
31 | |
32 idl_to_path_map = {} | |
33 core_dir = os.path.join(webkit_source, "core") | |
abarth-chromium
2013/04/25 14:14:24
I don't think we should hard-code information abou
| |
34 for (dirpath, dirnames, filenames) in os.walk(core_dir): | |
35 process_directory(dirpath, filenames, webkit_source, idl_to_path_map) | |
36 | |
37 no_in_core = len(idl_to_path_map) | |
38 if no_in_core == 0: | |
39 # Something is terribly bad. | |
40 print("Something is bad. Found no idl files in " + core_dir) | |
41 sys.exit(1) | |
42 | |
43 modules_dir = os.path.join(webkit_source, "modules") | |
44 for (dirpath, dirnames, filenames) in os.walk(modules_dir): | |
45 process_directory(dirpath, filenames, webkit_source, idl_to_path_map) | |
46 | |
47 if len(idl_to_path_map) == no_in_core: | |
48 # Something is terribly bad. | |
49 print("Something is bad. Found no idl files in " + modules_dir) | |
50 sys.exit(1) | |
51 | |
52 # print("Found %d idl files in %s and %s." % (len(idl_to_path_map), core_dir , modules_dir)) | |
53 # These are not (currently) found by the code above. | |
54 fallbacks = ( | |
55 ("HTMLBDIElement", "core/html"), | |
56 ("HTMLSummaryElement","core/html"), | |
57 ("InternalSettingsGenerated", ".."), | |
abarth-chromium
2013/04/25 14:14:24
This doesn't look very maintainable. It would be
Daniel Bratell
2013/04/25 21:24:26
And I've even found a few more interfaces that don
| |
58 ) | |
59 for fallback in fallbacks: | |
60 if not fallback[0] in idl_to_path_map: | |
61 idl_to_path_map[fallback[0]] = fallback[1] | |
62 | |
63 _write_output(idl_to_path_map, args.output_file) | |
64 print("Wrote new version of %s in %dms." % (args.output_file, | |
65 1000*(time.clock() - start))) | |
66 | |
67 def process_directory(dirpath, filenames, webkit_source, idl_to_path_map): | |
68 """Inserts every idl found file_names into idl_to_path_map.""" | |
69 include_path = os.path.relpath(dirpath, webkit_source) | |
70 include_path = include_path.replace("\\", "/") | |
71 | |
72 for filename in filenames: | |
73 if filename.endswith(".idl"): | |
74 interface_name = filename[:-4] | |
75 if interface_name: | |
76 if (interface_name == "JavaScriptCallFrame" or | |
77 interface_name == "ScriptProfile" or | |
78 interface_name == "ScriptProfileNode"): | |
79 # Not sure why these inspector files aren't in the | |
80 # same directory as the idl files, but... | |
81 interface_include_path = "bindings/v8" | |
82 else: | |
83 interface_include_path = include_path | |
84 | |
85 idl_to_path_map[interface_name] = interface_include_path | |
86 | |
87 def _write_output(idl_to_path_map, output_file): | |
88 """Writes the contents of idl_to_path_map to output_file.""" | |
89 entries = [] | |
90 for (interface_name, interface_include_path) in idl_to_path_map.iteritems(): | |
91 entries.append("%s,%s" % (interface_name, interface_include_path)) | |
92 | |
93 with open(output_file, "w") as f: | |
94 f.write("\n".join(entries)) | |
95 | |
96 if __name__ == "__main__": | |
97 main() | |
OLD | NEW |