OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (C) 2009 Google Inc. All rights reserved. | 3 # Copyright (C) 2009 Google Inc. All rights reserved. |
4 # | 4 # |
5 # Redistribution and use in source and binary forms, with or without | 5 # Redistribution and use in source and binary forms, with or without |
6 # modification, are permitted provided that the following conditions are | 6 # modification, are permitted provided that the following conditions are |
7 # met: | 7 # met: |
8 # | 8 # |
9 # * Redistributions of source code must retain the above copyright | 9 # * Redistributions of source code must retain the above copyright |
10 # notice, this list of conditions and the following disclaimer. | 10 # notice, this list of conditions and the following disclaimer. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 48 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
49 """ | 49 """ |
50 | 50 |
51 import errno | 51 import errno |
52 import os | 52 import os |
53 import re | 53 import re |
54 import sys | 54 import sys |
55 | 55 |
56 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl
_filename_to_component, idl_filename_to_interface_name, read_idl_files_list_from
_file | 56 from utilities import should_generate_impl_file_from_idl, get_file_contents, idl
_filename_to_component, idl_filename_to_interface_name, read_idl_files_list_from
_file |
57 | 57 |
58 # A regexp for finding Conditional attributes in interface definitions. | |
59 CONDITIONAL_PATTERN = re.compile( | |
60 r'\[' | |
61 r'[^\]]*' | |
62 r'Conditional=([\_0-9a-zA-Z]*)' | |
63 r'[^\]]*' | |
64 r'\]\s*' | |
65 r'((callback|partial)\s+)?' | |
66 r'interface\s+' | |
67 r'\w+\s*' | |
68 r'(:\s*\w+\s*)?' | |
69 r'{', | |
70 re.MULTILINE) | |
71 | |
72 COPYRIGHT_TEMPLATE = """/* | 58 COPYRIGHT_TEMPLATE = """/* |
73 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. | 59 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. |
74 * | 60 * |
75 * This file was generated by the action_derivedsourcesallinone.py script. | 61 * This file was generated by the action_derivedsourcesallinone.py script. |
76 * | 62 * |
77 * Copyright (C) 2009 Google Inc. All rights reserved. | 63 * Copyright (C) 2009 Google Inc. All rights reserved. |
78 * | 64 * |
79 * Redistribution and use in source and binary forms, with or without | 65 * Redistribution and use in source and binary forms, with or without |
80 * modification, are permitted provided that the following conditions | 66 * modification, are permitted provided that the following conditions |
81 * are met: | 67 * are met: |
(...skipping 11 matching lines...) Expand all Loading... |
93 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 79 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
94 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 80 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
95 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 81 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
96 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 82 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
97 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 83 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
98 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 84 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
99 */ | 85 */ |
100 """ | 86 """ |
101 | 87 |
102 | 88 |
103 def extract_conditional(idl_contents): | |
104 """Find [Conditional] interface extended attribute.""" | |
105 | |
106 match = CONDITIONAL_PATTERN.search(idl_contents) | |
107 if not match: | |
108 return None | |
109 return match.group(1) | |
110 | |
111 | |
112 def extract_meta_data(file_paths): | 89 def extract_meta_data(file_paths): |
113 """Extracts conditional and interface name from each IDL file.""" | 90 """Extracts interface name from each IDL file.""" |
114 meta_data_list = [] | 91 meta_data_list = [] |
115 | 92 |
116 for file_path in file_paths: | 93 for file_path in file_paths: |
117 if not file_path.endswith('.idl'): | 94 if not file_path.endswith('.idl'): |
118 print 'WARNING: non-IDL file passed: "%s"' % file_path | 95 print 'WARNING: non-IDL file passed: "%s"' % file_path |
119 continue | 96 continue |
120 if not os.path.exists(file_path): | 97 if not os.path.exists(file_path): |
121 print 'WARNING: file not found: "%s"' % file_path | 98 print 'WARNING: file not found: "%s"' % file_path |
122 continue | 99 continue |
123 | 100 |
124 idl_file_contents = get_file_contents(file_path) | 101 idl_file_contents = get_file_contents(file_path) |
125 if not should_generate_impl_file_from_idl(idl_file_contents): | 102 if not should_generate_impl_file_from_idl(idl_file_contents): |
126 continue | 103 continue |
127 | 104 |
128 # Extract interface name from file name | 105 # Extract interface name from file name |
129 interface_name = idl_filename_to_interface_name(file_path) | 106 interface_name = idl_filename_to_interface_name(file_path) |
130 | 107 |
131 meta_data = { | 108 meta_data = { |
132 'conditional': extract_conditional(idl_file_contents), | |
133 'name': interface_name, | 109 'name': interface_name, |
134 } | 110 } |
135 meta_data_list.append(meta_data) | 111 meta_data_list.append(meta_data) |
136 | 112 |
137 return meta_data_list | 113 return meta_data_list |
138 | 114 |
139 | 115 |
140 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat
a_this_partition): | 116 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat
a_this_partition): |
141 # Add fixed content. | 117 # Add fixed content. |
142 output = [COPYRIGHT_TEMPLATE, | 118 output = [COPYRIGHT_TEMPLATE, |
143 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] | 119 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] |
144 | 120 |
145 # List all includes segmented by if and endif. | 121 # List all includes. |
146 prev_conditional = None | 122 files_meta_data_this_partition.sort() |
147 files_meta_data_this_partition.sort(key=lambda e: e['conditional']) | |
148 for meta_data in files_meta_data_this_partition: | 123 for meta_data in files_meta_data_this_partition: |
149 conditional = meta_data['conditional'] | |
150 if prev_conditional != conditional: | |
151 if prev_conditional: | |
152 output.append('#endif\n') | |
153 if conditional: | |
154 output.append('\n#if ENABLE(%s)\n' % conditional) | |
155 prev_conditional = conditional | |
156 | |
157 if aggregate_partial_interfaces: | 124 if aggregate_partial_interfaces: |
158 cpp_filename = 'V8%sPartial.cpp' % meta_data['name'] | 125 cpp_filename = 'V8%sPartial.cpp' % meta_data['name'] |
159 else: | 126 else: |
160 cpp_filename = 'V8%s.cpp' % meta_data['name'] | 127 cpp_filename = 'V8%s.cpp' % meta_data['name'] |
161 | 128 |
162 output.append('#include "bindings/%s/v8/%s"\n' % | 129 output.append('#include "bindings/%s/v8/%s"\n' % |
163 (component_dir, cpp_filename)) | 130 (component_dir, cpp_filename)) |
164 | 131 |
165 if prev_conditional: | |
166 output.append('#endif\n') | |
167 | |
168 return ''.join(output) | 132 return ''.join(output) |
169 | 133 |
170 | 134 |
171 def write_content(content, output_file_name): | 135 def write_content(content, output_file_name): |
172 parent_path, file_name = os.path.split(output_file_name) | 136 parent_path, file_name = os.path.split(output_file_name) |
173 if not os.path.exists(parent_path): | 137 if not os.path.exists(parent_path): |
174 print 'Creating directory: %s' % parent_path | 138 print 'Creating directory: %s' % parent_path |
175 os.makedirs(parent_path) | 139 os.makedirs(parent_path) |
176 with open(output_file_name, 'w') as f: | 140 with open(output_file_name, 'w') as f: |
177 f.write(content) | 141 f.write(content) |
178 | 142 |
179 | 143 |
180 def main(args): | 144 def main(args): |
181 if len(args) <= 4: | 145 if len(args) <= 4: |
182 raise Exception('Expected at least 5 arguments.') | 146 raise Exception('Expected at least 5 arguments.') |
183 component_dir = args[1] | 147 component_dir = args[1] |
184 input_file_name = args[2] | 148 input_file_name = args[2] |
185 in_out_break_index = args.index('--') | 149 in_out_break_index = args.index('--') |
186 output_file_names = args[in_out_break_index + 1:] | 150 output_file_names = args[in_out_break_index + 1:] |
187 | 151 |
188 idl_file_names = read_idl_files_list_from_file(input_file_name) | 152 idl_file_names = read_idl_files_list_from_file(input_file_name, |
| 153 is_gyp_format=True) |
189 components = set([idl_filename_to_component(filename) | 154 components = set([idl_filename_to_component(filename) |
190 for filename in idl_file_names]) | 155 for filename in idl_file_names]) |
191 if len(components) != 1: | 156 if len(components) != 1: |
192 raise Exception('Cannot aggregate generated codes in different component
s') | 157 raise Exception('Cannot aggregate generated codes in different component
s') |
193 aggregate_partial_interfaces = component_dir not in components | 158 aggregate_partial_interfaces = component_dir not in components |
194 | 159 |
195 files_meta_data = extract_meta_data(idl_file_names) | 160 files_meta_data = extract_meta_data(idl_file_names) |
196 total_partitions = len(output_file_names) | 161 total_partitions = len(output_file_names) |
197 for partition, file_name in enumerate(output_file_names): | 162 for partition, file_name in enumerate(output_file_names): |
198 files_meta_data_this_partition = [ | 163 files_meta_data_this_partition = [ |
199 meta_data for meta_data in files_meta_data | 164 meta_data for meta_data in files_meta_data |
200 if hash(meta_data['name']) % total_partitions == partition] | 165 if hash(meta_data['name']) % total_partitions == partition] |
201 file_contents = generate_content(component_dir, | 166 file_contents = generate_content(component_dir, |
202 aggregate_partial_interfaces, | 167 aggregate_partial_interfaces, |
203 files_meta_data_this_partition) | 168 files_meta_data_this_partition) |
204 write_content(file_contents, file_name) | 169 write_content(file_contents, file_name) |
205 | 170 |
206 | 171 |
207 if __name__ == '__main__': | 172 if __name__ == '__main__': |
208 sys.exit(main(sys.argv)) | 173 sys.exit(main(sys.argv)) |
OLD | NEW |