| OLD | NEW |
| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 # core/inspector/InspectorInstrumentation.idl is not a valid Blink IDL. | 74 # core/inspector/InspectorInstrumentation.idl is not a valid Blink IDL. |
| 75 NON_BLINK_IDL_FILES = frozenset([ | 75 NON_BLINK_IDL_FILES = frozenset([ |
| 76 'InspectorInstrumentation.idl', | 76 'InspectorInstrumentation.idl', |
| 77 ]) | 77 ]) |
| 78 | 78 |
| 79 COMPONENT_DIRECTORY = frozenset(['core', 'modules']) | 79 COMPONENT_DIRECTORY = frozenset(['core', 'modules']) |
| 80 | 80 |
| 81 test_input_directory = os.path.join(source_path, 'bindings', 'tests', 'idls') | 81 test_input_directory = os.path.join(source_path, 'bindings', 'tests', 'idls') |
| 82 reference_directory = os.path.join(source_path, 'bindings', 'tests', 'results') | 82 reference_directory = os.path.join(source_path, 'bindings', 'tests', 'results') |
| 83 | 83 |
| 84 # component -> set of union types | 84 # component -> component_info. |
| 85 union_types = {} | 85 # Note that this dict contains information about testing idl files, which live |
| 86 # in Source/bindings/tests/idls/{core,modules}, not in Source/{core,modules}. |
| 87 test_component_info = {} |
| 86 | 88 |
| 87 @contextmanager | 89 @contextmanager |
| 88 def TemporaryDirectory(): | 90 def TemporaryDirectory(): |
| 89 """Wrapper for tempfile.mkdtemp() so it's usable with 'with' statement. | 91 """Wrapper for tempfile.mkdtemp() so it's usable with 'with' statement. |
| 90 | 92 |
| 91 Simple backport of tempfile.TemporaryDirectory from Python 3.2. | 93 Simple backport of tempfile.TemporaryDirectory from Python 3.2. |
| 92 """ | 94 """ |
| 93 name = tempfile.mkdtemp() | 95 name = tempfile.mkdtemp() |
| 94 try: | 96 try: |
| 95 yield name | 97 yield name |
| (...skipping 30 matching lines...) Expand all Loading... |
| 126 info_collector.collect_info(idl_path) | 128 info_collector.collect_info(idl_path) |
| 127 info = info_collector.get_info_as_dict() | 129 info = info_collector.get_info_as_dict() |
| 128 # TestDictionary.{h,cpp} are placed under | 130 # TestDictionary.{h,cpp} are placed under |
| 129 # Source/bindings/tests/idls/core. However, IdlCompiler generates | 131 # Source/bindings/tests/idls/core. However, IdlCompiler generates |
| 130 # TestDictionary.{h,cpp} by using relative_dir. | 132 # TestDictionary.{h,cpp} by using relative_dir. |
| 131 # So the files will be generated under | 133 # So the files will be generated under |
| 132 # output_dir/core/bindings/tests/idls/core. | 134 # output_dir/core/bindings/tests/idls/core. |
| 133 # To avoid this issue, we need to clear relative_dir here. | 135 # To avoid this issue, we need to clear relative_dir here. |
| 134 for value in info['interfaces_info'].itervalues(): | 136 for value in info['interfaces_info'].itervalues(): |
| 135 value['relative_dir'] = '' | 137 value['relative_dir'] = '' |
| 136 # Merge component-wide information. | |
| 137 component_info = info_collector.get_component_info_as_dict() | 138 component_info = info_collector.get_component_info_as_dict() |
| 138 info.update(component_info) | 139 return info, component_info |
| 139 return info | |
| 140 | 140 |
| 141 # We compute interfaces info for *all* IDL files, not just test IDL | 141 # We compute interfaces info for *all* IDL files, not just test IDL |
| 142 # files, as code generator output depends on inheritance (both ancestor | 142 # files, as code generator output depends on inheritance (both ancestor |
| 143 # chain and inherited extended attributes), and some real interfaces | 143 # chain and inherited extended attributes), and some real interfaces |
| 144 # are special-cased, such as Node. | 144 # are special-cased, such as Node. |
| 145 # | 145 # |
| 146 # For example, when testing the behavior of interfaces that inherit | 146 # For example, when testing the behavior of interfaces that inherit |
| 147 # from Node, we also need to know that these inherit from EventTarget, | 147 # from Node, we also need to know that these inherit from EventTarget, |
| 148 # since this is also special-cased and Node inherits from EventTarget, | 148 # since this is also special-cased and Node inherits from EventTarget, |
| 149 # but this inheritance information requires computing dependencies for | 149 # but this inheritance information requires computing dependencies for |
| 150 # the real Node.idl file. | 150 # the real Node.idl file. |
| 151 non_test_idl_paths = collect_blink_idl_paths() | 151 non_test_idl_paths = collect_blink_idl_paths() |
| 152 # For bindings test IDL files, we collect interfaces info for each | 152 # For bindings test IDL files, we collect interfaces info for each |
| 153 # component so that we can generate union type containers separately. | 153 # component so that we can generate union type containers separately. |
| 154 test_idl_paths = {} | 154 test_idl_paths = {} |
| 155 for component in COMPONENT_DIRECTORY: | 155 for component in COMPONENT_DIRECTORY: |
| 156 test_idl_paths[component] = idl_paths_recursive( | 156 test_idl_paths[component] = idl_paths_recursive( |
| 157 os.path.join(test_input_directory, component)) | 157 os.path.join(test_input_directory, component)) |
| 158 # 2nd-stage computation: individual, then overall | 158 # 2nd-stage computation: individual, then overall |
| 159 # | 159 # |
| 160 # Properly should compute separately by component (currently test | 160 # Properly should compute separately by component (currently test |
| 161 # includes are invalid), but that's brittle (would need to update this file | 161 # includes are invalid), but that's brittle (would need to update this file |
| 162 # for each new component) and doesn't test the code generator any better | 162 # for each new component) and doesn't test the code generator any better |
| 163 # than using a single component. | 163 # than using a single component. |
| 164 non_test_interfaces_info = collect_interfaces_info(non_test_idl_paths) | 164 non_test_interfaces_info, non_test_component_info = collect_interfaces_info(
non_test_idl_paths) |
| 165 test_interfaces_info = {} | 165 test_interfaces_info = {} |
| 166 for component, paths in test_idl_paths.iteritems(): | 166 for component, paths in test_idl_paths.iteritems(): |
| 167 test_interfaces_info[component] = collect_interfaces_info(paths) | 167 test_interfaces_info[component], test_component_info[component] = collec
t_interfaces_info(paths) |
| 168 # In order to allow test IDL files to override the production IDL files if | 168 # In order to allow test IDL files to override the production IDL files if |
| 169 # they have the same interface name, process the test IDL files after the | 169 # they have the same interface name, process the test IDL files after the |
| 170 # non-test IDL files. | 170 # non-test IDL files. |
| 171 info_individuals = [non_test_interfaces_info] + test_interfaces_info.values(
) | 171 info_individuals = [non_test_interfaces_info] + test_interfaces_info.values(
) |
| 172 compute_interfaces_info_overall(info_individuals) | 172 compute_interfaces_info_overall(info_individuals) |
| 173 # 3rd-stage: union types | |
| 174 # We only process union types which are defined under | |
| 175 # Source/bindings/tests/idls. Otherwise, the result of union type | |
| 176 # container classes will be affected by non-test IDL files. | |
| 177 for component, interfaces_info in test_interfaces_info.iteritems(): | |
| 178 union_types[component] = interfaces_info['union_types'] | |
| 179 | 173 |
| 180 | 174 |
| 181 def bindings_tests(output_directory, verbose): | 175 def bindings_tests(output_directory, verbose): |
| 182 executive = Executive() | 176 executive = Executive() |
| 183 | 177 |
| 184 def list_files(directory): | 178 def list_files(directory): |
| 185 files = [] | 179 files = [] |
| 186 for component in os.listdir(directory): | 180 for component in os.listdir(directory): |
| 187 if component not in COMPONENT_DIRECTORY: | 181 if component not in COMPONENT_DIRECTORY: |
| 188 continue | 182 continue |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 print ('Excess reference files! ' | 251 print ('Excess reference files! ' |
| 258 '(probably cruft from renaming or deleting):\n' + | 252 '(probably cruft from renaming or deleting):\n' + |
| 259 '\n'.join(excess_files)) | 253 '\n'.join(excess_files)) |
| 260 return False | 254 return False |
| 261 return True | 255 return True |
| 262 | 256 |
| 263 def generate_union_type_containers(output_directory, component): | 257 def generate_union_type_containers(output_directory, component): |
| 264 generator = CodeGeneratorUnionType( | 258 generator = CodeGeneratorUnionType( |
| 265 interfaces_info, cache_dir=None, output_dir=output_directory, | 259 interfaces_info, cache_dir=None, output_dir=output_directory, |
| 266 target_component=component) | 260 target_component=component) |
| 267 outputs = generator.generate_code(union_types[component]) | 261 outputs = generator.generate_code( |
| 262 test_component_info[component]['union_types']) |
| 268 for output_path, output_code in outputs: | 263 for output_path, output_code in outputs: |
| 269 write_file(output_code, output_path, only_if_changed=True) | 264 write_file(output_code, output_path, only_if_changed=True) |
| 270 | 265 |
| 271 try: | 266 try: |
| 272 generate_interface_dependencies(output_directory) | 267 generate_interface_dependencies(output_directory) |
| 273 for component in COMPONENT_DIRECTORY: | 268 for component in COMPONENT_DIRECTORY: |
| 274 output_dir = os.path.join(output_directory, component) | 269 output_dir = os.path.join(output_directory, component) |
| 275 if not os.path.exists(output_dir): | 270 if not os.path.exists(output_dir): |
| 276 os.makedirs(output_dir) | 271 os.makedirs(output_dir) |
| 277 | 272 |
| 278 generate_union_type_containers(output_dir, component) | 273 generate_union_type_containers(output_dir, component) |
| 279 | 274 |
| 280 idl_compiler = IdlCompilerV8(output_dir, | 275 idl_compiler = IdlCompilerV8(output_dir, |
| 281 interfaces_info=interfaces_info, | 276 interfaces_info=interfaces_info, |
| 277 component_info=test_component_info[comp
onent], |
| 282 only_if_changed=True) | 278 only_if_changed=True) |
| 283 if component == 'core': | 279 if component == 'core': |
| 284 partial_interface_output_dir = os.path.join(output_directory, | 280 partial_interface_output_dir = os.path.join(output_directory, |
| 285 'modules') | 281 'modules') |
| 286 if not os.path.exists(partial_interface_output_dir): | 282 if not os.path.exists(partial_interface_output_dir): |
| 287 os.makedirs(partial_interface_output_dir) | 283 os.makedirs(partial_interface_output_dir) |
| 288 idl_partial_interface_compiler = IdlCompilerV8( | 284 idl_partial_interface_compiler = IdlCompilerV8( |
| 289 partial_interface_output_dir, | 285 partial_interface_output_dir, |
| 290 interfaces_info=interfaces_info, | 286 interfaces_info=interfaces_info, |
| 287 component_info=test_component_info[component], |
| 291 only_if_changed=True, | 288 only_if_changed=True, |
| 292 target_component='modules') | 289 target_component='modules') |
| 293 else: | 290 else: |
| 294 idl_partial_interface_compiler = None | 291 idl_partial_interface_compiler = None |
| 295 | 292 |
| 296 dictionary_impl_compiler = IdlCompilerDictionaryImpl( | 293 dictionary_impl_compiler = IdlCompilerDictionaryImpl( |
| 297 output_dir, interfaces_info=interfaces_info, | 294 output_dir, interfaces_info=interfaces_info, |
| 295 component_info=test_component_info[component], |
| 298 only_if_changed=True) | 296 only_if_changed=True) |
| 299 | 297 |
| 300 idl_filenames = [] | 298 idl_filenames = [] |
| 301 input_directory = os.path.join(test_input_directory, component) | 299 input_directory = os.path.join(test_input_directory, component) |
| 302 for filename in os.listdir(input_directory): | 300 for filename in os.listdir(input_directory): |
| 303 if (filename.endswith('.idl') and | 301 if (filename.endswith('.idl') and |
| 304 # Dependencies aren't built | 302 # Dependencies aren't built |
| 305 # (they are used by the dependent) | 303 # (they are used by the dependent) |
| 306 filename not in DEPENDENCY_IDL_FILES): | 304 filename not in DEPENDENCY_IDL_FILES): |
| 307 idl_filenames.append( | 305 idl_filenames.append( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 338 | 336 |
| 339 | 337 |
| 340 def run_bindings_tests(reset_results, verbose): | 338 def run_bindings_tests(reset_results, verbose): |
| 341 # Generate output into the reference directory if resetting results, or | 339 # Generate output into the reference directory if resetting results, or |
| 342 # a temp directory if not. | 340 # a temp directory if not. |
| 343 if reset_results: | 341 if reset_results: |
| 344 print 'Resetting results' | 342 print 'Resetting results' |
| 345 return bindings_tests(reference_directory, verbose) | 343 return bindings_tests(reference_directory, verbose) |
| 346 with TemporaryDirectory() as temp_dir: | 344 with TemporaryDirectory() as temp_dir: |
| 347 return bindings_tests(temp_dir, verbose) | 345 return bindings_tests(temp_dir, verbose) |
| OLD | NEW |