OLD | NEW |
1 # Copyright (C) 2013 Google Inc. All rights reserved. | 1 # Copyright (C) 2013 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 are | 4 # modification, are permitted provided that the following conditions are |
5 # met: | 5 # met: |
6 # | 6 # |
7 # * Redistributions of source code must retain the above copyright | 7 # * Redistributions of source code must retain the above copyright |
8 # notice, this list of conditions and the following disclaimer. | 8 # notice, this list of conditions and the following disclaimer. |
9 # * Redistributions in binary form must reproduce the above | 9 # * Redistributions in binary form must reproduce the above |
10 # copyright notice, this list of conditions and the following disclaimer | 10 # copyright notice, this list of conditions and the following disclaimer |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 def initialize_jinja_env(cache_dir): | 390 def initialize_jinja_env(cache_dir): |
391 jinja_env = jinja2.Environment( | 391 jinja_env = jinja2.Environment( |
392 loader=jinja2.FileSystemLoader(templates_dir), | 392 loader=jinja2.FileSystemLoader(templates_dir), |
393 # Bytecode cache is not concurrency-safe unless pre-cached: | 393 # Bytecode cache is not concurrency-safe unless pre-cached: |
394 # if pre-cached this is read-only, but writing creates a race condition. | 394 # if pre-cached this is read-only, but writing creates a race condition. |
395 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), | 395 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), |
396 keep_trailing_newline=True, # newline-terminate generated files | 396 keep_trailing_newline=True, # newline-terminate generated files |
397 lstrip_blocks=True, # so can indent control flow tags | 397 lstrip_blocks=True, # so can indent control flow tags |
398 trim_blocks=True) | 398 trim_blocks=True) |
399 jinja_env.filters.update({ | 399 jinja_env.filters.update({ |
| 400 'api_experiment_enabled': api_experiment_enabled_if, |
400 'blink_capitalize': capitalize, | 401 'blink_capitalize': capitalize, |
401 'conditional': conditional_if_endif, | 402 'conditional': conditional_if_endif, |
| 403 'experimental_framework_runtime_enabled': experimental_framework_runtime
_enabled_if, |
402 'exposed': exposed_if, | 404 'exposed': exposed_if, |
403 'runtime_enabled': runtime_enabled_if, | 405 'runtime_enabled': runtime_enabled_if, |
404 }) | 406 }) |
405 return jinja_env | 407 return jinja_env |
406 | 408 |
407 | 409 |
408 def generate_indented_conditional(code, conditional): | 410 def generate_indented_conditional(code, conditional): |
409 # Indent if statement to level of original code | 411 # Indent if statement to level of original code |
410 indent = re.match(' *', code).group(0) | 412 indent = re.match(' *', code).group(0) |
411 return ('%sif (%s) {\n' % (indent, conditional) + | 413 return ('%sif (%s) {\n' % (indent, conditional) + |
(...skipping 18 matching lines...) Expand all Loading... |
430 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) | 432 return generate_indented_conditional(code, 'executionContext && (%s)' % expo
sed_test) |
431 | 433 |
432 | 434 |
433 # [RuntimeEnabled] | 435 # [RuntimeEnabled] |
434 def runtime_enabled_if(code, runtime_enabled_function_name): | 436 def runtime_enabled_if(code, runtime_enabled_function_name): |
435 if not runtime_enabled_function_name: | 437 if not runtime_enabled_function_name: |
436 return code | 438 return code |
437 return generate_indented_conditional(code, '%s()' % runtime_enabled_function
_name) | 439 return generate_indented_conditional(code, '%s()' % runtime_enabled_function
_name) |
438 | 440 |
439 | 441 |
| 442 # [APIExperimentEnabled] |
| 443 def api_experiment_enabled_if(code, api_experiment_name, error_message=None): |
| 444 if not api_experiment_name: |
| 445 return code |
| 446 if error_message: |
| 447 conditional = 'Experiments::isApiEnabled(currentExecutionContext(isolate
), "%s", %s)' % (api_experiment_name, error_message) |
| 448 else: |
| 449 conditional = 'Experiments::isApiEnabledWithoutMessage(currentExecutionC
ontext(isolate), "%s")' % api_experiment_name |
| 450 return generate_indented_conditional(code, conditional) |
| 451 |
| 452 |
| 453 def experimental_framework_runtime_enabled_if(code, api_experiment_name): |
| 454 if not api_experiment_name: |
| 455 return code |
| 456 return generate_indented_conditional(code, "RuntimeEnabledFeatures::experime
ntalFrameworkEnabled()") |
| 457 |
440 ################################################################################ | 458 ################################################################################ |
441 | 459 |
442 def main(argv): | 460 def main(argv): |
443 # If file itself executed, cache templates | 461 # If file itself executed, cache templates |
444 try: | 462 try: |
445 cache_dir = argv[1] | 463 cache_dir = argv[1] |
446 dummy_filename = argv[2] | 464 dummy_filename = argv[2] |
447 except IndexError as err: | 465 except IndexError as err: |
448 print 'Usage: %s CACHE_DIR DUMMY_FILENAME' % argv[0] | 466 print 'Usage: %s CACHE_DIR DUMMY_FILENAME' % argv[0] |
449 return 1 | 467 return 1 |
450 | 468 |
451 # Cache templates | 469 # Cache templates |
452 jinja_env = initialize_jinja_env(cache_dir) | 470 jinja_env = initialize_jinja_env(cache_dir) |
453 template_filenames = [filename for filename in os.listdir(templates_dir) | 471 template_filenames = [filename for filename in os.listdir(templates_dir) |
454 # Skip .svn, directories, etc. | 472 # Skip .svn, directories, etc. |
455 if filename.endswith(('.cpp', '.h'))] | 473 if filename.endswith(('.cpp', '.h'))] |
456 for template_filename in template_filenames: | 474 for template_filename in template_filenames: |
457 jinja_env.get_template(template_filename) | 475 jinja_env.get_template(template_filename) |
458 | 476 |
459 # Create a dummy file as output for the build system, | 477 # Create a dummy file as output for the build system, |
460 # since filenames of individual cache files are unpredictable and opaque | 478 # since filenames of individual cache files are unpredictable and opaque |
461 # (they are hashes of the template path, which varies based on environment) | 479 # (they are hashes of the template path, which varies based on environment) |
462 with open(dummy_filename, 'w') as dummy_file: | 480 with open(dummy_filename, 'w') as dummy_file: |
463 pass # |open| creates or touches the file | 481 pass # |open| creates or touches the file |
464 | 482 |
465 | 483 |
466 if __name__ == '__main__': | 484 if __name__ == '__main__': |
467 sys.exit(main(sys.argv)) | 485 sys.exit(main(sys.argv)) |
OLD | NEW |