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

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

Issue 2367303002: [Bindings] Remove a redundant option write-file-if-only-changed in bindings (Closed)
Patch Set: Rebase Created 4 years, 2 months 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
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 3 # Copyright 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Generates interface properties on global objects. 7 """Generates interface properties on global objects.
8 8
9 Concretely these are implemented as "constructor attributes", meaning 9 Concretely these are implemented as "constructor attributes", meaning
10 "attributes whose name ends with Constructor" (special-cased by code generator), 10 "attributes whose name ends with Constructor" (special-cased by code generator),
(...skipping 24 matching lines...) Expand all
35 35
36 HEADER_FORMAT = """// Stub header file for {{idl_basename}} 36 HEADER_FORMAT = """// Stub header file for {{idl_basename}}
37 // Required because the IDL compiler assumes that a corresponding header file 37 // Required because the IDL compiler assumes that a corresponding header file
38 // exists for each IDL file. 38 // exists for each IDL file.
39 """ 39 """
40 40
41 def parse_options(): 41 def parse_options():
42 parser = optparse.OptionParser() 42 parser = optparse.OptionParser()
43 parser.add_option('--idl-files-list', help='file listing IDL files') 43 parser.add_option('--idl-files-list', help='file listing IDL files')
44 parser.add_option('--global-objects-file', help='pickle file of global objec ts') 44 parser.add_option('--global-objects-file', help='pickle file of global objec ts')
45 parser.add_option('--write-file-only-if-changed', type='int', help='if true, do not write an output file if it would be identical to the existing one, which avoids unnecessary rebuilds in ninja')
46
47 options, args = parser.parse_args() 45 options, args = parser.parse_args()
48 46
49 if options.idl_files_list is None: 47 if options.idl_files_list is None:
50 parser.error('Must specify a file listing IDL files using --idl-files-li st.') 48 parser.error('Must specify a file listing IDL files using --idl-files-li st.')
51 if options.global_objects_file is None: 49 if options.global_objects_file is None:
52 parser.error('Must specify a pickle file of global objects using --globa l-objects-file.') 50 parser.error('Must specify a pickle file of global objects using --globa l-objects-file.')
53 if options.write_file_only_if_changed is None:
54 parser.error('Must specify whether output files are only written if chan ged using --write-file-only-if-changed.')
55 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
56 51
57 return options, args 52 return options, args
58 53
59 54
60 def flatten_list(iterable): 55 def flatten_list(iterable):
61 return list(itertools.chain.from_iterable(iterable)) 56 return list(itertools.chain.from_iterable(iterable))
62 57
63 58
64 def interface_name_to_constructors(interface_name): 59 def interface_name_to_constructors(interface_name):
65 """Returns constructors for an interface.""" 60 """Returns constructors for an interface."""
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 # Extract function name, namely everything before opening '(' 119 # Extract function name, namely everything before opening '('
125 constructor_name = re.sub(r'\(.*', '', named_constructor) 120 constructor_name = re.sub(r'\(.*', '', named_constructor)
126 # Note the reduplicated 'ConstructorConstructor' 121 # Note the reduplicated 'ConstructorConstructor'
127 # FIXME: rename to NamedConstructor 122 # FIXME: rename to NamedConstructor
128 attribute_string = 'attribute %sConstructorConstructor %s' % (interface_ name, constructor_name) 123 attribute_string = 'attribute %sConstructorConstructor %s' % (interface_ name, constructor_name)
129 attributes_list.append(extended_string + attribute_string) 124 attributes_list.append(extended_string + attribute_string)
130 125
131 return attributes_list 126 return attributes_list
132 127
133 128
134 def write_global_constructors_partial_interface(interface_name, idl_filename, co nstructor_attributes_list, only_if_changed): 129 def write_global_constructors_partial_interface(interface_name, idl_filename, co nstructor_attributes_list):
135 # FIXME: replace this with a simple Jinja template 130 # FIXME: replace this with a simple Jinja template
136 lines = (['partial interface %s {\n' % interface_name] + 131 lines = (['partial interface %s {\n' % interface_name] +
137 [' %s;\n' % constructor_attribute 132 [' %s;\n' % constructor_attribute
138 # FIXME: sort by interface name (not first by extended attributes) 133 # FIXME: sort by interface name (not first by extended attributes)
139 for constructor_attribute in sorted(constructor_attributes_list)] + 134 for constructor_attribute in sorted(constructor_attributes_list)] +
140 ['};\n']) 135 ['};\n'])
141 write_file(''.join(lines), idl_filename, only_if_changed) 136 write_file(''.join(lines), idl_filename)
142 header_filename = os.path.splitext(idl_filename)[0] + '.h' 137 header_filename = os.path.splitext(idl_filename)[0] + '.h'
143 idl_basename = os.path.basename(idl_filename) 138 idl_basename = os.path.basename(idl_filename)
144 write_file(HEADER_FORMAT.format(idl_basename=idl_basename), 139 write_file(HEADER_FORMAT.format(idl_basename=idl_basename), header_filename)
145 header_filename, only_if_changed)
146 140
147 141
148 ################################################################################ 142 ################################################################################
149 143
150 def main(): 144 def main():
151 options, args = parse_options() 145 options, args = parse_options()
152 146
153 # Input IDL files are passed in a file, due to OS command line length 147 # Input IDL files are passed in a file, due to OS command line length
154 # limits. This is generated at GYP time, which is ok b/c files are static. 148 # limits. This is generated at GYP time, which is ok b/c files are static.
155 idl_files = read_file_to_list(options.idl_files_list) 149 idl_files = read_file_to_list(options.idl_files_list)
(...skipping 19 matching lines...) Expand all
175 raise ValueError('The following global names were used in ' 169 raise ValueError('The following global names were used in '
176 '[Exposed=xxx] but do not match any [Global] / ' 170 '[Exposed=xxx] but do not match any [Global] / '
177 '[PrimaryGlobal] interface: %s' 171 '[PrimaryGlobal] interface: %s'
178 % list(unknown_global_names)) 172 % list(unknown_global_names))
179 173
180 # Write partial interfaces containing constructor attributes for each 174 # Write partial interfaces containing constructor attributes for each
181 # global interface. 175 # global interface.
182 for interface_name, idl_filename in interface_name_idl_filename: 176 for interface_name, idl_filename in interface_name_idl_filename:
183 constructors = interface_name_to_constructors(interface_name) 177 constructors = interface_name_to_constructors(interface_name)
184 write_global_constructors_partial_interface( 178 write_global_constructors_partial_interface(
185 interface_name, 179 interface_name, idl_filename, constructors)
186 idl_filename,
187 constructors,
188 options.write_file_only_if_changed)
189 180
190 181
191 if __name__ == '__main__': 182 if __name__ == '__main__':
192 sys.exit(main()) 183 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698