OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # | 2 # |
3 # Copyright (C) 2013 Google Inc. All rights reserved. | 3 # Copyright (C) 2013 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 interfaces_info = {} | 51 interfaces_info = {} |
52 partial_interface_files = defaultdict(lambda: { | 52 partial_interface_files = defaultdict(lambda: { |
53 'full_paths': [], | 53 'full_paths': [], |
54 'include_paths': [], | 54 'include_paths': [], |
55 }) | 55 }) |
56 | 56 |
57 | 57 |
58 def parse_options(): | 58 def parse_options(): |
59 usage = 'Usage: %prog [options] [generated1.idl]...' | 59 usage = 'Usage: %prog [options] [generated1.idl]...' |
60 parser = optparse.OptionParser(usage=usage) | 60 parser = optparse.OptionParser(usage=usage) |
| 61 parser.add_option('--component-dir', help='component directory') |
61 parser.add_option('--idl-files-list', help='file listing IDL files') | 62 parser.add_option('--idl-files-list', help='file listing IDL files') |
62 parser.add_option('--interfaces-info-file', help='output pickle file') | 63 parser.add_option('--interfaces-info-file', help='output pickle file') |
63 parser.add_option('--write-file-only-if-changed', type='int', help='if true,
do not write an output file if it would be identical to the existing one, which
avoids unnecessary rebuilds in ninja') | 64 parser.add_option('--write-file-only-if-changed', type='int', help='if true,
do not write an output file if it would be identical to the existing one, which
avoids unnecessary rebuilds in ninja') |
64 | 65 |
65 options, args = parser.parse_args() | 66 options, args = parser.parse_args() |
| 67 if options.component_dir is None: |
| 68 parser.error('Must specify a component directory using --component-dir.'
) |
66 if options.interfaces_info_file is None: | 69 if options.interfaces_info_file is None: |
67 parser.error('Must specify an output file using --interfaces-info-file.'
) | 70 parser.error('Must specify an output file using --interfaces-info-file.'
) |
68 if options.idl_files_list is None: | 71 if options.idl_files_list is None: |
69 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') | 72 parser.error('Must specify a file listing IDL files using --idl-files-li
st.') |
70 if options.write_file_only_if_changed is None: | 73 if options.write_file_only_if_changed is None: |
71 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') | 74 parser.error('Must specify whether file is only written if changed using
--write-file-only-if-changed.') |
72 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) | 75 options.write_file_only_if_changed = bool(options.write_file_only_if_changed
) |
73 return options, args | 76 return options, args |
74 | 77 |
75 | 78 |
(...skipping 17 matching lines...) Expand all Loading... |
93 return posixpath.join(relative_dir_posix, cpp_class_name + '.h') | 96 return posixpath.join(relative_dir_posix, cpp_class_name + '.h') |
94 | 97 |
95 | 98 |
96 def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p
ath=None): | 99 def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p
ath=None): |
97 paths_dict = partial_interface_files[partial_interface_name] | 100 paths_dict = partial_interface_files[partial_interface_name] |
98 paths_dict['full_paths'].append(full_path) | 101 paths_dict['full_paths'].append(full_path) |
99 if this_include_path: | 102 if this_include_path: |
100 paths_dict['include_paths'].append(this_include_path) | 103 paths_dict['include_paths'].append(this_include_path) |
101 | 104 |
102 | 105 |
103 def compute_info_individual(idl_filename): | 106 def compute_info_individual(idl_filename, component_dir): |
104 full_path = os.path.realpath(idl_filename) | 107 full_path = os.path.realpath(idl_filename) |
105 idl_file_contents = get_file_contents(full_path) | 108 idl_file_contents = get_file_contents(full_path) |
106 | 109 |
107 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) | 110 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) |
108 implemented_as = extended_attributes.get('ImplementedAs') | 111 implemented_as = extended_attributes.get('ImplementedAs') |
109 this_include_path = include_path(idl_filename, implemented_as) | 112 this_include_path = include_path(idl_filename, implemented_as) |
110 | 113 |
111 # Handle partial interfaces | 114 # Handle partial interfaces |
112 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) | 115 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) |
113 if partial_interface_name: | 116 if partial_interface_name: |
114 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu
de_path) | 117 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu
de_path) |
115 return | 118 return |
116 | 119 |
117 # If not a partial interface, the basename is the interface name | 120 # If not a partial interface, the basename is the interface name |
118 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 121 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) |
119 | 122 |
120 # 'implements' statements can be included in either the file for the | 123 # 'implements' statements can be included in either the file for the |
121 # implement*ing* interface (lhs of 'implements') or implement*ed* interface | 124 # implement*ing* interface (lhs of 'implements') or implement*ed* interface |
122 # (rhs of 'implements'). Store both for now, then merge to implement*ing* | 125 # (rhs of 'implements'). Store both for now, then merge to implement*ing* |
123 # interface later. | 126 # interface later. |
124 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content
s, interface_name) | 127 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content
s, interface_name) |
125 | 128 |
126 interfaces_info[interface_name] = { | 129 interfaces_info[interface_name] = { |
| 130 'component_dir': component_dir, |
127 'extended_attributes': extended_attributes, | 131 'extended_attributes': extended_attributes, |
128 'full_path': full_path, | 132 'full_path': full_path, |
129 'implemented_as': implemented_as, | 133 'implemented_as': implemented_as, |
130 'implemented_by_interfaces': left_interfaces, # private, merged to next | 134 'implemented_by_interfaces': left_interfaces, # private, merged to next |
131 'implements_interfaces': right_interfaces, | 135 'implements_interfaces': right_interfaces, |
132 'include_path': this_include_path, | 136 'include_path': this_include_path, |
133 # FIXME: temporary private field, while removing old treatement of | 137 # FIXME: temporary private field, while removing old treatement of |
134 # 'implements': http://crbug.com/360435 | 138 # 'implements': http://crbug.com/360435 |
135 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface'
in extended_attributes, | 139 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface'
in extended_attributes, |
136 'is_callback_interface': is_callback_interface_from_idl(idl_file_content
s), | 140 'is_callback_interface': is_callback_interface_from_idl(idl_file_content
s), |
(...skipping 28 matching lines...) Expand all Loading... |
165 idl_files = [line.rstrip('\n') for line in idl_files_list] | 169 idl_files = [line.rstrip('\n') for line in idl_files_list] |
166 # Generated IDL files are passed at the command line, since these are in the | 170 # Generated IDL files are passed at the command line, since these are in the |
167 # build directory, which is determined at build time, not GYP time, so these | 171 # build directory, which is determined at build time, not GYP time, so these |
168 # cannot be included in the file listing static files | 172 # cannot be included in the file listing static files |
169 idl_files.extend(args) | 173 idl_files.extend(args) |
170 | 174 |
171 # Compute information for individual files | 175 # Compute information for individual files |
172 # Information is stored in global variables interfaces_info and | 176 # Information is stored in global variables interfaces_info and |
173 # partial_interface_files. | 177 # partial_interface_files. |
174 for idl_filename in idl_files: | 178 for idl_filename in idl_files: |
175 compute_info_individual(idl_filename) | 179 compute_info_individual(idl_filename, options.component_dir) |
176 | 180 |
177 write_pickle_file(options.interfaces_info_file, | 181 write_pickle_file(options.interfaces_info_file, |
178 info_individual(), | 182 info_individual(), |
179 options.write_file_only_if_changed) | 183 options.write_file_only_if_changed) |
180 | 184 |
181 | 185 |
182 if __name__ == '__main__': | 186 if __name__ == '__main__': |
183 sys.exit(main()) | 187 sys.exit(main()) |
OLD | NEW |