Index: Source/bindings/scripts/idltopathgenerator.py |
diff --git a/Source/bindings/scripts/idltopathgenerator.py b/Source/bindings/scripts/idltopathgenerator.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e0f0e356f6128475dc0f8403d355ae5baf7b9ecc |
--- /dev/null |
+++ b/Source/bindings/scripts/idltopathgenerator.py |
@@ -0,0 +1,97 @@ |
+from __future__ import print_function |
+ |
+import time |
+start = time.clock() |
+ |
+import os |
+import argparse |
+import sys |
+ |
+def main(): |
+ """Main function.""" |
+ |
+ parser = argparse.ArgumentParser( |
+ description="Generates a table of idl name to source code path.") |
+ |
+ 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.
|
+ help="The directory that contains the Blink source.") |
+ parser.add_argument("--idl-list-file", required=True, |
+ help="The file that contains the list of idl files.") |
+ parser.add_argument("--output-file", required=True, |
+ help="The file to write the output table to.") |
+ |
+ args = parser.parse_args() |
+ |
+ # print("args.blink_source_directory = " + args.blink_source_directory) |
+ # print("args.idl_list_file = " + args.idl_list_file) |
+ # print("args.output_file = " + args.output_file) |
+ |
+ # Find the WebCore directory |
abarth-chromium
2013/04/25 14:14:24
There is no such thing as WebCore.
|
+ 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
|
+ |
+ idl_to_path_map = {} |
+ 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
|
+ for (dirpath, dirnames, filenames) in os.walk(core_dir): |
+ process_directory(dirpath, filenames, webkit_source, idl_to_path_map) |
+ |
+ no_in_core = len(idl_to_path_map) |
+ if no_in_core == 0: |
+ # Something is terribly bad. |
+ print("Something is bad. Found no idl files in " + core_dir) |
+ sys.exit(1) |
+ |
+ modules_dir = os.path.join(webkit_source, "modules") |
+ for (dirpath, dirnames, filenames) in os.walk(modules_dir): |
+ process_directory(dirpath, filenames, webkit_source, idl_to_path_map) |
+ |
+ if len(idl_to_path_map) == no_in_core: |
+ # Something is terribly bad. |
+ print("Something is bad. Found no idl files in " + modules_dir) |
+ sys.exit(1) |
+ |
+ # print("Found %d idl files in %s and %s." % (len(idl_to_path_map), core_dir, modules_dir)) |
+ # These are not (currently) found by the code above. |
+ fallbacks = ( |
+ ("HTMLBDIElement", "core/html"), |
+ ("HTMLSummaryElement","core/html"), |
+ ("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
|
+ ) |
+ for fallback in fallbacks: |
+ if not fallback[0] in idl_to_path_map: |
+ idl_to_path_map[fallback[0]] = fallback[1] |
+ |
+ _write_output(idl_to_path_map, args.output_file) |
+ print("Wrote new version of %s in %dms." % (args.output_file, |
+ 1000*(time.clock() - start))) |
+ |
+def process_directory(dirpath, filenames, webkit_source, idl_to_path_map): |
+ """Inserts every idl found file_names into idl_to_path_map.""" |
+ include_path = os.path.relpath(dirpath, webkit_source) |
+ include_path = include_path.replace("\\", "/") |
+ |
+ for filename in filenames: |
+ if filename.endswith(".idl"): |
+ interface_name = filename[:-4] |
+ if interface_name: |
+ if (interface_name == "JavaScriptCallFrame" or |
+ interface_name == "ScriptProfile" or |
+ interface_name == "ScriptProfileNode"): |
+ # Not sure why these inspector files aren't in the |
+ # same directory as the idl files, but... |
+ interface_include_path = "bindings/v8" |
+ else: |
+ interface_include_path = include_path |
+ |
+ idl_to_path_map[interface_name] = interface_include_path |
+ |
+def _write_output(idl_to_path_map, output_file): |
+ """Writes the contents of idl_to_path_map to output_file.""" |
+ entries = [] |
+ for (interface_name, interface_include_path) in idl_to_path_map.iteritems(): |
+ entries.append("%s,%s" % (interface_name, interface_include_path)) |
+ |
+ with open(output_file, "w") as f: |
+ f.write("\n".join(entries)) |
+ |
+if __name__ == "__main__": |
+ main() |