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

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: 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 49
49 50
50 PASS_MESSAGE = 'All tests PASS!' 51 PASS_MESSAGE = 'All tests PASS!'
51 FAIL_MESSAGE = """Some tests FAIL! 52 FAIL_MESSAGE = """Some tests FAIL!
52 To update the reference files, execute: 53 To update the reference files, execute:
53 run-bindings-tests --reset-results 54 run-bindings-tests --reset-results
54 55
55 If the failures are not due to your changes, test results may be out of sync; 56 If the failures are not due to your changes, test results may be out of sync;
56 please rebaseline them in a separate CL, after checking that tests fail in ToT. 57 please rebaseline them in a separate CL, after checking that tests fail in ToT.
57 In CL, please set: 58 In CL, please set:
58 NOTRY=true 59 NOTRY=true
59 TBR=(someone in Source/bindings/OWNERS or WATCHLISTS:bindings) 60 TBR=(someone in Source/bindings/OWNERS or WATCHLISTS:bindings)
60 """ 61 """
61 62
62 DEPENDENCY_IDL_FILES = frozenset([ 63 DEPENDENCY_IDL_FILES = frozenset([
63 'TestImplements.idl', 64 'TestImplements.idl',
64 'TestImplements2.idl', 65 'TestImplements2.idl',
65 'TestImplements3.idl', 66 'TestImplements3.idl',
66 'TestPartialInterface.idl', 67 'TestPartialInterface.idl',
67 'TestPartialInterface2.idl', 68 'TestPartialInterface2.idl',
68 'TestPartialInterface3.idl', 69 'TestPartialInterface3.idl',
69 ]) 70 ])
70 71
72 # core/inspector/InspectorInstrumentation.idl is not a valid Blink IDL.
73 NON_BLINK_IDL_FILES = frozenset([
74 'InspectorInstrumentation.idl',
75 ])
76
71 COMPONENT_DIRECTORY = frozenset(['core', 'modules']) 77 COMPONENT_DIRECTORY = frozenset(['core', 'modules'])
72 78
73 test_input_directory = os.path.join(source_path, 'bindings', 'tests', 'idls') 79 test_input_directory = os.path.join(source_path, 'bindings', 'tests', 'idls')
74 reference_directory = os.path.join(source_path, 'bindings', 'tests', 'results') 80 reference_directory = os.path.join(source_path, 'bindings', 'tests', 'results')
75 81
76 PLY_LEX_YACC_FILES = frozenset([ 82 PLY_LEX_YACC_FILES = frozenset([
77 'lextab.py', # PLY lex 83 'lextab.py', # PLY lex
78 'lextab.pyc', 84 'lextab.pyc',
79 'parsetab.pickle', # PLY yacc 85 'parsetab.pickle', # PLY yacc
80 ]) 86 ])
81 87
82 @contextmanager 88 @contextmanager
83 def TemporaryDirectory(): 89 def TemporaryDirectory():
84 """Wrapper for tempfile.mkdtemp() so it's usable with 'with' statement. 90 """Wrapper for tempfile.mkdtemp() so it's usable with 'with' statement.
85 91
86 Simple backport of tempfile.TemporaryDirectory from Python 3.2. 92 Simple backport of tempfile.TemporaryDirectory from Python 3.2.
87 """ 93 """
88 name = tempfile.mkdtemp() 94 name = tempfile.mkdtemp()
89 try: 95 try:
90 yield name 96 yield name
91 finally: 97 finally:
92 shutil.rmtree(name) 98 shutil.rmtree(name)
93 99
94 100
95 def generate_interface_dependencies(): 101 def generate_interface_dependencies(output_directory):
96 def idl_paths_recursive(directory): 102 def idl_paths_recursive(directory):
97 # This is slow, especially on Windows, due to os.walk making 103 # This is slow, especially on Windows, due to os.walk making
98 # excess stat() calls. Faster versions may appear in Python 3.5 or 104 # excess stat() calls. Faster versions may appear in Python 3.5 or
99 # later: 105 # later:
100 # https://github.com/benhoyt/scandir 106 # https://github.com/benhoyt/scandir
101 # http://bugs.python.org/issue11406 107 # http://bugs.python.org/issue11406
102 idl_paths = [] 108 idl_paths = []
103 for dirpath, _, files in os.walk(directory): 109 for dirpath, _, files in os.walk(directory):
104 idl_paths.extend(os.path.join(dirpath, filename) 110 idl_paths.extend(os.path.join(dirpath, filename)
105 for filename in fnmatch.filter(files, '*.idl')) 111 for filename in fnmatch.filter(files, '*.idl'))
106 return idl_paths 112 return idl_paths
107 113
108 # We compute interfaces info for *all* IDL files, not just test IDL 114 # We compute interfaces info for *all* IDL files, not just test IDL
109 # files, as code generator output depends on inheritance (both ancestor 115 # files, as code generator output depends on inheritance (both ancestor
110 # chain and inherited extended attributes), and some real interfaces 116 # chain and inherited extended attributes), and some real interfaces
111 # are special-cased, such as Node. 117 # are special-cased, such as Node.
112 # 118 #
113 # For example, when testing the behavior of interfaces that inherit 119 # For example, when testing the behavior of interfaces that inherit
114 # from Node, we also need to know that these inherit from EventTarget, 120 # from Node, we also need to know that these inherit from EventTarget,
115 # since this is also special-cased and Node inherits from EventTarget, 121 # since this is also special-cased and Node inherits from EventTarget,
116 # but this inheritance information requires computing dependencies for 122 # but this inheritance information requires computing dependencies for
117 # the real Node.idl file. 123 # the real Node.idl file.
118 124
119 # 2-stage computation: individual, then overall 125 # 2-stage computation: individual, then overall
120 # 126 #
121 # Properly should compute separately by component (currently test 127 # Properly should compute separately by component (currently test
122 # includes are invalid), but that's brittle (would need to update this file 128 # includes are invalid), but that's brittle (would need to update this file
123 # for each new component) and doesn't test the code generator any better 129 # for each new component) and doesn't test the code generator any better
124 # than using a single component. 130 # than using a single component.
131 reader = IdlReader(outputdir=output_directory)
125 for idl_filename in idl_paths_recursive(source_path): 132 for idl_filename in idl_paths_recursive(source_path):
126 compute_info_individual(idl_filename) 133 if os.path.basename(idl_filename) in NON_BLINK_IDL_FILES:
134 continue
135 compute_info_individual(idl_filename, reader)
127 info_individuals = [info_individual()] 136 info_individuals = [info_individual()]
128 # TestDictionary.{h,cpp} are placed under Source/bindings/tests/idls/core. 137 # TestDictionary.{h,cpp} are placed under Source/bindings/tests/idls/core.
129 # However, IdlCompiler generates TestDictionary.{h,cpp} by using relative_di r. 138 # However, IdlCompiler generates TestDictionary.{h,cpp} by using relative_di r.
130 # So the files will be generated under output_dir/core/bindings/tests/idls/c ore. 139 # So the files will be generated under output_dir/core/bindings/tests/idls/c ore.
131 # To avoid this issue, we need to clear relative_dir here. 140 # To avoid this issue, we need to clear relative_dir here.
132 for info in info_individuals: 141 for info in info_individuals:
133 for value in info['interfaces_info'].itervalues(): 142 for value in info['interfaces_info'].itervalues():
134 value['relative_dir'] = '' 143 value['relative_dir'] = ''
135 compute_interfaces_info_overall(info_individuals) 144 compute_interfaces_info_overall(info_individuals)
136 145
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 if relpath not in generated_files: 224 if relpath not in generated_files:
216 excess_files.append(relpath) 225 excess_files.append(relpath)
217 if excess_files: 226 if excess_files:
218 print ('Excess reference files! ' 227 print ('Excess reference files! '
219 '(probably cruft from renaming or deleting):\n' + 228 '(probably cruft from renaming or deleting):\n' +
220 '\n'.join(excess_files)) 229 '\n'.join(excess_files))
221 return False 230 return False
222 return True 231 return True
223 232
224 try: 233 try:
225 generate_interface_dependencies() 234 generate_interface_dependencies(output_directory)
226 for component in COMPONENT_DIRECTORY: 235 for component in COMPONENT_DIRECTORY:
227 output_dir = os.path.join(output_directory, component) 236 output_dir = os.path.join(output_directory, component)
228 if not os.path.exists(output_dir): 237 if not os.path.exists(output_dir):
229 os.makedirs(output_dir) 238 os.makedirs(output_dir)
230 239
231 idl_compiler = IdlCompilerV8(output_dir, 240 idl_compiler = IdlCompilerV8(output_dir,
232 interfaces_info=interfaces_info, 241 interfaces_info=interfaces_info,
233 only_if_changed=True) 242 only_if_changed=True)
234 dictionary_impl_compiler = IdlCompilerDictionaryImpl( 243 dictionary_impl_compiler = IdlCompilerDictionaryImpl(
235 output_dir, interfaces_info=interfaces_info, 244 output_dir, interfaces_info=interfaces_info,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 281
273 282
274 def run_bindings_tests(reset_results, verbose): 283 def run_bindings_tests(reset_results, verbose):
275 # Generate output into the reference directory if resetting results, or 284 # Generate output into the reference directory if resetting results, or
276 # a temp directory if not. 285 # a temp directory if not.
277 if reset_results: 286 if reset_results:
278 print 'Resetting results' 287 print 'Resetting results'
279 return bindings_tests(reference_directory, verbose) 288 return bindings_tests(reference_directory, verbose)
280 with TemporaryDirectory() as temp_dir: 289 with TemporaryDirectory() as temp_dir:
281 return bindings_tests(temp_dir, verbose) 290 return bindings_tests(temp_dir, verbose)
OLDNEW
« Source/bindings/core/generated.gyp ('K') | « Source/bindings/scripts/utilities.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698