| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 sys | 54 import sys |
| 55 | 55 |
| 56 from utilities import idl_filename_to_interface_name, read_idl_files_list_from_f
ile | 56 from utilities import 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. | 58 # A regexp for finding Conditional attributes in interface definitions. |
| 59 CONDITIONAL_PATTERN = re.compile( | 59 CONDITIONAL_PATTERN = re.compile( |
| 60 r'\[' | 60 r'\[' |
| 61 r'[^\]]*' | 61 r'[^\]]*' |
| 62 r'Conditional=([\_0-9a-zA-Z]*)' | 62 r'Conditional=([\_0-9a-zA-Z]*)' |
| 63 r'[^\]]*' | 63 r'[^\]]*' |
| 64 r'\]\s*' | 64 r'\]\s*' |
| 65 r'((callback|partial)\s+)?' | 65 r'((callback|partial)\s+)?' |
| 66 r'interface\s+' | 66 r'interface\s+' |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 meta_data = { | 129 meta_data = { |
| 130 'conditional': extract_conditional(file_path), | 130 'conditional': extract_conditional(file_path), |
| 131 'name': interface_name, | 131 'name': interface_name, |
| 132 } | 132 } |
| 133 meta_data_list.append(meta_data) | 133 meta_data_list.append(meta_data) |
| 134 | 134 |
| 135 return meta_data_list | 135 return meta_data_list |
| 136 | 136 |
| 137 | 137 |
| 138 def generate_content(component_dir, files_meta_data_this_partition): | 138 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat
a_this_partition): |
| 139 # Add fixed content. | 139 # Add fixed content. |
| 140 output = [COPYRIGHT_TEMPLATE, | 140 output = [COPYRIGHT_TEMPLATE, |
| 141 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] | 141 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] |
| 142 | 142 |
| 143 # List all includes segmented by if and endif. | 143 # List all includes segmented by if and endif. |
| 144 prev_conditional = None | 144 prev_conditional = None |
| 145 files_meta_data_this_partition.sort(key=lambda e: e['conditional']) | 145 files_meta_data_this_partition.sort(key=lambda e: e['conditional']) |
| 146 for meta_data in files_meta_data_this_partition: | 146 for meta_data in files_meta_data_this_partition: |
| 147 conditional = meta_data['conditional'] | 147 conditional = meta_data['conditional'] |
| 148 if prev_conditional != conditional: | 148 if prev_conditional != conditional: |
| 149 if prev_conditional: | 149 if prev_conditional: |
| 150 output.append('#endif\n') | 150 output.append('#endif\n') |
| 151 if conditional: | 151 if conditional: |
| 152 output.append('\n#if ENABLE(%s)\n' % conditional) | 152 output.append('\n#if ENABLE(%s)\n' % conditional) |
| 153 prev_conditional = conditional | 153 prev_conditional = conditional |
| 154 | 154 |
| 155 output.append('#include "bindings/%s/v8/V8%s.cpp"\n' % | 155 if aggregate_partial_interfaces: |
| 156 (component_dir, meta_data['name'])) | 156 cpp_filename = 'V8%sPartial.cpp' % meta_data['name'] |
| 157 else: |
| 158 cpp_filename = 'V8%s.cpp' % meta_data['name'] |
| 159 |
| 160 output.append('#include "bindings/%s/v8/%s"\n' % |
| 161 (component_dir, cpp_filename)) |
| 157 | 162 |
| 158 if prev_conditional: | 163 if prev_conditional: |
| 159 output.append('#endif\n') | 164 output.append('#endif\n') |
| 160 | 165 |
| 161 return ''.join(output) | 166 return ''.join(output) |
| 162 | 167 |
| 163 | 168 |
| 164 def write_content(content, output_file_name): | 169 def write_content(content, output_file_name): |
| 165 parent_path, file_name = os.path.split(output_file_name) | 170 parent_path, file_name = os.path.split(output_file_name) |
| 166 if not os.path.exists(parent_path): | 171 if not os.path.exists(parent_path): |
| 167 print 'Creating directory: %s' % parent_path | 172 print 'Creating directory: %s' % parent_path |
| 168 os.makedirs(parent_path) | 173 os.makedirs(parent_path) |
| 169 with open(output_file_name, 'w') as f: | 174 with open(output_file_name, 'w') as f: |
| 170 f.write(content) | 175 f.write(content) |
| 171 | 176 |
| 172 | 177 |
| 173 def main(args): | 178 def main(args): |
| 174 if len(args) <= 4: | 179 if len(args) <= 4: |
| 175 raise Exception('Expected at least 5 arguments.') | 180 raise Exception('Expected at least 5 arguments.') |
| 176 component_dir = args[1] | 181 component_dir = args[1] |
| 177 input_file_name = args[2] | 182 input_file_name = args[2] |
| 178 in_out_break_index = args.index('--') | 183 in_out_break_index = args.index('--') |
| 179 output_file_names = args[in_out_break_index + 1:] | 184 output_file_names = args[in_out_break_index + 1:] |
| 180 | 185 |
| 181 idl_file_names = read_idl_files_list_from_file(input_file_name) | 186 idl_file_names = read_idl_files_list_from_file(input_file_name) |
| 187 components = set([idl_filename_to_component(filename) |
| 188 for filename in idl_file_names]) |
| 189 if len(components) != 1: |
| 190 raise Exception('Cannot aggregate generated codes in different component
s') |
| 191 aggregate_partial_interfaces = component_dir not in components |
| 192 |
| 182 files_meta_data = extract_meta_data(idl_file_names) | 193 files_meta_data = extract_meta_data(idl_file_names) |
| 183 total_partitions = len(output_file_names) | 194 total_partitions = len(output_file_names) |
| 184 for partition, file_name in enumerate(output_file_names): | 195 for partition, file_name in enumerate(output_file_names): |
| 185 files_meta_data_this_partition = [ | 196 files_meta_data_this_partition = [ |
| 186 meta_data for meta_data in files_meta_data | 197 meta_data for meta_data in files_meta_data |
| 187 if hash(meta_data['name']) % total_partitions == partition] | 198 if hash(meta_data['name']) % total_partitions == partition] |
| 188 file_contents = generate_content(component_dir, | 199 file_contents = generate_content(component_dir, |
| 200 aggregate_partial_interfaces, |
| 189 files_meta_data_this_partition) | 201 files_meta_data_this_partition) |
| 190 write_content(file_contents, file_name) | 202 write_content(file_contents, file_name) |
| 191 | 203 |
| 192 | 204 |
| 193 if __name__ == '__main__': | 205 if __name__ == '__main__': |
| 194 sys.exit(main(sys.argv)) | 206 sys.exit(main(sys.argv)) |
| OLD | NEW |