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

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: Updated to a newer chromium version 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.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..b3925f2586cd121411b5ecf34d4c50c2f837ddd3
--- /dev/null
+++ b/Source/bindings/scripts/idltopathgenerator.py
@@ -0,0 +1,102 @@
+from __future__ import print_function
+
+import time
+start = time.clock()
+
+import os
+import argparse
+import sys
+
+INTERFACE_FALLBACK_MAP = (
+ # Interfaces that have no corresponding idl file.
+ ("HTMLBDIElement", "core/html"),
+ ("HTMLSummaryElement", "core/html"),
+ ("MathMLElement", "core/mathml"),
+ ("MathMLInlineContainerElement", "core/mathml"),
+ ("MathMLMathElement", "core/mathml"),
+ ("MathMLTextElement", "core/mathml"),
+ # Generated file.
+ ("InternalSettingsGenerated", ".."),
+ )
+
+def main():
+ """Main function."""
+
+ parser = argparse.ArgumentParser(
+ description="Generates a table of idl name to source code path.")
+
+ parser.add_argument("--include-root-directory", required=True,
+ help="The directory the paths should be relative to.")
+ 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.include_root_directory = " + args.include_root_directory)
+ print("args.idl_list_file = " + args.idl_list_file)
+ print("args.output_file = " + args.output_file)
+ with open(args.idl_list_file) as f:
+ idls = f.read().splitlines()
+
+ root_dir = os.path.abspath(args.include_root_directory)
+
+ idl_to_path_map = {}
+
+ # # Build the map by reading from the input file.
+ # for idl in idls:
+ # filename = os.path.basename(idl)
+ # idl_path = os.path.dirname(os.path.abspath(idl))
+ # include_path = os.path.relpath(idl_path, root_dir)
+ # include_path = include_path.replace(os.sep, "/")
+ # process_file(filename, include_path, idl_to_path_map)
+
+ # Build the map by reading the file system.
+ # Not both of these are needed. Which is best? Well,
+ # "MediaKeyMessageEvent" and probably other idls are not included
+ # above. So this will have to be the solution.
+ for (dirpath, dirnames, filenames) in os.walk(root_dir):
+ process_directory(dirpath, filenames, root_dir, idl_to_path_map)
+
+ if len(idl_to_path_map) == 0:
+ # Something is terribly bad.
+ print("Something is bad. Found no idl files in " + args.idl_list_file)
+ sys.exit(1)
+
+ # These are not (currently) found by the code above.
+ for fallback in INTERFACE_FALLBACK_MAP:
+ 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, root_dir, idl_to_path_map):
+ """Inserts every idl found file_names into idl_to_path_map."""
+ include_path = os.path.relpath(dirpath, root_dir)
+ include_path = include_path.replace(os.sep, "/")
+
+ for filename in filenames:
+ process_file(filename, include_path, idl_to_path_map)
+
+def process_file(filename, include_path, idl_to_path_map):
+ if filename.endswith(".idl"):
+ interface_name = filename[:-4]
+ if interface_name:
+ include_path = include_path
+
+ idl_to_path_map[interface_name] = 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()
« no previous file with comments | « Source/bindings/scripts/idltopath.pm ('k') | Source/core/core.gyp/core.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698