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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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+' |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 174 |
176 def write_content(content, output_file_name): | 175 def write_content(content, output_file_name): |
177 parent_path, file_name = os.path.split(output_file_name) | 176 parent_path, file_name = os.path.split(output_file_name) |
178 if not os.path.exists(parent_path): | 177 if not os.path.exists(parent_path): |
179 print 'Creating directory: %s' % parent_path | 178 print 'Creating directory: %s' % parent_path |
180 os.makedirs(parent_path) | 179 os.makedirs(parent_path) |
181 with open(output_file_name, 'w') as f: | 180 with open(output_file_name, 'w') as f: |
182 f.write(content) | 181 f.write(content) |
183 | 182 |
184 | 183 |
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): | 184 def main(args): |
201 if len(args) <= 4: | 185 if len(args) <= 4: |
202 raise Exception('Expected at least 5 arguments.') | 186 raise Exception('Expected at least 5 arguments.') |
203 component_dir = args[1] | 187 component_dir = args[1] |
204 input_file_name = args[2] | 188 input_file_name = args[2] |
205 in_out_break_index = args.index('--') | 189 in_out_break_index = args.index('--') |
206 output_file_names = args[in_out_break_index + 1:] | 190 output_file_names = args[in_out_break_index + 1:] |
207 | 191 |
208 with open(input_file_name) as input_file: | 192 idl_file_names = read_idl_files_list_from_file(input_file_name) |
209 file_names = sorted([os.path.realpath(line.rstrip('\n')) | |
210 for line in input_file]) | |
211 idl_file_names = [file_name for file_name in file_names | |
212 if not file_name.startswith('/cygdrive')] | |
213 cygdrive_names = [file_name for file_name in file_names | |
214 if file_name.startswith('/cygdrive')] | |
215 idl_file_names.extend(resolve_cygpath(cygdrive_names)) | |
216 | |
217 files_meta_data = extract_meta_data(idl_file_names) | 193 files_meta_data = extract_meta_data(idl_file_names) |
218 total_partitions = len(output_file_names) | 194 total_partitions = len(output_file_names) |
219 for partition, file_name in enumerate(output_file_names): | 195 for partition, file_name in enumerate(output_file_names): |
220 files_meta_data_this_partition = [ | 196 files_meta_data_this_partition = [ |
221 meta_data for meta_data in files_meta_data | 197 meta_data for meta_data in files_meta_data |
222 if hash(meta_data['name']) % total_partitions == partition] | 198 if hash(meta_data['name']) % total_partitions == partition] |
223 file_contents = generate_content(component_dir, | 199 file_contents = generate_content(component_dir, |
224 files_meta_data_this_partition) | 200 files_meta_data_this_partition) |
225 write_content(file_contents, file_name) | 201 write_content(file_contents, file_name) |
226 | 202 |
227 | 203 |
228 if __name__ == '__main__': | 204 if __name__ == '__main__': |
229 sys.exit(main(sys.argv)) | 205 sys.exit(main(sys.argv)) |
OLD | NEW |