| 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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 Design doc: http://www.chromium.org/developers/design-documents/idl-build | 36 Design doc: http://www.chromium.org/developers/design-documents/idl-build |
| 37 """ | 37 """ |
| 38 | 38 |
| 39 from collections import defaultdict | 39 from collections import defaultdict |
| 40 import optparse | 40 import optparse |
| 41 import os | 41 import os |
| 42 import posixpath | 42 import posixpath |
| 43 import sys | 43 import sys |
| 44 | 44 |
| 45 from utilities import get_file_contents, write_pickle_file, get_interface_extend
ed_attributes_from_idl, is_callback_interface_from_idl, get_partial_interface_na
me_from_idl, get_implements_from_idl, get_parent_interface, get_put_forward_inte
rfaces_from_idl | 45 from utilities import get_file_contents, read_file_to_list, idl_filename_to_inte
rface_name, write_pickle_file, get_interface_extended_attributes_from_idl, is_ca
llback_interface_from_idl, get_partial_interface_name_from_idl, get_implements_f
rom_idl, get_parent_interface, get_put_forward_interfaces_from_idl |
| 46 | 46 |
| 47 module_path = os.path.dirname(__file__) | 47 module_path = os.path.dirname(__file__) |
| 48 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) | 48 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) |
| 49 | 49 |
| 50 # Global variables (filled in and exported) | 50 # Global variables (filled in and exported) |
| 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 }) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 83 def include_path(idl_filename, implemented_as=None): | 83 def include_path(idl_filename, implemented_as=None): |
| 84 """Returns relative path to header file in POSIX format; used in includes. | 84 """Returns relative path to header file in POSIX format; used in includes. |
| 85 | 85 |
| 86 POSIX format is used for consistency of output, so reference tests are | 86 POSIX format is used for consistency of output, so reference tests are |
| 87 platform-independent. | 87 platform-independent. |
| 88 """ | 88 """ |
| 89 relative_path_local = os.path.relpath(idl_filename, source_path) | 89 relative_path_local = os.path.relpath(idl_filename, source_path) |
| 90 relative_dir_local = os.path.dirname(relative_path_local) | 90 relative_dir_local = os.path.dirname(relative_path_local) |
| 91 relative_dir_posix = relative_dir_local.replace(os.path.sep, posixpath.sep) | 91 relative_dir_posix = relative_dir_local.replace(os.path.sep, posixpath.sep) |
| 92 | 92 |
| 93 # IDL file basename is used even if only a partial interface file |
| 93 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) | 94 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) |
| 94 cpp_class_name = implemented_as or idl_file_basename | 95 cpp_class_name = implemented_as or idl_file_basename |
| 95 | 96 |
| 96 return posixpath.join(relative_dir_posix, cpp_class_name + '.h') | 97 return posixpath.join(relative_dir_posix, cpp_class_name + '.h') |
| 97 | 98 |
| 98 | 99 |
| 99 def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p
ath=None): | 100 def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p
ath=None): |
| 100 paths_dict = partial_interface_files[partial_interface_name] | 101 paths_dict = partial_interface_files[partial_interface_name] |
| 101 paths_dict['full_paths'].append(full_path) | 102 paths_dict['full_paths'].append(full_path) |
| 102 if this_include_path: | 103 if this_include_path: |
| 103 paths_dict['include_paths'].append(this_include_path) | 104 paths_dict['include_paths'].append(this_include_path) |
| 104 | 105 |
| 105 | 106 |
| 106 def compute_info_individual(idl_filename, component_dir): | 107 def compute_info_individual(idl_filename, component_dir): |
| 107 full_path = os.path.realpath(idl_filename) | 108 full_path = os.path.realpath(idl_filename) |
| 108 idl_file_contents = get_file_contents(full_path) | 109 idl_file_contents = get_file_contents(full_path) |
| 109 | 110 |
| 110 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) | 111 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co
ntents) |
| 111 implemented_as = extended_attributes.get('ImplementedAs') | 112 implemented_as = extended_attributes.get('ImplementedAs') |
| 112 this_include_path = include_path(idl_filename, implemented_as) | 113 this_include_path = include_path(idl_filename, implemented_as) |
| 113 | 114 |
| 114 # Handle partial interfaces | 115 # Handle partial interfaces |
| 115 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) | 116 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten
ts) |
| 116 if partial_interface_name: | 117 if partial_interface_name: |
| 117 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu
de_path) | 118 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu
de_path) |
| 118 return | 119 return |
| 119 | 120 |
| 120 # If not a partial interface, the basename is the interface name | 121 # If not a partial interface, the basename is the interface name |
| 121 interface_name, _ = os.path.splitext(os.path.basename(idl_filename)) | 122 interface_name = idl_filename_to_interface_name(idl_filename) |
| 122 | 123 |
| 123 # 'implements' statements can be included in either the file for the | 124 # 'implements' statements can be included in either the file for the |
| 124 # implement*ing* interface (lhs of 'implements') or implement*ed* interface | 125 # implement*ing* interface (lhs of 'implements') or implement*ed* interface |
| 125 # (rhs of 'implements'). Store both for now, then merge to implement*ing* | 126 # (rhs of 'implements'). Store both for now, then merge to implement*ing* |
| 126 # interface later. | 127 # interface later. |
| 127 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content
s, interface_name) | 128 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content
s, interface_name) |
| 128 | 129 |
| 129 interfaces_info[interface_name] = { | 130 interfaces_info[interface_name] = { |
| 130 'component_dir': component_dir, | 131 'component_dir': component_dir, |
| 131 'extended_attributes': extended_attributes, | 132 'extended_attributes': extended_attributes, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 158 } | 159 } |
| 159 | 160 |
| 160 | 161 |
| 161 ################################################################################ | 162 ################################################################################ |
| 162 | 163 |
| 163 def main(): | 164 def main(): |
| 164 options, args = parse_options() | 165 options, args = parse_options() |
| 165 | 166 |
| 166 # Static IDL files are passed in a file (generated at GYP time), due to OS | 167 # Static IDL files are passed in a file (generated at GYP time), due to OS |
| 167 # command line length limits | 168 # command line length limits |
| 168 with open(options.idl_files_list) as idl_files_list: | 169 idl_files = read_file_to_list(options.idl_files_list) |
| 169 idl_files = [line.rstrip('\n') for line in idl_files_list] | |
| 170 # 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 |
| 171 # 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 |
| 172 # cannot be included in the file listing static files | 172 # cannot be included in the file listing static files |
| 173 idl_files.extend(args) | 173 idl_files.extend(args) |
| 174 | 174 |
| 175 # Compute information for individual files | 175 # Compute information for individual files |
| 176 # Information is stored in global variables interfaces_info and | 176 # Information is stored in global variables interfaces_info and |
| 177 # partial_interface_files. | 177 # partial_interface_files. |
| 178 for idl_filename in idl_files: | 178 for idl_filename in idl_files: |
| 179 compute_info_individual(idl_filename, options.component_dir) | 179 compute_info_individual(idl_filename, options.component_dir) |
| 180 | 180 |
| 181 write_pickle_file(options.interfaces_info_file, | 181 write_pickle_file(options.interfaces_info_file, |
| 182 info_individual(), | 182 info_individual(), |
| 183 options.write_file_only_if_changed) | 183 options.write_file_only_if_changed) |
| 184 | 184 |
| 185 | 185 |
| 186 if __name__ == '__main__': | 186 if __name__ == '__main__': |
| 187 sys.exit(main()) | 187 sys.exit(main()) |
| OLD | NEW |