Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: Source/bindings/scripts/compute_interfaces_info_individual.py

Issue 386963003: [WIP][NotForLand] IDL dictionary support (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: sequence and array support Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 29 matching lines...) Expand all
40 40
41 Design doc: http://www.chromium.org/developers/design-documents/idl-build 41 Design doc: http://www.chromium.org/developers/design-documents/idl-build
42 """ 42 """
43 43
44 from collections import defaultdict 44 from collections import defaultdict
45 import optparse 45 import optparse
46 import os 46 import os
47 import posixpath 47 import posixpath
48 import sys 48 import sys
49 49
50 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 50 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, is_dictionary_from_idl, get_partial_interface_name_fr om_idl, get_implements_from_idl, get_parent_interface, get_put_forward_interface s_from_idl
51 51
52 module_path = os.path.dirname(__file__) 52 module_path = os.path.dirname(__file__)
53 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir)) 53 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
54 54
55 # Global variables (filled in and exported) 55 # Global variables (filled in and exported)
56 interfaces_info = {} 56 interfaces_info = {}
57 partial_interface_files = defaultdict(lambda: { 57 partial_interface_files = defaultdict(lambda: {
58 'full_paths': [], 58 'full_paths': [],
59 'include_paths': [], 59 'include_paths': [],
60 }) 60 })
(...skipping 17 matching lines...) Expand all
78 if options.write_file_only_if_changed is None: 78 if options.write_file_only_if_changed is None:
79 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.') 79 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.')
80 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) 80 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
81 return options, args 81 return options, args
82 82
83 83
84 ################################################################################ 84 ################################################################################
85 # Computations 85 # Computations
86 ################################################################################ 86 ################################################################################
87 87
88 def relative_dir_posix(idl_filename):
89 """Returns relative path to the directory of idl_file in POSIX format."""
90 relative_path_local = os.path.relpath(idl_filename, source_path)
91 relative_dir_local = os.path.dirname(relative_path_local)
92 return relative_dir_local.replace(os.path.sep, posixpath.sep)
93
94
88 def include_path(idl_filename, implemented_as=None): 95 def include_path(idl_filename, implemented_as=None):
89 """Returns relative path to header file in POSIX format; used in includes. 96 """Returns relative path to header file in POSIX format; used in includes.
90 97
91 POSIX format is used for consistency of output, so reference tests are 98 POSIX format is used for consistency of output, so reference tests are
92 platform-independent. 99 platform-independent.
93 """ 100 """
94 relative_path_local = os.path.relpath(idl_filename, source_path) 101 relative_dir = relative_dir_posix(idl_filename)
95 relative_dir_local = os.path.dirname(relative_path_local)
96 relative_dir_posix = relative_dir_local.replace(os.path.sep, posixpath.sep)
97
98 # IDL file basename is used even if only a partial interface file 102 # IDL file basename is used even if only a partial interface file
99 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename)) 103 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
100 cpp_class_name = implemented_as or idl_file_basename 104 cpp_class_name = implemented_as or idl_file_basename
101 105
102 return posixpath.join(relative_dir_posix, cpp_class_name + '.h') 106 return posixpath.join(relative_dir, cpp_class_name + '.h')
103 107
104 108
105 def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p ath=None): 109 def add_paths_to_partials_dict(partial_interface_name, full_path, this_include_p ath=None):
106 paths_dict = partial_interface_files[partial_interface_name] 110 paths_dict = partial_interface_files[partial_interface_name]
107 paths_dict['full_paths'].append(full_path) 111 paths_dict['full_paths'].append(full_path)
108 if this_include_path: 112 if this_include_path:
109 paths_dict['include_paths'].append(this_include_path) 113 paths_dict['include_paths'].append(this_include_path)
110 114
111 115
112 def compute_info_individual(idl_filename, component_dir): 116 def compute_info_individual(idl_filename, component_dir):
113 full_path = os.path.realpath(idl_filename) 117 full_path = os.path.realpath(idl_filename)
114 idl_file_contents = get_file_contents(full_path) 118 idl_file_contents = get_file_contents(full_path)
115 119
116 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents) 120 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents)
117 implemented_as = extended_attributes.get('ImplementedAs') 121 implemented_as = extended_attributes.get('ImplementedAs')
118 this_include_path = include_path(idl_filename, implemented_as) 122 this_include_path = include_path(idl_filename, implemented_as)
123 relative_dir = relative_dir_posix(idl_filename)
119 124
120 # Handle partial interfaces 125 # Handle partial interfaces
121 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten ts) 126 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten ts)
122 if partial_interface_name: 127 if partial_interface_name:
123 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu de_path) 128 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu de_path)
124 return 129 return
125 130
126 # If not a partial interface, the basename is the interface name 131 # If not a partial interface, the basename is the interface name
127 interface_name = idl_filename_to_interface_name(idl_filename) 132 interface_name = idl_filename_to_interface_name(idl_filename)
128 133
129 # 'implements' statements can be included in either the file for the 134 # 'implements' statements can be included in either the file for the
130 # implement*ing* interface (lhs of 'implements') or implement*ed* interface 135 # implement*ing* interface (lhs of 'implements') or implement*ed* interface
131 # (rhs of 'implements'). Store both for now, then merge to implement*ing* 136 # (rhs of 'implements'). Store both for now, then merge to implement*ing*
132 # interface later. 137 # interface later.
133 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content s, interface_name) 138 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content s, interface_name)
134 139
135 interfaces_info[interface_name] = { 140 interfaces_info[interface_name] = {
136 'component_dir': component_dir, 141 'component_dir': component_dir,
137 'extended_attributes': extended_attributes, 142 'extended_attributes': extended_attributes,
138 'full_path': full_path, 143 'full_path': full_path,
139 'implemented_as': implemented_as, 144 'implemented_as': implemented_as,
140 'implemented_by_interfaces': left_interfaces, # private, merged to next 145 'implemented_by_interfaces': left_interfaces, # private, merged to next
141 'implements_interfaces': right_interfaces, 146 'implements_interfaces': right_interfaces,
142 'include_path': this_include_path, 147 'include_path': this_include_path,
148 'is_callback_interface': is_callback_interface_from_idl(idl_file_content s),
149 'is_dictionary': is_dictionary_from_idl(idl_file_contents),
143 # FIXME: temporary private field, while removing old treatement of 150 # FIXME: temporary private field, while removing old treatement of
144 # 'implements': http://crbug.com/360435 151 # 'implements': http://crbug.com/360435
145 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface' in extended_attributes, 152 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface' in extended_attributes,
146 'is_callback_interface': is_callback_interface_from_idl(idl_file_content s),
147 'parent': get_parent_interface(idl_file_contents), 153 'parent': get_parent_interface(idl_file_contents),
148 # Interfaces that are referenced (used as types) and that we introspect 154 # Interfaces that are referenced (used as types) and that we introspect
149 # during code generation (beyond interface-level data ([ImplementedAs], 155 # during code generation (beyond interface-level data ([ImplementedAs],
150 # is_callback_interface, ancestors, and inherited extended attributes): 156 # is_callback_interface, ancestors, and inherited extended attributes):
151 # deep dependencies. 157 # deep dependencies.
152 # These cause rebuilds of referrers, due to the dependency, so these 158 # These cause rebuilds of referrers, due to the dependency, so these
153 # should be minimized; currently only targets of [PutForwards]. 159 # should be minimized; currently only targets of [PutForwards].
154 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_co ntents), 160 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_co ntents),
161 'relative_dir': relative_dir,
155 } 162 }
156 163
157 164
158 def info_individual(): 165 def info_individual():
159 """Returns info packaged as a dict.""" 166 """Returns info packaged as a dict."""
160 return { 167 return {
161 'interfaces_info': interfaces_info, 168 'interfaces_info': interfaces_info,
162 # Can't pickle defaultdict, convert to dict 169 # Can't pickle defaultdict, convert to dict
163 'partial_interface_files': dict(partial_interface_files), 170 'partial_interface_files': dict(partial_interface_files),
164 } 171 }
(...skipping 18 matching lines...) Expand all
183 for idl_filename in idl_files: 190 for idl_filename in idl_files:
184 compute_info_individual(idl_filename, options.component_dir) 191 compute_info_individual(idl_filename, options.component_dir)
185 192
186 write_pickle_file(options.interfaces_info_file, 193 write_pickle_file(options.interfaces_info_file,
187 info_individual(), 194 info_individual(),
188 options.write_file_only_if_changed) 195 options.write_file_only_if_changed)
189 196
190 197
191 if __name__ == '__main__': 198 if __name__ == '__main__':
192 sys.exit(main()) 199 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/scripts/code_generator_v8.py ('k') | Source/bindings/scripts/generate_global_constructors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698