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

Side by Side Diff: Source/bindings/scripts/unstable/interface_dependency_resolver.py

Issue 124913002: IDL compiler: Pickle interface information (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revised Created 6 years, 11 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
« no previous file with comments | « Source/bindings/scripts/unstable/idl_reader.py ('k') | Tools/Scripts/webkitpy/bindings/main.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 20 matching lines...) Expand all
31 This library computes interface dependencies (partial interfaces and 31 This library computes interface dependencies (partial interfaces and
32 implements), reads the dependency files, and merges them to the IdlDefinitions 32 implements), reads the dependency files, and merges them to the IdlDefinitions
33 for the main IDL file, producing an IdlDefinitions object representing the 33 for the main IDL file, producing an IdlDefinitions object representing the
34 entire interface. 34 entire interface.
35 35
36 It also checks whether a file should have bindings generated, or whether 36 It also checks whether a file should have bindings generated, or whether
37 instead it is just a dependency. 37 instead it is just a dependency.
38 """ 38 """
39 39
40 import os.path 40 import os.path
41 import cPickle as pickle
41 42
42 43
43 class InterfaceNotFoundError(Exception): 44 class InterfaceNotFoundError(Exception):
44 """Raised if (partial) interface not found in target IDL file.""" 45 """Raised if (partial) interface not found in target IDL file."""
45 pass 46 pass
46 47
47 48
48 class InvalidPartialInterfaceError(Exception): 49 class InvalidPartialInterfaceError(Exception):
49 """Raised if a file listed as a partial interface is not in fact so.""" 50 """Raised if a file listed as a partial interface is not in fact so."""
50 pass 51 pass
51 52
52 53
53 class InterfaceDependencyResolver: 54 class InterfaceDependencyResolver:
54 def __init__(self, interface_dependencies_filename, additional_idl_filenames , reader): 55 def __init__(self, interfaces_info_filename, additional_idl_filenames, reade r):
55 """Inits dependency resolver. 56 """Inits dependency resolver.
56 57
57 Args: 58 Args:
58 interface_dependencies_filename: 59 interfaces_info_filename:
59 filename of dependencies file (produced by 60 interfaces information file, output by compute_dependencies.py
60 compute_dependencies.py)
61 additional_idl_filenames: 61 additional_idl_filenames:
62 list of additional files, not listed in 62 list of additional files, not listed in
63 interface_dependencies_file, for which bindings should 63 interface_dependencies_file, for which bindings should
64 nonetheless be generated 64 nonetheless be generated
65 reader: 65 reader:
66 IdlReader, used for reading dependency files 66 IdlReader, used for reading dependency files
67 """ 67 """
68 self.interface_dependencies = read_interface_dependencies_file(interface _dependencies_filename) 68 with open(interfaces_info_filename, 'r') as interfaces_info_file:
69 self.interface_dependencies = pickle.load(interfaces_info_file)
69 self.additional_interfaces = set() 70 self.additional_interfaces = set()
70 for filename in additional_idl_filenames: 71 for filename in additional_idl_filenames:
71 basename = os.path.basename(filename) 72 basename = os.path.basename(filename)
72 interface_name, _ = os.path.splitext(basename) 73 interface_name, _ = os.path.splitext(basename)
73 self.additional_interfaces.add(interface_name) 74 self.additional_interfaces.add(interface_name)
74 self.reader = reader 75 self.reader = reader
75 76
76 def resolve_dependencies(self, definitions, interface_name): 77 def resolve_dependencies(self, definitions, interface_name):
77 """Resolves dependencies, merging them into IDL definitions of main file . 78 """Resolves dependencies, merging them into IDL definitions of main file .
78 79
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 # additional_interfaces is a list of interfaces that should not be 125 # additional_interfaces is a list of interfaces that should not be
125 # included in DerivedSources*.cpp, and hence are not listed in the 126 # included in DerivedSources*.cpp, and hence are not listed in the
126 # interface dependencies file, but for which we should generate .cpp 127 # interface dependencies file, but for which we should generate .cpp
127 # and .h files. 128 # and .h files.
128 if target_interface_name in self.additional_interfaces: 129 if target_interface_name in self.additional_interfaces:
129 return [] 130 return []
130 131
131 return None 132 return None
132 133
133 134
134 def read_interface_dependencies_file(interface_dependencies_filename):
135 """Reads the interface dependencies file, returns a dict for resolving depen dencies.
136
137 The format of the interface dependencies file is:
138
139 Document.idl P.idl
140 Event.idl
141 Window.idl Q.idl R.idl S.idl
142 ...
143
144 The above indicates that:
145 Document.idl depends on P.idl,
146 Event.idl depends on no other IDL files, and
147 Window.idl depends on Q.idl, R.idl, and S.idl.
148
149 The head entries (first IDL file on a line) are the files that should
150 have bindings generated.
151
152 An IDL file that is a dependency of another IDL file (e.g., P.idl in the
153 above example) does not have its own line in the dependency file:
154 dependencies do not have bindings generated, and do not have their
155 own dependencies.
156
157 Args:
158 interface_dependencies_filename: filename of file in above format
159 Returns:
160 dict of interface_name -> dependency_filenames
161 """
162 interface_dependencies = {}
163 with open(interface_dependencies_filename) as interface_dependencies_file:
164 for line in interface_dependencies_file:
165 idl_filename, _, dependency_filenames_string = line.partition(' ')
166 idl_basename = os.path.basename(idl_filename)
167 interface_name, _ = os.path.splitext(idl_basename)
168 dependency_filenames = dependency_filenames_string.split()
169 interface_dependencies[interface_name] = dependency_filenames
170 return interface_dependencies
171
172
173 def merge_interface_dependencies(target_interface, dependency_idl_filenames, rea der): 135 def merge_interface_dependencies(target_interface, dependency_idl_filenames, rea der):
174 """Merge dependencies ('partial interface' and 'implements') in dependency_i dl_filenames into target_interface. 136 """Merge dependencies ('partial interface' and 'implements') in dependency_i dl_filenames into target_interface.
175 137
176 No return: modifies target_document in place. 138 No return: modifies target_document in place.
177 """ 139 """
178 # Sort so order consistent, so can compare output from run to run. 140 # Sort so order consistent, so can compare output from run to run.
179 for dependency_idl_filename in sorted(dependency_idl_filenames): 141 for dependency_idl_filename in sorted(dependency_idl_filenames):
180 dependency_interface_name, _ = os.path.splitext(os.path.basename(depende ncy_idl_filename)) 142 dependency_interface_name, _ = os.path.splitext(os.path.basename(depende ncy_idl_filename))
181 definitions = reader.read_idl_file(dependency_idl_filename) 143 definitions = reader.read_idl_file(dependency_idl_filename)
182 144
(...skipping 19 matching lines...) Expand all
202 # FIXME: remove check for LegacyImplementedInBaseClass when this 164 # FIXME: remove check for LegacyImplementedInBaseClass when this
203 # attribute is removed 165 # attribute is removed
204 if 'LegacyImplementedInBaseClass' not in dependency_interface.extend ed_attributes: 166 if 'LegacyImplementedInBaseClass' not in dependency_interface.extend ed_attributes:
205 element.extended_attributes['ImplementedBy'] = dependency_interf ace_name 167 element.extended_attributes['ImplementedBy'] = dependency_interf ace_name
206 element.extended_attributes.update(dependency_interface.extended_att ributes) 168 element.extended_attributes.update(dependency_interface.extended_att ributes)
207 target_list.append(element) 169 target_list.append(element)
208 170
209 merge_lists(dependency_interface.attributes, target_interface.attributes) 171 merge_lists(dependency_interface.attributes, target_interface.attributes)
210 merge_lists(dependency_interface.constants, target_interface.constants) 172 merge_lists(dependency_interface.constants, target_interface.constants)
211 merge_lists(dependency_interface.operations, target_interface.operations) 173 merge_lists(dependency_interface.operations, target_interface.operations)
OLDNEW
« no previous file with comments | « Source/bindings/scripts/unstable/idl_reader.py ('k') | Tools/Scripts/webkitpy/bindings/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698