Chromium Code Reviews| 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, | |
| 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 | |
| 30 webkit_source = os.path.abspath(args.blink_source_directory) | |
| 31 | |
| 32 idl_to_path_map = {} | |
| 33 core_dir = os.path.join(webkit_source, "core") | |
| 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", ".."), | |
| 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 output = [] | |
| 89 output.append("#!/usr/bin/perl") | |
| 90 output.append("use strict;") | |
| 91 output.append("use warnings;") | |
| 92 output.append("use Exporter;") | |
| 93 | |
| 94 output.append("") | |
| 95 output.append("# GENERATED BY idltopath.py, DO NOT MODIFY BY HAND.") | |
|
eseidel
2013/04/25 07:03:39
Woh. Using python to generate perl, eh?
I think
| |
| 96 output.append("# (c) 2013 Daniel Bratell, Opera Software ASA") | |
| 97 output.append("") | |
| 98 output.append("package idltopath;") | |
| 99 output.append("") | |
| 100 output.append("our @ISA = qw( Exporter );") | |
| 101 output.append("# our @EXPORT_OK = qw( export_me export_me_too );") | |
| 102 | |
| 103 output.append("# These are exported by default.") | |
| 104 output.append("our @EXPORT = qw( idl_to_path );") | |
| 105 output.append("") | |
| 106 output.append("my %idl_to_path_hash = (") | |
| 107 | |
| 108 for (interface_name, interface_include_path) in idl_to_path_map.iteritems(): | |
| 109 output.append(' "%s" => "%s",' % ( | |
| 110 interface_name, interface_include_path)) | |
| 111 | |
| 112 output.append(");") | |
| 113 output.append("") | |
| 114 output.append("sub idl_to_path") | |
| 115 output.append("{") | |
| 116 output.append(" my $interface = shift;") | |
| 117 output.append("") | |
| 118 output.append(" if ($idl_to_path_hash{$interface}) {") | |
| 119 output.append(" return $idl_to_path_hash{$interface} . '/';") | |
| 120 output.append(" } elsif ($interface =~ /^SVGPath/ && $idl_to_path_hash{$i nterface . \"Abs\"}) {") | |
| 121 output.append(" return $idl_to_path_hash{$interface . \"Abs\"} . '/'; ") | |
| 122 output.append(" } else {") | |
| 123 output.append(" return 'fixmebratell89/';") | |
| 124 output.append(" }") | |
| 125 output.append("}") | |
| 126 | |
| 127 output.append("1;") # To make sure the module returns "true". | |
| 128 | |
| 129 # print("\n".join(output)) | |
| 130 | |
| 131 entries = [] | |
| 132 for (interface_name, interface_include_path) in idl_to_path_map.iteritems(): | |
| 133 entries.append("%s,%s" % (interface_name, interface_include_path)) | |
| 134 | |
| 135 with open(output_file, "w") as f: | |
| 136 f.write("\n".join(entries)) | |
| 137 | |
| 138 if __name__ == "__main__": | |
| 139 main() | |
| OLD | NEW |