OLD | NEW |
---|---|
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), |
11 hence "global constructors" for short. | 11 hence "global constructors" for short. |
12 | 12 |
13 For reference on global objects, see: | 13 For reference on global objects, see: |
14 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes#TOC-GlobalCon text-i- | 14 http://www.chromium.org/blink/webidl/blink-idl-extended-attributes#TOC-GlobalCon text-i- |
15 | 15 |
16 Design document: http://www.chromium.org/developers/design-documents/idl-build | 16 Design document: http://www.chromium.org/developers/design-documents/idl-build |
17 """ | 17 """ |
18 | 18 |
19 import optparse | 19 import optparse |
20 import os | 20 import os |
21 import re | 21 import re |
22 import sys | 22 import sys |
23 | 23 |
24 from utilities import get_file_contents, write_file, get_interface_extended_attr ibutes_from_idl, is_callback_interface_from_idl | 24 from utilities import get_file_contents, write_file, get_interface_extended_attr ibutes_from_idl, is_callback_interface_from_idl |
25 | 25 |
26 global_objects = {} | 26 global_objects = {} |
27 | 27 |
28 | 28 |
29 HEADER_FORMAT = """ | |
30 // Stub header file, required by IDL compiler due to existence | |
31 // of {{idl_basename}} (corresponding header assumed to exist). | |
haraken
2014/03/24 06:22:07
Would you make this message more descriptive so th
Nils Barth (inactive)
2014/03/24 06:27:51
Revised; is it clearer now?
| |
32 """ | |
33 | |
29 def parse_options(): | 34 def parse_options(): |
30 parser = optparse.OptionParser() | 35 parser = optparse.OptionParser() |
31 parser.add_option('--idl-files-list', help='file listing IDL files') | 36 parser.add_option('--idl-files-list', help='file listing IDL files') |
32 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') | 37 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') |
33 | 38 |
34 options, args = parser.parse_args() | 39 options, args = parser.parse_args() |
35 | 40 |
36 if options.idl_files_list is None: | 41 if options.idl_files_list is None: |
37 parser.error('Must specify a file listing IDL files using --idl-files-li st.') | 42 parser.error('Must specify a file listing IDL files using --idl-files-li st.') |
38 if options.write_file_only_if_changed is None: | 43 if options.write_file_only_if_changed is None: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 # Extract function name, namely everything before opening '(' | 90 # Extract function name, namely everything before opening '(' |
86 constructor_name = re.sub(r'\(.*', '', named_constructor) | 91 constructor_name = re.sub(r'\(.*', '', named_constructor) |
87 # Note the reduplicated 'ConstructorConstructor' | 92 # Note the reduplicated 'ConstructorConstructor' |
88 # FIXME: rename to NamedConstructor | 93 # FIXME: rename to NamedConstructor |
89 attribute_string = 'attribute %sConstructorConstructor %s' % (interface_ name, constructor_name) | 94 attribute_string = 'attribute %sConstructorConstructor %s' % (interface_ name, constructor_name) |
90 attributes_list.append(extended_string + attribute_string) | 95 attributes_list.append(extended_string + attribute_string) |
91 | 96 |
92 return attributes_list | 97 return attributes_list |
93 | 98 |
94 | 99 |
95 def write_global_constructors_partial_interface(interface_name, destination_file name, constructor_attributes_list, only_if_changed): | 100 def write_global_constructors_partial_interface(interface_name, idl_filename, co nstructor_attributes_list, only_if_changed): |
96 # FIXME: replace this with a simple Jinja template | 101 # FIXME: replace this with a simple Jinja template |
97 lines = (['[\n'] + | 102 lines = (['partial interface %s {\n' % interface_name] + |
98 [' NoHeader,\n'] + | |
99 [']\n'] + | |
100 ['partial interface %s {\n' % interface_name] + | |
101 [' %s;\n' % constructor_attribute | 103 [' %s;\n' % constructor_attribute |
102 # FIXME: sort by interface name (not first by extended attributes) | 104 # FIXME: sort by interface name (not first by extended attributes) |
103 for constructor_attribute in sorted(constructor_attributes_list)] + | 105 for constructor_attribute in sorted(constructor_attributes_list)] + |
104 ['};\n']) | 106 ['};\n']) |
105 write_file(''.join(lines), destination_filename, only_if_changed) | 107 write_file(''.join(lines), idl_filename, only_if_changed) |
108 header_filename = os.path.splitext(idl_filename)[0] + '.h' | |
109 idl_basename = os.path.basename(idl_filename) | |
110 write_file(HEADER_FORMAT.format(idl_basename=idl_basename), | |
111 header_filename, only_if_changed) | |
106 | 112 |
107 | 113 |
108 ################################################################################ | 114 ################################################################################ |
109 | 115 |
110 def main(): | 116 def main(): |
111 options, args = parse_options() | 117 options, args = parse_options() |
112 | 118 |
113 # Input IDL files are passed in a file, due to OS command line length | 119 # Input IDL files are passed in a file, due to OS command line length |
114 # limits. This is generated at GYP time, which is ok b/c files are static. | 120 # limits. This is generated at GYP time, which is ok b/c files are static. |
115 with open(options.idl_files_list) as idl_files_list: | 121 with open(options.idl_files_list) as idl_files_list: |
116 idl_files = [line.rstrip('\n') for line in idl_files_list] | 122 idl_files = [line.rstrip('\n') for line in idl_files_list] |
117 | 123 |
118 # Output IDL files (to generate) are passed at the command line, since | 124 # Output IDL files (to generate) are passed at the command line, since |
119 # these are in the build directory, which is determined at build time, not | 125 # these are in the build directory, which is determined at build time, not |
120 # GYP time. | 126 # GYP time. |
121 # These are passed as pairs of GlobalObjectName, GlobalObject.idl | 127 # These are passed as pairs of GlobalObjectName, GlobalObject.idl |
122 interface_name_filename = [(args[i], args[i + 1]) | 128 interface_name_idl_filename = [(args[i], args[i + 1]) |
123 for i in range(0, len(args), 2)] | 129 for i in range(0, len(args), 2)] |
124 global_objects.update( | 130 global_objects.update( |
125 (interface_name, { | 131 (interface_name, { |
126 'filename': filename, | 132 'idl_filename': idl_filename, |
127 'constructors': [], | 133 'constructors': [], |
128 }) | 134 }) |
129 for interface_name, filename in interface_name_filename) | 135 for interface_name, idl_filename in interface_name_idl_filename) |
130 | 136 |
131 for idl_filename in idl_files: | 137 for idl_filename in idl_files: |
132 record_global_constructors(idl_filename) | 138 record_global_constructors(idl_filename) |
133 | 139 |
134 for interface_name, global_object in global_objects.iteritems(): | 140 for interface_name, global_object in global_objects.iteritems(): |
135 write_global_constructors_partial_interface(interface_name, global_objec t['filename'], global_object['constructors'], options.write_file_only_if_changed ) | 141 write_global_constructors_partial_interface( |
142 interface_name, | |
143 global_object['idl_filename'], | |
144 global_object['constructors'], | |
145 options.write_file_only_if_changed) | |
136 | 146 |
137 | 147 |
138 if __name__ == '__main__': | 148 if __name__ == '__main__': |
139 sys.exit(main()) | 149 sys.exit(main()) |
OLD | NEW |