| 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 27 matching lines...) Expand all Loading... |
| 38 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir, | 38 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir, |
| 39 os.pardir, os.pardir, 'Source')) | 39 os.pardir, os.pardir, 'Source')) |
| 40 bindings_script_path = os.path.join(source_path, 'bindings', 'scripts') | 40 bindings_script_path = os.path.join(source_path, 'bindings', 'scripts') |
| 41 sys.path.append(bindings_script_path) # for Source/bindings imports | 41 sys.path.append(bindings_script_path) # for Source/bindings imports |
| 42 | 42 |
| 43 from code_generator_v8 import CodeGeneratorDictionaryImpl | 43 from code_generator_v8 import CodeGeneratorDictionaryImpl |
| 44 from code_generator_v8 import CodeGeneratorV8 | 44 from code_generator_v8 import CodeGeneratorV8 |
| 45 from code_generator_v8 import CodeGeneratorUnionType | 45 from code_generator_v8 import CodeGeneratorUnionType |
| 46 from code_generator_v8 import CodeGeneratorCallbackFunction | 46 from code_generator_v8 import CodeGeneratorCallbackFunction |
| 47 from compute_interfaces_info_individual import InterfaceInfoCollector | 47 from compute_interfaces_info_individual import InterfaceInfoCollector |
| 48 from compute_interfaces_info_overall import compute_interfaces_info_overall, int
erfaces_info | 48 from compute_interfaces_info_overall import (compute_interfaces_info_overall, |
| 49 from idl_compiler import IdlCompiler | 49 interfaces_info) |
| 50 from idl_compiler import (generate_bindings, |
| 51 generate_union_type_containers, |
| 52 generate_dictionary_impl, |
| 53 generate_callback_function_impl) |
| 50 from utilities import ComponentInfoProviderCore | 54 from utilities import ComponentInfoProviderCore |
| 51 from utilities import ComponentInfoProviderModules | 55 from utilities import ComponentInfoProviderModules |
| 52 from utilities import write_file | 56 from utilities import write_file |
| 53 | 57 |
| 54 | 58 |
| 55 PASS_MESSAGE = 'All tests PASS!' | 59 PASS_MESSAGE = 'All tests PASS!' |
| 56 FAIL_MESSAGE = """Some tests FAIL! | 60 FAIL_MESSAGE = """Some tests FAIL! |
| 57 To update the reference files, execute: | 61 To update the reference files, execute: |
| 58 run-bindings-tests --reset-results | 62 run-bindings-tests --reset-results |
| 59 | 63 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 # component info. | 186 # component info. |
| 183 test_component_info['core']['typedefs'].update( | 187 test_component_info['core']['typedefs'].update( |
| 184 non_test_component_info['typedefs']) | 188 non_test_component_info['typedefs']) |
| 185 component_info_providers['core'] = ComponentInfoProviderCore( | 189 component_info_providers['core'] = ComponentInfoProviderCore( |
| 186 interfaces_info, test_component_info['core']) | 190 interfaces_info, test_component_info['core']) |
| 187 component_info_providers['modules'] = ComponentInfoProviderModules( | 191 component_info_providers['modules'] = ComponentInfoProviderModules( |
| 188 interfaces_info, test_component_info['core'], | 192 interfaces_info, test_component_info['core'], |
| 189 test_component_info['modules']) | 193 test_component_info['modules']) |
| 190 | 194 |
| 191 | 195 |
| 196 class IdlCompilerOptions(object): |
| 197 def __init__(self, output_directory, cache_directory, impl_output_directory, |
| 198 target_component): |
| 199 self.output_directory = output_directory |
| 200 self.cache_directory = cache_directory |
| 201 self.impl_output_directory = impl_output_directory |
| 202 self.target_component = target_component |
| 203 |
| 192 def bindings_tests(output_directory, verbose): | 204 def bindings_tests(output_directory, verbose): |
| 193 executive = Executive() | 205 executive = Executive() |
| 194 | 206 |
| 195 def list_files(directory): | 207 def list_files(directory): |
| 196 files = [] | 208 files = [] |
| 197 for component in os.listdir(directory): | 209 for component in os.listdir(directory): |
| 198 if component not in COMPONENT_DIRECTORY: | 210 if component not in COMPONENT_DIRECTORY: |
| 199 continue | 211 continue |
| 200 directory_with_component = os.path.join(directory, component) | 212 directory_with_component = os.path.join(directory, component) |
| 201 for filename in os.listdir(directory_with_component): | 213 for filename in os.listdir(directory_with_component): |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 relpath = os.path.relpath(path, reference_directory) | 276 relpath = os.path.relpath(path, reference_directory) |
| 265 if relpath not in generated_files: | 277 if relpath not in generated_files: |
| 266 excess_files.append(relpath) | 278 excess_files.append(relpath) |
| 267 if excess_files: | 279 if excess_files: |
| 268 print ('Excess reference files! ' | 280 print ('Excess reference files! ' |
| 269 '(probably cruft from renaming or deleting):\n' + | 281 '(probably cruft from renaming or deleting):\n' + |
| 270 '\n'.join(excess_files)) | 282 '\n'.join(excess_files)) |
| 271 return False | 283 return False |
| 272 return True | 284 return True |
| 273 | 285 |
| 274 def generate_union_type_containers(output_directory, component): | |
| 275 generator = CodeGeneratorUnionType( | |
| 276 component_info_providers[component], cache_dir=None, | |
| 277 output_dir=output_directory, target_component=component) | |
| 278 outputs = generator.generate_code() | |
| 279 for output_path, output_code in outputs: | |
| 280 write_file(output_code, output_path) | |
| 281 | |
| 282 def generate_callback_function_impl(output_directory, component): | |
| 283 generator = CodeGeneratorCallbackFunction( | |
| 284 component_info_providers[component], cache_dir=None, | |
| 285 output_dir=output_directory, target_component=component) | |
| 286 outputs = generator.generate_code() | |
| 287 for output_path, output_code in outputs: | |
| 288 write_file(output_code, output_path) | |
| 289 | |
| 290 try: | 286 try: |
| 291 generate_interface_dependencies() | 287 generate_interface_dependencies() |
| 292 for component in COMPONENT_DIRECTORY: | 288 for component in COMPONENT_DIRECTORY: |
| 293 output_dir = os.path.join(output_directory, component) | 289 output_dir = os.path.join(output_directory, component) |
| 294 if not os.path.exists(output_dir): | 290 if not os.path.exists(output_dir): |
| 295 os.makedirs(output_dir) | 291 os.makedirs(output_dir) |
| 296 | 292 |
| 297 generate_union_type_containers(output_dir, component) | 293 options = IdlCompilerOptions( |
| 298 generate_callback_function_impl(output_dir, component) | 294 output_directory=output_dir, |
| 295 impl_output_directory=output_dir, |
| 296 cache_directory=None, |
| 297 target_component=component) |
| 299 | 298 |
| 300 idl_compiler = IdlCompiler( | |
| 301 output_directory=output_dir, | |
| 302 code_generator_class=CodeGeneratorV8, | |
| 303 info_provider=component_info_providers[component], | |
| 304 target_component=component) | |
| 305 if component == 'core': | 299 if component == 'core': |
| 306 partial_interface_output_dir = os.path.join(output_directory, | 300 partial_interface_output_dir = os.path.join(output_directory, |
| 307 'modules') | 301 'modules') |
| 308 if not os.path.exists(partial_interface_output_dir): | 302 if not os.path.exists(partial_interface_output_dir): |
| 309 os.makedirs(partial_interface_output_dir) | 303 os.makedirs(partial_interface_output_dir) |
| 310 idl_partial_interface_compiler = IdlCompiler( | 304 partial_interface_options = IdlCompilerOptions( |
| 311 output_directory=partial_interface_output_dir, | 305 output_directory=partial_interface_output_dir, |
| 312 code_generator_class=CodeGeneratorV8, | 306 impl_output_directory=None, |
| 313 info_provider=component_info_providers['modules'], | 307 cache_directory=None, |
| 314 target_component='modules') | 308 target_component='modules') |
| 315 else: | |
| 316 idl_partial_interface_compiler = None | |
| 317 | |
| 318 dictionary_impl_compiler = IdlCompiler( | |
| 319 output_directory=output_dir, | |
| 320 info_provider=component_info_providers[component], | |
| 321 code_generator_class=CodeGeneratorDictionaryImpl, | |
| 322 target_component=component) | |
| 323 | 309 |
| 324 idl_filenames = [] | 310 idl_filenames = [] |
| 311 dictionary_impl_filenames = [] |
| 312 partial_interface_filenames = [] |
| 325 input_directory = os.path.join(test_input_directory, component) | 313 input_directory = os.path.join(test_input_directory, component) |
| 326 for filename in os.listdir(input_directory): | 314 for filename in os.listdir(input_directory): |
| 327 if (filename.endswith('.idl') and | 315 if (filename.endswith('.idl') and |
| 328 # Dependencies aren't built | 316 # Dependencies aren't built |
| 329 # (they are used by the dependent) | 317 # (they are used by the dependent) |
| 330 filename not in DEPENDENCY_IDL_FILES): | 318 filename not in DEPENDENCY_IDL_FILES): |
| 331 idl_filenames.append( | 319 idl_path = os.path.realpath( |
| 332 os.path.realpath( | 320 os.path.join(input_directory, filename)) |
| 333 os.path.join(input_directory, filename))) | 321 idl_filenames.append(idl_path) |
| 334 for idl_path in idl_filenames: | 322 idl_basename = os.path.basename(idl_path) |
| 335 idl_basename = os.path.basename(idl_path) | 323 definition_name, _ = os.path.splitext(idl_basename) |
| 336 idl_compiler.compile_file(idl_path) | 324 if definition_name in interfaces_info: |
| 337 definition_name, _ = os.path.splitext(idl_basename) | 325 interface_info = interfaces_info[definition_name] |
| 338 if definition_name in interfaces_info: | 326 if interface_info['is_dictionary']: |
| 339 interface_info = interfaces_info[definition_name] | 327 dictionary_impl_filenames.append(idl_path) |
| 340 if interface_info['is_dictionary']: | 328 if component == 'core' and interface_info[ |
| 341 dictionary_impl_compiler.compile_file(idl_path) | 329 'dependencies_other_component_full_paths']: |
| 342 if component == 'core' and interface_info['dependencies_othe
r_component_full_paths']: | 330 partial_interface_filenames.append(idl_path) |
| 343 idl_partial_interface_compiler.compile_file(idl_path) | 331 |
| 344 if verbose: | 332 generate_union_type_containers(CodeGeneratorUnionType, |
| 345 print 'Compiled: %s' % idl_path | 333 component_info_providers[component], |
| 334 options) |
| 335 generate_callback_function_impl(CodeGeneratorCallbackFunction, |
| 336 component_info_providers[component], |
| 337 options) |
| 338 generate_bindings( |
| 339 CodeGeneratorV8, |
| 340 component_info_providers[component], |
| 341 options, |
| 342 idl_filenames) |
| 343 generate_bindings( |
| 344 CodeGeneratorV8, |
| 345 component_info_providers['modules'], |
| 346 partial_interface_options, |
| 347 partial_interface_filenames) |
| 348 generate_dictionary_impl( |
| 349 CodeGeneratorDictionaryImpl, |
| 350 component_info_providers[component], |
| 351 options, |
| 352 dictionary_impl_filenames) |
| 353 |
| 346 finally: | 354 finally: |
| 347 delete_cache_files() | 355 delete_cache_files() |
| 348 | 356 |
| 349 # Detect all changes | 357 # Detect all changes |
| 350 output_files = list_files(output_directory) | 358 output_files = list_files(output_directory) |
| 351 passed = identical_output_files(output_files) | 359 passed = identical_output_files(output_files) |
| 352 passed &= no_excess_files(output_files) | 360 passed &= no_excess_files(output_files) |
| 353 | 361 |
| 354 if passed: | 362 if passed: |
| 355 if verbose: | 363 if verbose: |
| 356 print | 364 print |
| 357 print PASS_MESSAGE | 365 print PASS_MESSAGE |
| 358 return 0 | 366 return 0 |
| 359 print | 367 print |
| 360 print FAIL_MESSAGE | 368 print FAIL_MESSAGE |
| 361 return 1 | 369 return 1 |
| 362 | 370 |
| 363 | 371 |
| 364 def run_bindings_tests(reset_results, verbose): | 372 def run_bindings_tests(reset_results, verbose): |
| 365 # Generate output into the reference directory if resetting results, or | 373 # Generate output into the reference directory if resetting results, or |
| 366 # a temp directory if not. | 374 # a temp directory if not. |
| 367 if reset_results: | 375 if reset_results: |
| 368 print 'Resetting results' | 376 print 'Resetting results' |
| 369 return bindings_tests(reference_directory, verbose) | 377 return bindings_tests(reference_directory, verbose) |
| 370 with TemporaryDirectory() as temp_dir: | 378 with TemporaryDirectory() as temp_dir: |
| 371 return bindings_tests(temp_dir, verbose) | 379 return bindings_tests(temp_dir, verbose) |
| OLD | NEW |