Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/code_generator.py

Issue 2578943002: [Bindings] Refactoring of binding code around runtime enabled features (Closed)
Patch Set: Work for a comment Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/v8_attributes.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import v8_utilities
19 from v8_utilities import capitalize, unique_by 20 from v8_utilities import capitalize, unique_by
20 from utilities import (idl_filename_to_component, is_valid_component_dependency, 21 from utilities import (idl_filename_to_component, is_valid_component_dependency,
21 format_remove_duplicates, format_blink_cpp_source_code) 22 format_remove_duplicates, format_blink_cpp_source_code)
22 23
23 # Path handling for libraries and templates 24 # Path handling for libraries and templates
24 # Paths have to be normalized because Jinja uses the exact template path to 25 # 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 26 # 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 27 # to be concurrency-safe. Use absolute path because __file__ is absolute if
27 # module is imported, and relative if executed directly. 28 # module is imported, and relative if executed directly.
28 # If paths differ between pre-caching and individual file compilation, the cache 29 # If paths differ between pre-caching and individual file compilation, the cache
(...skipping 28 matching lines...) Expand all
57 58
58 59
59 # [SecureContext] 60 # [SecureContext]
60 def secure_context_if(code, secure_context_test): 61 def secure_context_if(code, secure_context_test):
61 if not secure_context_test: 62 if not secure_context_test:
62 return code 63 return code
63 return generate_indented_conditional(code, 'executionContext && (%s)' % secu re_context_test) 64 return generate_indented_conditional(code, 'executionContext && (%s)' % secu re_context_test)
64 65
65 66
66 # [RuntimeEnabled] 67 # [RuntimeEnabled]
67 def runtime_enabled_if(code, runtime_enabled_function_name): 68 def runtime_enabled_if(code, name):
68 if not runtime_enabled_function_name: 69 if not name:
69 return code 70 return code
70 return generate_indented_conditional(code, '%s()' % runtime_enabled_function _name) 71
72 function = 'RuntimeEnabledFeatures::%sEnabled()' % v8_utilities.uncapitalize (name)
73 return generate_indented_conditional(code, function)
71 74
72 75
73 def initialize_jinja_env(cache_dir): 76 def initialize_jinja_env(cache_dir):
74 jinja_env = jinja2.Environment( 77 jinja_env = jinja2.Environment(
75 loader=jinja2.FileSystemLoader(TEMPLATES_DIR), 78 loader=jinja2.FileSystemLoader(TEMPLATES_DIR),
76 # Bytecode cache is not concurrency-safe unless pre-cached: 79 # Bytecode cache is not concurrency-safe unless pre-cached:
77 # 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.
78 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir), 81 bytecode_cache=jinja2.FileSystemBytecodeCache(cache_dir),
79 keep_trailing_newline=True, # newline-terminate generated files 82 keep_trailing_newline=True, # newline-terminate generated files
80 lstrip_blocks=True, # so can indent control flow tags 83 lstrip_blocks=True, # so can indent control flow tags
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 183
181 # Create a dummy file as output for the build system, 184 # Create a dummy file as output for the build system,
182 # since filenames of individual cache files are unpredictable and opaque 185 # since filenames of individual cache files are unpredictable and opaque
183 # (they are hashes of the template path, which varies based on environment) 186 # (they are hashes of the template path, which varies based on environment)
184 with open(dummy_filename, 'w') as dummy_file: 187 with open(dummy_filename, 'w') as dummy_file:
185 pass # |open| creates or touches the file 188 pass # |open| creates or touches the file
186 189
187 190
188 if __name__ == '__main__': 191 if __name__ == '__main__':
189 sys.exit(main(sys.argv)) 192 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/bindings/scripts/v8_attributes.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698