| 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 |
| 11 import re | 11 import re |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 from idl_types import set_ancestors, IdlType | 14 from idl_types import set_ancestors, IdlType |
| 15 from v8_globals import includes | 15 from v8_globals import includes |
| 16 from v8_interface import constant_filters | 16 from v8_interface import constant_filters |
| 17 from v8_types import set_component_dirs | 17 from v8_types import set_component_dirs |
| 18 from v8_methods import method_filters | 18 from v8_methods import method_filters |
| 19 from v8_utilities import capitalize, for_origin_trial_feature, unique_by | 19 from v8_utilities import capitalize, unique_by |
| 20 from utilities import (idl_filename_to_component, is_valid_component_dependency, | 20 from utilities import (idl_filename_to_component, is_valid_component_dependency, |
| 21 format_remove_duplicates, format_blink_cpp_source_code) | 21 format_remove_duplicates, format_blink_cpp_source_code) |
| 22 | 22 |
| 23 # Path handling for libraries and templates | 23 # Path handling for libraries and templates |
| 24 # Paths have to be normalized because Jinja uses the exact template path to | 24 # Paths have to be normalized because Jinja uses the exact template path to |
| 25 # determine the hash used in the cache filename, and we need a pre-caching step | 25 # determine the hash used in the cache filename, and we need a pre-caching step |
| 26 # to be concurrency-safe. Use absolute path because __file__ is absolute if | 26 # to be concurrency-safe. Use absolute path because __file__ is absolute if |
| 27 # module is imported, and relative if executed directly. | 27 # module is imported, and relative if executed directly. |
| 28 # If paths differ between pre-caching and individual file compilation, the cache | 28 # If paths differ between pre-caching and individual file compilation, the cache |
| 29 # is regenerated, which causes a race condition and breaks concurrent build, | 29 # is regenerated, which causes a race condition and breaks concurrent build, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), | 75 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), |
| 76 # Bytecode cache is not concurrency-safe unless pre-cached: | 76 # Bytecode cache is not concurrency-safe unless pre-cached: |
| 77 # if pre-cached this is read-only, but writing creates a race condition. | 77 # if pre-cached this is read-only, but writing creates a race condition. |
| 78 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), | 78 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), |
| 79 keep_trailing_newline=True, # newline-terminate generated files | 79 keep_trailing_newline=True, # newline-terminate generated files |
| 80 lstrip_blocks=True, # so can indent control flow tags | 80 lstrip_blocks=True, # so can indent control flow tags |
| 81 trim_blocks=True) | 81 trim_blocks=True) |
| 82 jinja_env.filters.update({ | 82 jinja_env.filters.update({ |
| 83 'blink_capitalize': capitalize, | 83 'blink_capitalize': capitalize, |
| 84 'exposed': exposed_if, | 84 'exposed': exposed_if, |
| 85 'for_origin_trial_feature': for_origin_trial_feature, | |
| 86 'format_blink_cpp_source_code': format_blink_cpp_source_code, | 85 'format_blink_cpp_source_code': format_blink_cpp_source_code, |
| 87 'format_remove_duplicates': format_remove_duplicates, | 86 'format_remove_duplicates': format_remove_duplicates, |
| 88 'runtime_enabled': runtime_enabled_if, | 87 'runtime_enabled': runtime_enabled_if, |
| 89 'secure_context': secure_context_if, | 88 'secure_context': secure_context_if, |
| 90 'unique_by': unique_by}) | 89 'unique_by': unique_by}) |
| 91 jinja_env.filters.update(constant_filters()) | 90 jinja_env.filters.update(constant_filters()) |
| 92 jinja_env.filters.update(method_filters()) | 91 jinja_env.filters.update(method_filters()) |
| 93 return jinja_env | 92 return jinja_env |
| 94 | 93 |
| 95 | 94 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 173 |
| 175 # Create a dummy file as output for the build system, | 174 # Create a dummy file as output for the build system, |
| 176 # since filenames of individual cache files are unpredictable and opaque | 175 # since filenames of individual cache files are unpredictable and opaque |
| 177 # (they are hashes of the template path, which varies based on environment) | 176 # (they are hashes of the template path, which varies based on environment) |
| 178 with open(dummy_filename, 'w') as dummy_file: | 177 with open(dummy_filename, 'w') as dummy_file: |
| 179 pass # |open| creates or touches the file | 178 pass # |open| creates or touches the file |
| 180 | 179 |
| 181 | 180 |
| 182 if __name__ == '__main__': | 181 if __name__ == '__main__': |
| 183 sys.exit(main(sys.argv)) | 182 sys.exit(main(sys.argv)) |
| OLD | NEW |