| OLD | NEW |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # pylint: disable=import-error,print-statement,relative-import | 5 # pylint: disable=import-error,print-statement,relative-import |
| 6 | 6 |
| 7 """Plumbing for a Jinja-based code generator, including CodeGeneratorBase, a bas
e class for all generators.""" | 7 """Plumbing for a Jinja-based code generator, including CodeGeneratorBase, a bas
e class for all generators.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import posixpath | 10 import posixpath |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if not secure_context_test: | 62 if not secure_context_test: |
| 63 return code | 63 return code |
| 64 return generate_indented_conditional(code, 'executionContext && (%s)' % secu
re_context_test) | 64 return generate_indented_conditional(code, 'executionContext && (%s)' % secu
re_context_test) |
| 65 | 65 |
| 66 | 66 |
| 67 # [RuntimeEnabled] | 67 # [RuntimeEnabled] |
| 68 def runtime_enabled_if(code, name): | 68 def runtime_enabled_if(code, name): |
| 69 if not name: | 69 if not name: |
| 70 return code | 70 return code |
| 71 | 71 |
| 72 function = 'RuntimeEnabledFeatures::%sEnabled()' % v8_utilities.uncapitalize
(name) | 72 function = v8_utilities.runtime_enabled_function(name) |
| 73 return generate_indented_conditional(code, function) | 73 return generate_indented_conditional(code, function) |
| 74 | 74 |
| 75 | 75 |
| 76 def initialize_jinja_env(cache_dir): | 76 def initialize_jinja_env(cache_dir): |
| 77 jinja_env = jinja2.Environment( | 77 jinja_env = jinja2.Environment( |
| 78 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), | 78 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), |
| 79 # Bytecode cache is not concurrency-safe unless pre-cached: | 79 # Bytecode cache is not concurrency-safe unless pre-cached: |
| 80 # if pre-cached this is read-only, but writing creates a race condition. | 80 # if pre-cached this is read-only, but writing creates a race condition. |
| 81 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), | 81 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), |
| 82 keep_trailing_newline=True, # newline-terminate generated files | 82 keep_trailing_newline=True, # newline-terminate generated files |
| 83 lstrip_blocks=True, # so can indent control flow tags | 83 lstrip_blocks=True, # so can indent control flow tags |
| 84 trim_blocks=True) | 84 trim_blocks=True) |
| 85 jinja_env.filters.update({ | 85 jinja_env.filters.update({ |
| 86 'blink_capitalize': capitalize, | 86 'blink_capitalize': capitalize, |
| 87 'exposed': exposed_if, | 87 'exposed': exposed_if, |
| 88 'format_blink_cpp_source_code': format_blink_cpp_source_code, | 88 'format_blink_cpp_source_code': format_blink_cpp_source_code, |
| 89 'format_remove_duplicates': format_remove_duplicates, | 89 'format_remove_duplicates': format_remove_duplicates, |
| 90 'runtime_enabled': runtime_enabled_if, | 90 'runtime_enabled': runtime_enabled_if, |
| 91 'runtime_enabled_function': v8_utilities.runtime_enabled_function, |
| 91 'secure_context': secure_context_if, | 92 'secure_context': secure_context_if, |
| 92 'unique_by': unique_by}) | 93 'unique_by': unique_by}) |
| 93 jinja_env.filters.update(constant_filters()) | 94 jinja_env.filters.update(constant_filters()) |
| 94 jinja_env.filters.update(method_filters()) | 95 jinja_env.filters.update(method_filters()) |
| 95 return jinja_env | 96 return jinja_env |
| 96 | 97 |
| 97 | 98 |
| 98 def normalize_and_sort_includes(include_paths): | 99 def normalize_and_sort_includes(include_paths): |
| 99 normalized_include_paths = [] | 100 normalized_include_paths = [] |
| 100 for include_path in include_paths: | 101 for include_path in include_paths: |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 184 |
| 184 # Create a dummy file as output for the build system, | 185 # Create a dummy file as output for the build system, |
| 185 # since filenames of individual cache files are unpredictable and opaque | 186 # since filenames of individual cache files are unpredictable and opaque |
| 186 # (they are hashes of the template path, which varies based on environment) | 187 # (they are hashes of the template path, which varies based on environment) |
| 187 with open(dummy_filename, 'w') as dummy_file: | 188 with open(dummy_filename, 'w') as dummy_file: |
| 188 pass # |open| creates or touches the file | 189 pass # |open| creates or touches the file |
| 189 | 190 |
| 190 | 191 |
| 191 if __name__ == '__main__': | 192 if __name__ == '__main__': |
| 192 sys.exit(main(sys.argv)) | 193 sys.exit(main(sys.argv)) |
| OLD | NEW |