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

Side by Side 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, 7 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 INTERFACE_FALLBACK_MAP = (
11 # Interfaces that have no corresponding idl file.
12 ("HTMLBDIElement", "core/html"),
13 ("HTMLSummaryElement", "core/html"),
14 ("MathMLElement", "core/mathml"),
15 ("MathMLInlineContainerElement", "core/mathml"),
16 ("MathMLMathElement", "core/mathml"),
17 ("MathMLTextElement", "core/mathml"),
18 # Generated file.
19 ("InternalSettingsGenerated", ".."),
20 )
21
22 def main():
23 """Main function."""
24
25 parser = argparse.ArgumentParser(
26 description="Generates a table of idl name to source code path.")
27
28 parser.add_argument("--include-root-directory", required=True,
29 help="The directory the paths should be relative to.")
30 parser.add_argument("--idl-list-file", required=True,
31 help="The file that contains the list of idl files.")
32 parser.add_argument("--output-file", required=True,
33 help="The file to write the output table to.")
34
35 args = parser.parse_args()
36
37 print("args.include_root_directory = " + args.include_root_directory)
38 print("args.idl_list_file = " + args.idl_list_file)
39 print("args.output_file = " + args.output_file)
40 with open(args.idl_list_file) as f:
41 idls = f.read().splitlines()
42
43 root_dir = os.path.abspath(args.include_root_directory)
44
45 idl_to_path_map = {}
46
47 # # Build the map by reading from the input file.
48 # for idl in idls:
49 # filename = os.path.basename(idl)
50 # idl_path = os.path.dirname(os.path.abspath(idl))
51 # include_path = os.path.relpath(idl_path, root_dir)
52 # include_path = include_path.replace(os.sep, "/")
53 # process_file(filename, include_path, idl_to_path_map)
54
55 # Build the map by reading the file system.
56 # Not both of these are needed. Which is best? Well,
57 # "MediaKeyMessageEvent" and probably other idls are not included
58 # above. So this will have to be the solution.
59 for (dirpath, dirnames, filenames) in os.walk(root_dir):
60 process_directory(dirpath, filenames, root_dir, idl_to_path_map)
61
62 if len(idl_to_path_map) == 0:
63 # Something is terribly bad.
64 print("Something is bad. Found no idl files in " + args.idl_list_file)
65 sys.exit(1)
66
67 # These are not (currently) found by the code above.
68 for fallback in INTERFACE_FALLBACK_MAP:
69 if not fallback[0] in idl_to_path_map:
70 idl_to_path_map[fallback[0]] = fallback[1]
71
72 _write_output(idl_to_path_map, args.output_file)
73 print("Wrote new version of %s in %dms." % (args.output_file,
74 1000*(time.clock() - start)))
75
76 def process_directory(dirpath, filenames, root_dir, idl_to_path_map):
77 """Inserts every idl found file_names into idl_to_path_map."""
78 include_path = os.path.relpath(dirpath, root_dir)
79 include_path = include_path.replace(os.sep, "/")
80
81 for filename in filenames:
82 process_file(filename, include_path, idl_to_path_map)
83
84 def process_file(filename, include_path, idl_to_path_map):
85 if filename.endswith(".idl"):
86 interface_name = filename[:-4]
87 if interface_name:
88 include_path = include_path
89
90 idl_to_path_map[interface_name] = include_path
91
92 def _write_output(idl_to_path_map, output_file):
93 """Writes the contents of idl_to_path_map to output_file."""
94 entries = []
95 for (interface_name, interface_include_path) in idl_to_path_map.iteritems():
96 entries.append("%s,%s" % (interface_name, interface_include_path))
97
98 with open(output_file, "w") as f:
99 f.write("\n".join(entries))
100
101 if __name__ == "__main__":
102 main()
OLDNEW
« 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