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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 optparse | 52 import optparse |
53 import os | 53 import os |
54 import re | 54 import re |
55 import sys | 55 import sys |
56 | 56 |
57 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 from utilities import (should_generate_impl_file_from_idl, |
| 58 get_file_contents, |
| 59 idl_filename_to_interface_name, |
| 60 read_idl_files_list_from_file) |
58 | 61 |
59 COPYRIGHT_TEMPLATE = """/* | 62 COPYRIGHT_TEMPLATE = """/* |
60 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. | 63 * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. |
61 * | 64 * |
62 * This file was generated by the action_derivedsourcesallinone.py script. | 65 * This file was generated by the action_derivedsourcesallinone.py script. |
63 * | 66 * |
64 * Copyright (C) 2009 Google Inc. All rights reserved. | 67 * Copyright (C) 2009 Google Inc. All rights reserved. |
65 * | 68 * |
66 * Redistribution and use in source and binary forms, with or without | 69 * Redistribution and use in source and binary forms, with or without |
67 * modification, are permitted provided that the following conditions | 70 * modification, are permitted provided that the following conditions |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 return meta_data_list | 117 return meta_data_list |
115 | 118 |
116 | 119 |
117 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat
a_this_partition): | 120 def generate_content(component_dir, aggregate_partial_interfaces, files_meta_dat
a_this_partition): |
118 # Add fixed content. | 121 # Add fixed content. |
119 output = [COPYRIGHT_TEMPLATE, | 122 output = [COPYRIGHT_TEMPLATE, |
120 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] | 123 '#define NO_IMPLICIT_ATOMICSTRING\n\n'] |
121 | 124 |
122 # List all includes. | 125 # List all includes. |
123 files_meta_data_this_partition.sort() | 126 files_meta_data_this_partition.sort() |
| 127 suffix = 'Partial' if aggregate_partial_interfaces else '' |
124 for meta_data in files_meta_data_this_partition: | 128 for meta_data in files_meta_data_this_partition: |
125 if aggregate_partial_interfaces: | 129 cpp_filename = 'V8%s%s.cpp' % (meta_data['name'], suffix) |
126 cpp_filename = 'V8%sPartial.cpp' % meta_data['name'] | |
127 else: | |
128 cpp_filename = 'V8%s.cpp' % meta_data['name'] | |
129 | 130 |
130 output.append('#include "bindings/%s/v8/%s"\n' % | 131 output.append('#include "bindings/%s/v8/%s"\n' % |
131 (component_dir, cpp_filename)) | 132 (component_dir, cpp_filename)) |
132 | 133 |
133 return ''.join(output) | 134 return ''.join(output) |
134 | 135 |
135 | 136 |
136 def write_content(content, output_file_name): | 137 def write_content(content, output_file_name): |
137 parent_path, file_name = os.path.split(output_file_name) | 138 parent_path, file_name = os.path.split(output_file_name) |
138 if not os.path.exists(parent_path): | 139 if not os.path.exists(parent_path): |
139 print 'Creating directory: %s' % parent_path | 140 print 'Creating directory: %s' % parent_path |
140 os.makedirs(parent_path) | 141 os.makedirs(parent_path) |
141 with open(output_file_name, 'w') as f: | 142 with open(output_file_name, 'w') as f: |
142 f.write(content) | 143 f.write(content) |
143 | 144 |
144 | 145 |
145 def parse_options(): | 146 def parse_options(): |
146 parser = optparse.OptionParser() | 147 parser = optparse.OptionParser() |
147 parser.add_option('--component-directory') | 148 parser.add_option('--component-directory') |
148 parser.add_option('--input-file', | 149 parser.add_option('--input-file', |
149 help='A file name which lists up target IDL file names.', | 150 help='A file name which lists up target IDL file names.', |
150 type='string') | 151 type='string') |
| 152 parser.add_option('--partial', |
| 153 help='To parse partial IDLs, add this option.', |
| 154 action='store_true', |
| 155 dest='partial', |
| 156 default=False) |
151 | 157 |
152 options, output_file_names = parser.parse_args() | 158 options, output_file_names = parser.parse_args() |
153 if len(output_file_names) == 0: | 159 if len(output_file_names) == 0: |
154 raise Exception('Expected at least one output file name(s).') | 160 raise Exception('Expected at least one output file name(s).') |
155 if not options.input_file: | 161 if not options.input_file: |
156 raise Exception('No input file is specified.') | 162 raise Exception('No input file is specified.') |
157 | 163 |
158 return options, output_file_names | 164 return options, output_file_names |
159 | 165 |
160 | 166 |
161 def main(): | 167 def main(): |
162 options, output_file_names = parse_options() | 168 options, output_file_names = parse_options() |
163 component_dir = options.component_directory | 169 component_dir = options.component_directory |
164 input_file_name = options.input_file | 170 input_file_name = options.input_file |
165 | 171 aggregate_partial_interfaces = options.partial |
166 idl_file_names = read_idl_files_list_from_file(input_file_name, | 172 idl_file_names = read_idl_files_list_from_file(input_file_name, |
167 is_gyp_format=True) | 173 is_gyp_format=True) |
168 components = set([idl_filename_to_component(filename) | |
169 for filename in idl_file_names]) | |
170 if len(components) != 1: | |
171 raise Exception('Cannot aggregate generated codes in different component
s') | |
172 aggregate_partial_interfaces = component_dir not in components | |
173 | 174 |
174 files_meta_data = extract_meta_data(idl_file_names) | 175 files_meta_data = extract_meta_data(idl_file_names) |
175 total_partitions = len(output_file_names) | 176 total_partitions = len(output_file_names) |
176 for partition, file_name in enumerate(output_file_names): | 177 for partition, file_name in enumerate(output_file_names): |
177 files_meta_data_this_partition = [ | 178 files_meta_data_this_partition = [ |
178 meta_data for meta_data in files_meta_data | 179 meta_data for meta_data in files_meta_data |
179 if hash(meta_data['name']) % total_partitions == partition] | 180 if hash(meta_data['name']) % total_partitions == partition] |
180 file_contents = generate_content(component_dir, | 181 file_contents = generate_content(component_dir, |
181 aggregate_partial_interfaces, | 182 aggregate_partial_interfaces, |
182 files_meta_data_this_partition) | 183 files_meta_data_this_partition) |
183 write_content(file_contents, file_name) | 184 write_content(file_contents, file_name) |
184 | 185 |
185 | 186 |
186 if __name__ == '__main__': | 187 if __name__ == '__main__': |
187 sys.exit(main()) | 188 sys.exit(main()) |
OLD | NEW |