Chromium Code Reviews| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 57 return generate_indented_conditional(code, 'executionContext && (%s)' % expo sed_test) | 57 return generate_indented_conditional(code, 'executionContext && (%s)' % expo sed_test) |
| 58 | 58 |
| 59 | 59 |
| 60 # [SecureContext] | 60 # [SecureContext] |
| 61 def secure_context_if(code, secure_context_test): | 61 def secure_context_if(code, secure_context_test): |
| 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 def secure_context_cached_if(code, secure_context_test): | |
|
Yuki
2017/05/12 09:10:05
Hmm, I think *cached* in the name is not easy to u
chasej
2017/05/16 02:21:39
I agree on many points here. In an interim version
| |
| 68 if not secure_context_test: | |
| 69 return code | |
| 70 return generate_indented_conditional(code, 'isSecureContext') | |
|
Yuki
2017/05/12 09:10:05
nit: s/isSecureContext/is_secure_context/
iclelland
2017/05/12 15:11:49
This looks like it matches surrounding code -- esp
Yuki
2017/05/12 15:14:11
Makes sense. I'm fine with either way.
| |
| 71 | |
| 67 # [RuntimeEnabled] | 72 # [RuntimeEnabled] |
| 68 def runtime_enabled_if(code, name): | 73 def runtime_enabled_if(code, name): |
| 69 if not name: | 74 if not name: |
| 70 return code | 75 return code |
| 71 | 76 |
| 72 function = v8_utilities.runtime_enabled_function(name) | 77 function = v8_utilities.runtime_enabled_function(name) |
| 73 return generate_indented_conditional(code, function) | 78 return generate_indented_conditional(code, function) |
| 74 | 79 |
| 75 | |
| 76 def initialize_jinja_env(cache_dir): | 80 def initialize_jinja_env(cache_dir): |
| 77 jinja_env = jinja2.Environment( | 81 jinja_env = jinja2.Environment( |
| 78 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), | 82 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), |
| 79 # Bytecode cache is not concurrency-safe unless pre-cached: | 83 # Bytecode cache is not concurrency-safe unless pre-cached: |
| 80 # if pre-cached this is read-only, but writing creates a race condition. | 84 # if pre-cached this is read-only, but writing creates a race condition. |
| 81 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), | 85 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), |
| 82 keep_trailing_newline=True, # newline-terminate generated files | 86 keep_trailing_newline=True, # newline-terminate generated files |
| 83 lstrip_blocks=True, # so can indent control flow tags | 87 lstrip_blocks=True, # so can indent control flow tags |
| 84 trim_blocks=True) | 88 trim_blocks=True) |
| 85 jinja_env.filters.update({ | 89 jinja_env.filters.update({ |
| 86 'blink_capitalize': capitalize, | 90 'blink_capitalize': capitalize, |
| 87 'exposed': exposed_if, | 91 'exposed': exposed_if, |
| 88 'format_blink_cpp_source_code': format_blink_cpp_source_code, | 92 'format_blink_cpp_source_code': format_blink_cpp_source_code, |
| 89 'format_remove_duplicates': format_remove_duplicates, | 93 'format_remove_duplicates': format_remove_duplicates, |
| 90 'runtime_enabled': runtime_enabled_if, | 94 'runtime_enabled': runtime_enabled_if, |
| 91 'runtime_enabled_function': v8_utilities.runtime_enabled_function, | 95 'runtime_enabled_function': v8_utilities.runtime_enabled_function, |
| 92 'secure_context': secure_context_if, | 96 'secure_context': secure_context_if, |
| 97 'secure_context_cached': secure_context_cached_if, | |
| 93 'unique_by': unique_by}) | 98 'unique_by': unique_by}) |
| 94 jinja_env.filters.update(constant_filters()) | 99 jinja_env.filters.update(constant_filters()) |
| 95 jinja_env.filters.update(method_filters()) | 100 jinja_env.filters.update(method_filters()) |
| 96 return jinja_env | 101 return jinja_env |
| 97 | 102 |
| 98 | 103 |
| 99 def normalize_and_sort_includes(include_paths): | 104 def normalize_and_sort_includes(include_paths): |
| 100 normalized_include_paths = [] | 105 normalized_include_paths = [] |
| 101 for include_path in include_paths: | 106 for include_path in include_paths: |
| 102 match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path)) | 107 match = re.search(r'/gen/blink/(.*)$', posixpath.abspath(include_path)) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 | 189 |
| 185 # Create a dummy file as output for the build system, | 190 # Create a dummy file as output for the build system, |
| 186 # since filenames of individual cache files are unpredictable and opaque | 191 # since filenames of individual cache files are unpredictable and opaque |
| 187 # (they are hashes of the template path, which varies based on environment) | 192 # (they are hashes of the template path, which varies based on environment) |
| 188 with open(dummy_filename, 'w') as dummy_file: | 193 with open(dummy_filename, 'w') as dummy_file: |
| 189 pass # |open| creates or touches the file | 194 pass # |open| creates or touches the file |
| 190 | 195 |
| 191 | 196 |
| 192 if __name__ == '__main__': | 197 if __name__ == '__main__': |
| 193 sys.exit(main(sys.argv)) | 198 sys.exit(main(sys.argv)) |
| OLD | NEW |