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

Unified Diff: Source/bindings/scripts/idltopathgenerator.py

Issue 14456006: Fixes to make scripts generate includes with paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 8 months 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 | « Source/bindings/scripts/idltopath.pm ('k') | Source/core/core.gyp/core_derived_sources.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..b326cd2eb24e8497d3436c0019f47c0c5a716718
--- /dev/null
+++ b/Source/bindings/scripts/idltopathgenerator.py
@@ -0,0 +1,139 @@
+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,
+ 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
+ webkit_source = os.path.abspath(args.blink_source_directory)
+
+ idl_to_path_map = {}
+ core_dir = os.path.join(webkit_source, "core")
+ 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", ".."),
+ )
+ 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):
+ output = []
+ output.append("#!/usr/bin/perl")
+ output.append("use strict;")
+ output.append("use warnings;")
+ output.append("use Exporter;")
+
+ output.append("")
+ 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
+ output.append("# (c) 2013 Daniel Bratell, Opera Software ASA")
+ output.append("")
+ output.append("package idltopath;")
+ output.append("")
+ output.append("our @ISA = qw( Exporter );")
+ output.append("# our @EXPORT_OK = qw( export_me export_me_too );")
+
+ output.append("# These are exported by default.")
+ output.append("our @EXPORT = qw( idl_to_path );")
+ output.append("")
+ output.append("my %idl_to_path_hash = (")
+
+ for (interface_name, interface_include_path) in idl_to_path_map.iteritems():
+ output.append(' "%s" => "%s",' % (
+ interface_name, interface_include_path))
+
+ output.append(");")
+ output.append("")
+ output.append("sub idl_to_path")
+ output.append("{")
+ output.append(" my $interface = shift;")
+ output.append("")
+ output.append(" if ($idl_to_path_hash{$interface}) {")
+ output.append(" return $idl_to_path_hash{$interface} . '/';")
+ output.append(" } elsif ($interface =~ /^SVGPath/ && $idl_to_path_hash{$interface . \"Abs\"}) {")
+ output.append(" return $idl_to_path_hash{$interface . \"Abs\"} . '/';")
+ output.append(" } else {")
+ output.append(" return 'fixmebratell89/';")
+ output.append(" }")
+ output.append("}")
+
+ output.append("1;") # To make sure the module returns "true".
+
+# print("\n".join(output))
+
+ 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()
« no previous file with comments | « Source/bindings/scripts/idltopath.pm ('k') | Source/core/core.gyp/core_derived_sources.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698