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

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

Issue 300273005: Bindings build: split compute_interfaces_info into 2 stages (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Remove debugging Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 #!/usr/bin/python
2 #
3 # Copyright (C) 2013 Google Inc. All rights reserved.
4 #
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met:
8 #
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following disclaimer
13 # in the documentation and/or other materials provided with the
14 # distribution.
15 # * Neither the name of Google Inc. nor the names of its
16 # contributors may be used to endorse or promote products derived from
17 # this software without specific prior written permission.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 """Compute global interface information for individual IDL files.
32
33 Auxiliary module for compute_interfaces_info_overall, which consolidates
34 this individual information.
35
36 Design doc: http://www.chromium.org/developers/design-documents/idl-build
37 """
38
39 from collections import defaultdict
40 import optparse
41 import os
42 import posixpath
43 import sys
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
46
47 module_path = os.path.dirname(__file__)
48 source_path = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
49
50 # Global variables (filled in and exported)
51 interfaces_info = {}
52 partial_interface_files = defaultdict(lambda: {
53 'full_paths': [],
54 'include_paths': [],
55 })
56
57
58 def parse_options():
59 usage = 'Usage: %prog [options] [generated1.idl]...'
60 parser = optparse.OptionParser(usage=usage)
61 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('--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 options, args = parser.parse_args()
66 if options.interfaces_info_file is None:
67 parser.error('Must specify an output file using --interfaces-info-file.' )
68 if options.idl_files_list is None:
69 parser.error('Must specify a file listing IDL files using --idl-files-li st.')
70 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.')
72 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
73 return options, args
74
75
76 ################################################################################
77 # Computations
78 ################################################################################
79
80 def include_path(idl_filename, implemented_as=None):
81 """Returns relative path to header file in POSIX format; used in includes.
82
83 POSIX format is used for consistency of output, so reference tests are
84 platform-independent.
85 """
86 relative_path_local = os.path.relpath(idl_filename, source_path)
87 relative_dir_local = os.path.dirname(relative_path_local)
88 relative_dir_posix = relative_dir_local.replace(os.path.sep, posixpath.sep)
89
90 idl_file_basename, _ = os.path.splitext(os.path.basename(idl_filename))
91 cpp_class_name = implemented_as or idl_file_basename
92
93 return posixpath.join(relative_dir_posix, cpp_class_name + '.h')
94
95
96 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]
98 paths_dict['full_paths'].append(full_path)
99 if this_include_path:
100 paths_dict['include_paths'].append(this_include_path)
101
102
103 def compute_individual_info(idl_filename):
104 full_path = os.path.realpath(idl_filename)
105 idl_file_contents = get_file_contents(full_path)
106
107 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents)
108 implemented_as = extended_attributes.get('ImplementedAs')
109 this_include_path = include_path(idl_filename, implemented_as)
110
111 # Handle partial interfaces
112 partial_interface_name = get_partial_interface_name_from_idl(idl_file_conten ts)
113 if partial_interface_name:
114 add_paths_to_partials_dict(partial_interface_name, full_path, this_inclu de_path)
115 return
116
117 # If not a partial interface, the basename is the interface name
118 interface_name, _ = os.path.splitext(os.path.basename(idl_filename))
119
120 # 'implements' statements can be included in either the file for the
121 # implement*ing* interface (lhs of 'implements') or implement*ed* interface
122 # (rhs of 'implements'). Store both for now, then merge to implement*ing*
123 # interface later.
124 left_interfaces, right_interfaces = get_implements_from_idl(idl_file_content s, interface_name)
125
126 interfaces_info[interface_name] = {
127 'extended_attributes': extended_attributes,
128 'full_path': full_path,
129 'implemented_as': implemented_as,
130 'implemented_by_interfaces': left_interfaces, # private, merged to next
131 'implements_interfaces': right_interfaces,
132 'include_path': this_include_path,
133 # FIXME: temporary private field, while removing old treatement of
134 # 'implements': http://crbug.com/360435
135 'is_legacy_treat_as_partial_interface': 'LegacyTreatAsPartialInterface' in extended_attributes,
136 'is_callback_interface': is_callback_interface_from_idl(idl_file_content s),
137 'parent': get_parent_interface(idl_file_contents),
138 # Interfaces that are referenced (used as types) and that we introspect
139 # during code generation (beyond interface-level data ([ImplementedAs],
140 # is_callback_interface, ancestors, and inherited extended attributes):
141 # deep dependencies.
142 # These cause rebuilds of referrers, due to the dependency, so these
143 # should be minimized; currently only targets of [PutForwards].
144 'referenced_interfaces': get_put_forward_interfaces_from_idl(idl_file_co ntents),
145 }
146
147
148 ################################################################################
149
150 def main():
151 options, args = parse_options()
152
153 # Static IDL files are passed in a file (generated at GYP time), due to OS
154 # command line length limits
155 with open(options.idl_files_list) as idl_files_list:
156 idl_files = [line.rstrip('\n') for line in idl_files_list]
157 # Generated IDL files are passed at the command line, since these are in the
158 # build directory, which is determined at build time, not GYP time, so these
159 # cannot be included in the file listing static files
160 idl_files.extend(args)
161
162 # Compute information for individual files
163 # Information is stored in global variables interfaces_info and
164 # partial_interface_files.
165 for idl_filename in idl_files:
166 compute_individual_info(idl_filename)
167
168 write_pickle_file(options.interfaces_info_file,
169 {
170 'interfaces_info': interfaces_info,
171 # Can't pickle defaultdict, convert to dict
172 'partial_interface_files': dict(partial_interface_file s),
173 },
174 options.write_file_only_if_changed)
175
176
177 if __name__ == '__main__':
178 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/scripts/compute_interfaces_info.py ('k') | Source/bindings/scripts/compute_interfaces_info_overall.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698