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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 | 163 |
165 def write_content(content, output_file_name): | 164 def write_content(content, output_file_name): |
166 parent_path, file_name = os.path.split(output_file_name) | 165 parent_path, file_name = os.path.split(output_file_name) |
167 if not os.path.exists(parent_path): | 166 if not os.path.exists(parent_path): |
168 print 'Creating directory: %s' % parent_path | 167 print 'Creating directory: %s' % parent_path |
169 os.makedirs(parent_path) | 168 os.makedirs(parent_path) |
170 with open(output_file_name, 'w') as f: | 169 with open(output_file_name, 'w') as f: |
171 f.write(content) | 170 f.write(content) |
172 | 171 |
173 | 172 |
174 def resolve_cygpath(cygdrive_names): | |
175 if not cygdrive_names: | |
176 return [] | |
177 cmd = ['cygpath', '-f', '-', '-wa'] | |
178 process = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIP
E, stderr=subprocess.STDOUT) | |
179 idl_file_names = [] | |
180 for file_name in cygdrive_names: | |
181 process.stdin.write('%s\n' % file_name) | |
182 process.stdin.flush() | |
183 idl_file_names.append(process.stdout.readline().rstrip()) | |
184 process.stdin.close() | |
185 process.wait() | |
186 return idl_file_names | |
187 | |
188 | |
189 def main(args): | 173 def main(args): |
190 if len(args) <= 4: | 174 if len(args) <= 4: |
191 raise Exception('Expected at least 5 arguments.') | 175 raise Exception('Expected at least 5 arguments.') |
192 component_dir = args[1] | 176 component_dir = args[1] |
193 input_file_name = args[2] | 177 input_file_name = args[2] |
194 in_out_break_index = args.index('--') | 178 in_out_break_index = args.index('--') |
195 output_file_names = args[in_out_break_index + 1:] | 179 output_file_names = args[in_out_break_index + 1:] |
196 | 180 |
197 with open(input_file_name) as input_file: | 181 idl_file_names = read_idl_files_list_from_file(input_file_name) |
198 file_names = sorted([os.path.realpath(line.rstrip('\n')) | |
199 for line in input_file]) | |
200 idl_file_names = [file_name for file_name in file_names | |
201 if not file_name.startswith('/cygdrive')] | |
202 cygdrive_names = [file_name for file_name in file_names | |
203 if file_name.startswith('/cygdrive')] | |
204 idl_file_names.extend(resolve_cygpath(cygdrive_names)) | |
205 | |
206 files_meta_data = extract_meta_data(idl_file_names) | 182 files_meta_data = extract_meta_data(idl_file_names) |
207 total_partitions = len(output_file_names) | 183 total_partitions = len(output_file_names) |
208 for partition, file_name in enumerate(output_file_names): | 184 for partition, file_name in enumerate(output_file_names): |
209 files_meta_data_this_partition = [ | 185 files_meta_data_this_partition = [ |
210 meta_data for meta_data in files_meta_data | 186 meta_data for meta_data in files_meta_data |
211 if hash(meta_data['name']) % total_partitions == partition] | 187 if hash(meta_data['name']) % total_partitions == partition] |
212 file_contents = generate_content(component_dir, | 188 file_contents = generate_content(component_dir, |
213 files_meta_data_this_partition) | 189 files_meta_data_this_partition) |
214 write_content(file_contents, file_name) | 190 write_content(file_contents, file_name) |
215 | 191 |
216 | 192 |
217 if __name__ == '__main__': | 193 if __name__ == '__main__': |
218 sys.exit(main(sys.argv)) | 194 sys.exit(main(sys.argv)) |
OLD | NEW |