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

Side by Side Diff: bindings/scripts/aggregate_generated_bindings.py

Issue 959933002: Move IDLs to 39 roll (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « bindings/dart/scripts/test/main.py ('k') | bindings/scripts/blink_idl_parser.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 #!/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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 IDL_FILES_LIST is a text file containing the IDL file paths, so the command 44 IDL_FILES_LIST is a text file containing the IDL file paths, so the command
45 line doesn't exceed OS length limits. 45 line doesn't exceed OS length limits.
46 OUTPUT_FILE1 etc. are filenames of output files. 46 OUTPUT_FILE1 etc. are filenames of output files.
47 47
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 subprocess
55 import sys 54 import sys
56 55
57 from utilities import idl_filename_to_interface_name 56 from utilities import idl_filename_to_interface_name, read_idl_files_list_from_f ile
58 57
59 # A regexp for finding Conditional attributes in interface definitions. 58 # A regexp for finding Conditional attributes in interface definitions.
60 CONDITIONAL_PATTERN = re.compile( 59 CONDITIONAL_PATTERN = re.compile(
61 r'\[' 60 r'\['
62 r'[^\]]*' 61 r'[^\]]*'
63 r'Conditional=([\_0-9a-zA-Z&|]*)' 62 r'Conditional=([\_0-9a-zA-Z]*)'
64 r'[^\]]*' 63 r'[^\]]*'
65 r'\]\s*' 64 r'\]\s*'
66 r'((callback|partial)\s+)?' 65 r'((callback|partial)\s+)?'
67 r'interface\s+' 66 r'interface\s+'
68 r'\w+\s*' 67 r'\w+\s*'
69 r'(:\s*\w+\s*)?' 68 r'(:\s*\w+\s*)?'
70 r'{', 69 r'{',
71 re.MULTILINE) 70 re.MULTILINE)
72 71
73 COPYRIGHT_TEMPLATE = """/* 72 COPYRIGHT_TEMPLATE = """/*
(...skipping 20 matching lines...) Expand all
94 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 93 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
95 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 94 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
96 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 95 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
97 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 96 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 97 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
99 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 98 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100 */ 99 */
101 """ 100 """
102 101
103 102
104 def format_conditional(conditional):
105 """Wraps conditional with ENABLE() and replace '&','|' with '&&','||' if
106 more than one conditional is specified."""
107 def wrap_with_enable(s):
108 if s in ['|', '&']:
109 return s * 2
110 return 'ENABLE(' + s + ')'
111 return ' '.join(map(wrap_with_enable, conditional))
112
113
114 def extract_conditional(idl_file_path): 103 def extract_conditional(idl_file_path):
115 """Find [Conditional] interface extended attribute.""" 104 """Find [Conditional] interface extended attribute."""
116 with open(idl_file_path) as idl_file: 105 with open(idl_file_path) as idl_file:
117 idl_contents = idl_file.read() 106 idl_contents = idl_file.read()
118 107
119 match = CONDITIONAL_PATTERN.search(idl_contents) 108 match = CONDITIONAL_PATTERN.search(idl_contents)
120 if not match: 109 if not match:
121 return None 110 return None
122 conditional = match.group(1) 111 return match.group(1)
123 return re.split('([|,])', conditional)
124 112
125 113
126 def extract_meta_data(file_paths): 114 def extract_meta_data(file_paths):
127 """Extracts conditional and interface name from each IDL file.""" 115 """Extracts conditional and interface name from each IDL file."""
128 meta_data_list = [] 116 meta_data_list = []
129 117
130 for file_path in file_paths: 118 for file_path in file_paths:
131 if not file_path.endswith('.idl'): 119 if not file_path.endswith('.idl'):
132 print 'WARNING: non-IDL file passed: "%s"' % file_path 120 print 'WARNING: non-IDL file passed: "%s"' % file_path
133 continue 121 continue
(...skipping 20 matching lines...) Expand all
154 142
155 # List all includes segmented by if and endif. 143 # List all includes segmented by if and endif.
156 prev_conditional = None 144 prev_conditional = None
157 files_meta_data_this_partition.sort(key=lambda e: e['conditional']) 145 files_meta_data_this_partition.sort(key=lambda e: e['conditional'])
158 for meta_data in files_meta_data_this_partition: 146 for meta_data in files_meta_data_this_partition:
159 conditional = meta_data['conditional'] 147 conditional = meta_data['conditional']
160 if prev_conditional != conditional: 148 if prev_conditional != conditional:
161 if prev_conditional: 149 if prev_conditional:
162 output.append('#endif\n') 150 output.append('#endif\n')
163 if conditional: 151 if conditional:
164 output.append('\n#if %s\n' % format_conditional(conditional)) 152 output.append('\n#if ENABLE(%s)\n' % conditional)
165 prev_conditional = conditional 153 prev_conditional = conditional
166 154
167 output.append('#include "bindings/%s/%s/%s%s.cpp"\n' % 155 output.append('#include "bindings/%s/%s/%s%s.cpp"\n' %
168 (component_dir, prefix.lower(), prefix, meta_data['name']) ) 156 (component_dir, prefix.lower(), prefix, meta_data['name']) )
169 157
170 if prev_conditional: 158 if prev_conditional:
171 output.append('#endif\n') 159 output.append('#endif\n')
172 160
173 return ''.join(output) 161 return ''.join(output)
174 162
175 163
176 def write_content(content, output_file_name): 164 def write_content(content, output_file_name):
177 parent_path, file_name = os.path.split(output_file_name) 165 parent_path, file_name = os.path.split(output_file_name)
178 if not os.path.exists(parent_path): 166 if not os.path.exists(parent_path):
179 print 'Creating directory: %s' % parent_path 167 print 'Creating directory: %s' % parent_path
180 os.makedirs(parent_path) 168 os.makedirs(parent_path)
181 with open(output_file_name, 'w') as f: 169 with open(output_file_name, 'w') as f:
182 f.write(content) 170 f.write(content)
183 171
184 172
185 def resolve_cygpath(cygdrive_names):
186 if not cygdrive_names:
187 return []
188 cmd = ['cygpath', '-f', '-', '-wa']
189 process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIP E, stderr=subprocess.STDOUT)
190 idl_file_names = []
191 for file_name in cygdrive_names:
192 process.stdin.write('%s\n' % file_name)
193 process.stdin.flush()
194 idl_file_names.append(process.stdout.readline().rstrip())
195 process.stdin.close()
196 process.wait()
197 return idl_file_names
198
199
200 def main(args): 173 def main(args):
201 if len(args) <= 4: 174 if len(args) <= 4:
202 raise Exception('Expected at least 5 arguments.') 175 raise Exception('Expected at least 5 arguments.')
203 if (args[1] == '--dart'): 176 if (args[1] == '--dart'):
204 component_dir = args[2] 177 component_dir = args[2]
205 input_file_name = args[3] 178 input_file_name = args[3]
206 prefix = 'Dart' 179 prefix = 'Dart'
207 else: 180 else:
208 component_dir = args[1] 181 component_dir = args[1]
209 input_file_name = args[2] 182 input_file_name = args[2]
210 prefix = 'V8' 183 prefix = 'V8'
211 in_out_break_index = args.index('--') 184 in_out_break_index = args.index('--')
212 output_file_names = args[in_out_break_index + 1:] 185 output_file_names = args[in_out_break_index + 1:]
213 186
214 with open(input_file_name) as input_file: 187 idl_file_names = read_idl_files_list_from_file(input_file_name)
215 file_names = sorted([os.path.realpath(line.rstrip('\n'))
216 for line in input_file])
217 idl_file_names = [file_name for file_name in file_names
218 if not file_name.startswith('/cygdrive')]
219 cygdrive_names = [file_name for file_name in file_names
220 if file_name.startswith('/cygdrive')]
221 idl_file_names.extend(resolve_cygpath(cygdrive_names))
222
223 files_meta_data = extract_meta_data(idl_file_names) 188 files_meta_data = extract_meta_data(idl_file_names)
224 total_partitions = len(output_file_names) 189 total_partitions = len(output_file_names)
225 for partition, file_name in enumerate(output_file_names): 190 for partition, file_name in enumerate(output_file_names):
226 files_meta_data_this_partition = [ 191 files_meta_data_this_partition = [
227 meta_data for meta_data in files_meta_data 192 meta_data for meta_data in files_meta_data
228 if hash(meta_data['name']) % total_partitions == partition] 193 if hash(meta_data['name']) % total_partitions == partition]
229 file_contents = generate_content(component_dir, 194 file_contents = generate_content(component_dir,
230 files_meta_data_this_partition, 195 files_meta_data_this_partition,
231 prefix) 196 prefix)
232 write_content(file_contents, file_name) 197 write_content(file_contents, file_name)
233 198
234 199
235 if __name__ == '__main__': 200 if __name__ == '__main__':
236 sys.exit(main(sys.argv)) 201 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « bindings/dart/scripts/test/main.py ('k') | bindings/scripts/blink_idl_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698