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

Side by Side Diff: Tools/Scripts/webkitpy/bindings/main.py

Issue 670663002: IDL: Use IdlReader to compute interface_info_individual (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 2 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
OLDNEW
1 # Copyright (C) 2011 Google Inc. All rights reserved. 1 # Copyright (C) 2011 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions 4 # modification, are permitted provided that the following conditions
5 # are met: 5 # are met:
6 # 1. Redistributions of source code must retain the above copyright 6 # 1. Redistributions of source code must retain the above copyright
7 # notice, this list of conditions and the following disclaimer. 7 # notice, this list of conditions and the following disclaimer.
8 # 2. Redistributions in binary form must reproduce the above copyright 8 # 2. Redistributions in binary form must reproduce the above copyright
9 # notice, this list of conditions and the following disclaimer in the 9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution. 10 # documentation and/or other materials provided with the distribution.
(...skipping 27 matching lines...) Expand all
38 module_path = os.path.dirname(__file__) 38 module_path = os.path.dirname(__file__)
39 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir, 39 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir,
40 os.pardir, os.pardir, 'Source')) 40 os.pardir, os.pardir, 'Source'))
41 sys.path.append(source_path) # for Source/bindings imports 41 sys.path.append(source_path) # for Source/bindings imports
42 42
43 import bindings.scripts.compute_interfaces_info_individual 43 import bindings.scripts.compute_interfaces_info_individual
44 from bindings.scripts.compute_interfaces_info_individual import compute_info_ind ividual, info_individual 44 from bindings.scripts.compute_interfaces_info_individual import compute_info_ind ividual, info_individual
45 import bindings.scripts.compute_interfaces_info_overall 45 import bindings.scripts.compute_interfaces_info_overall
46 from bindings.scripts.compute_interfaces_info_overall import compute_interfaces_ info_overall, interfaces_info 46 from bindings.scripts.compute_interfaces_info_overall import compute_interfaces_ info_overall, interfaces_info
47 from bindings.scripts.idl_compiler import IdlCompilerDictionaryImpl, IdlCompiler V8 47 from bindings.scripts.idl_compiler import IdlCompilerDictionaryImpl, IdlCompiler V8
48 from bindings.scripts.idl_reader import IdlReader
48 from bindings.scripts.utilities import idl_filename_to_component 49 from bindings.scripts.utilities import idl_filename_to_component
49 50
50 51
51 PASS_MESSAGE = 'All tests PASS!' 52 PASS_MESSAGE = 'All tests PASS!'
52 FAIL_MESSAGE = """Some tests FAIL! 53 FAIL_MESSAGE = """Some tests FAIL!
53 To update the reference files, execute: 54 To update the reference files, execute:
54 run-bindings-tests --reset-results 55 run-bindings-tests --reset-results
55 56
56 If the failures are not due to your changes, test results may be out of sync; 57 If the failures are not due to your changes, test results may be out of sync;
57 please rebaseline them in a separate CL, after checking that tests fail in ToT. 58 please rebaseline them in a separate CL, after checking that tests fail in ToT.
58 In CL, please set: 59 In CL, please set:
59 NOTRY=true 60 NOTRY=true
60 TBR=(someone in Source/bindings/OWNERS or WATCHLISTS:bindings) 61 TBR=(someone in Source/bindings/OWNERS or WATCHLISTS:bindings)
61 """ 62 """
62 63
63 DEPENDENCY_IDL_FILES = frozenset([ 64 DEPENDENCY_IDL_FILES = frozenset([
64 'TestImplements.idl', 65 'TestImplements.idl',
65 'TestImplements2.idl', 66 'TestImplements2.idl',
66 'TestImplements3.idl', 67 'TestImplements3.idl',
67 'TestPartialInterface.idl', 68 'TestPartialInterface.idl',
68 'TestPartialInterface2.idl', 69 'TestPartialInterface2.idl',
69 'TestPartialInterface3.idl', 70 'TestPartialInterface3.idl',
70 ]) 71 ])
71 72
73 # core/inspector/InspectorInstrumentation.idl is not a valid Blink IDL.
74 NON_BLINK_IDL_FILES = frozenset([
75 'InspectorInstrumentation.idl',
76 ])
77
72 COMPONENT_DIRECTORY = frozenset(['core', 'modules']) 78 COMPONENT_DIRECTORY = frozenset(['core', 'modules'])
73 79
74 test_input_directory = os.path.join(source_path, 'bindings', 'tests', 'idls') 80 test_input_directory = os.path.join(source_path, 'bindings', 'tests', 'idls')
75 reference_directory = os.path.join(source_path, 'bindings', 'tests', 'results') 81 reference_directory = os.path.join(source_path, 'bindings', 'tests', 'results')
76 82
77 PLY_LEX_YACC_FILES = frozenset([ 83 PLY_LEX_YACC_FILES = frozenset([
78 'lextab.py', # PLY lex 84 'lextab.py', # PLY lex
79 'lextab.pyc', 85 'lextab.pyc',
80 'parsetab.pickle', # PLY yacc 86 'parsetab.pickle', # PLY yacc
81 ]) 87 ])
82 88
83 @contextmanager 89 @contextmanager
84 def TemporaryDirectory(): 90 def TemporaryDirectory():
85 """Wrapper for tempfile.mkdtemp() so it's usable with 'with' statement. 91 """Wrapper for tempfile.mkdtemp() so it's usable with 'with' statement.
86 92
87 Simple backport of tempfile.TemporaryDirectory from Python 3.2. 93 Simple backport of tempfile.TemporaryDirectory from Python 3.2.
88 """ 94 """
89 name = tempfile.mkdtemp() 95 name = tempfile.mkdtemp()
90 try: 96 try:
91 yield name 97 yield name
92 finally: 98 finally:
93 shutil.rmtree(name) 99 shutil.rmtree(name)
94 100
95 101
96 def generate_interface_dependencies(): 102 def generate_interface_dependencies(output_directory):
97 def idl_paths_recursive(directory): 103 def idl_paths_recursive(directory):
98 # This is slow, especially on Windows, due to os.walk making 104 # This is slow, especially on Windows, due to os.walk making
99 # excess stat() calls. Faster versions may appear in Python 3.5 or 105 # excess stat() calls. Faster versions may appear in Python 3.5 or
100 # later: 106 # later:
101 # https://github.com/benhoyt/scandir 107 # https://github.com/benhoyt/scandir
102 # http://bugs.python.org/issue11406 108 # http://bugs.python.org/issue11406
103 idl_paths = [] 109 idl_paths = []
104 for dirpath, _, files in os.walk(directory): 110 for dirpath, _, files in os.walk(directory):
105 idl_paths.extend(os.path.join(dirpath, filename) 111 idl_paths.extend(os.path.join(dirpath, filename)
106 for filename in fnmatch.filter(files, '*.idl')) 112 for filename in fnmatch.filter(files, '*.idl'))
(...skipping 20 matching lines...) Expand all
127 # 2-stage computation: individual, then overall 133 # 2-stage computation: individual, then overall
128 # 134 #
129 # Properly should compute separately by component (currently test 135 # Properly should compute separately by component (currently test
130 # includes are invalid), but that's brittle (would need to update this file 136 # includes are invalid), but that's brittle (would need to update this file
131 # for each new component) and doesn't test the code generator any better 137 # for each new component) and doesn't test the code generator any better
132 # than using a single component. 138 # than using a single component.
133 # 139 #
134 # In order to allow test IDL files to override the production IDL files if 140 # In order to allow test IDL files to override the production IDL files if
135 # they have the same interface name, process the test IDL files after the 141 # they have the same interface name, process the test IDL files after the
136 # non-test IDL files. 142 # non-test IDL files.
143 reader = IdlReader(outputdir=output_directory)
137 for idl_path_list in (non_test_idl_paths, test_idl_paths): 144 for idl_path_list in (non_test_idl_paths, test_idl_paths):
138 for idl_path in idl_path_list: 145 for idl_path in idl_path_list:
139 compute_info_individual(idl_path) 146 if os.path.basename(idl_path) in NON_BLINK_IDL_FILES:
147 continue
148 compute_info_individual(idl_path, reader)
140 info_individuals = [info_individual()] 149 info_individuals = [info_individual()]
141 # TestDictionary.{h,cpp} are placed under Source/bindings/tests/idls/core. 150 # TestDictionary.{h,cpp} are placed under Source/bindings/tests/idls/core.
142 # However, IdlCompiler generates TestDictionary.{h,cpp} by using relative_di r. 151 # However, IdlCompiler generates TestDictionary.{h,cpp} by using relative_di r.
143 # So the files will be generated under output_dir/core/bindings/tests/idls/c ore. 152 # So the files will be generated under output_dir/core/bindings/tests/idls/c ore.
144 # To avoid this issue, we need to clear relative_dir here. 153 # To avoid this issue, we need to clear relative_dir here.
145 for info in info_individuals: 154 for info in info_individuals:
146 for value in info['interfaces_info'].itervalues(): 155 for value in info['interfaces_info'].itervalues():
147 value['relative_dir'] = '' 156 value['relative_dir'] = ''
148 compute_interfaces_info_overall(info_individuals) 157 compute_interfaces_info_overall(info_individuals)
149 158
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 if relpath not in generated_files: 237 if relpath not in generated_files:
229 excess_files.append(relpath) 238 excess_files.append(relpath)
230 if excess_files: 239 if excess_files:
231 print ('Excess reference files! ' 240 print ('Excess reference files! '
232 '(probably cruft from renaming or deleting):\n' + 241 '(probably cruft from renaming or deleting):\n' +
233 '\n'.join(excess_files)) 242 '\n'.join(excess_files))
234 return False 243 return False
235 return True 244 return True
236 245
237 try: 246 try:
238 generate_interface_dependencies() 247 generate_interface_dependencies(output_directory)
239 for component in COMPONENT_DIRECTORY: 248 for component in COMPONENT_DIRECTORY:
240 output_dir = os.path.join(output_directory, component) 249 output_dir = os.path.join(output_directory, component)
241 if not os.path.exists(output_dir): 250 if not os.path.exists(output_dir):
242 os.makedirs(output_dir) 251 os.makedirs(output_dir)
243 252
244 idl_compiler = IdlCompilerV8(output_dir, 253 idl_compiler = IdlCompilerV8(output_dir,
245 interfaces_info=interfaces_info, 254 interfaces_info=interfaces_info,
246 only_if_changed=True) 255 only_if_changed=True)
247 if component == 'core': 256 if component == 'core':
248 partial_interface_output_dir = os.path.join(output_directory, 257 partial_interface_output_dir = os.path.join(output_directory,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 311
303 312
304 def run_bindings_tests(reset_results, verbose): 313 def run_bindings_tests(reset_results, verbose):
305 # Generate output into the reference directory if resetting results, or 314 # Generate output into the reference directory if resetting results, or
306 # a temp directory if not. 315 # a temp directory if not.
307 if reset_results: 316 if reset_results:
308 print 'Resetting results' 317 print 'Resetting results'
309 return bindings_tests(reference_directory, verbose) 318 return bindings_tests(reference_directory, verbose)
310 with TemporaryDirectory() as temp_dir: 319 with TemporaryDirectory() as temp_dir:
311 return bindings_tests(temp_dir, verbose) 320 return bindings_tests(temp_dir, verbose)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698