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

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

Issue 18190004: Add Python flow to bindings generation, move dummy-generating IDL files over (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Revision 4 (IdlDocument -> IdlDefinitions) Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are
5 # met:
6 #
7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer
11 # in the documentation and/or other materials provided with the
12 # distribution.
13 # * Neither the name of Google Inc. nor the names of its
14 # contributors may be used to endorse or promote products derived from
15 # this software without specific prior written permission.
16 #
17 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 """Resolve interface dependencies, producing a merged IdlDefinitions object.
30
31 This library computes interface dependencies (partial interfaces and
32 implements), reads the dependency files, and merges them to the IdlDefinitions
33 for the main IDL file, producing an IdlDefinitions object representing the
34 entire interface.
35
36 It also checks whether a file should have bindings generated, or whether
37 instead it is just a dependency.
38
39 FIXME: Currently a stub, as part of landing the parser incrementally.
40 Just computes dependencies, and should always return None, indicating
41 bindings should not be generated.
42 Does not read IDL files or merge IdlDefinitions yet.
43 """
44
45 import os.path
46
47
48 def merge_interface_dependencies(idl_definitions, idl_filename, interface_depend encies_filename, additional_idl_filenames):
49 """Merges dependencies into an existing IDL document.
50
51 Modifies idl_definitions in place by adding parsed dependencies, and checks
52 whether bindings should be generated, returning bool.
53
54 FIXME: stub: parser not implemented yet
55
56 Arguments:
57 idl_definitions: IdlDefinitions object, modified in place
58 idl_filename: filename of main IDL file for the interface
59 interface_dependencies_file: filename of dependencies file (produced by compute_dependencies.py)
60 additional_idl_files: list of additional files, not listed in interface_ dependencies_file, for which bindings should nonetheless be generated
61 Returns:
62 bool, whether bindings should be generated or not.
63 """
64 basename = os.path.basename(idl_filename)
65 interface_name, _ = os.path.splitext(basename)
66
67 dependency_idl_filenames = compute_dependency_idl_files(basename, interface_ dependencies_filename, additional_idl_filenames)
68 if dependency_idl_filenames is None:
69 return False
70 # FIXME: currently dependency_idl_files *must* be None (indicating that
71 # dummy .cpp and .h files should be generated), as actual parser not
72 # present yet.
73 raise RuntimeError('Stub: parser not implemented yet')
74
75
76 def compute_dependency_idl_files(target_idl_basename, interface_dependencies_fil ename, additional_idl_filenames):
77 """Returns list of IDL file dependencies for a given main IDL file.
78
79 - Returns a list of IDL files on which a given IDL file depends,
80 possibly empty.
81 Dependencies consist of partial interface files and files for other
82 interfaces that the given interface implements.
83 - Returns an empty list also if the given IDL file is an additional IDL
84 file.
85 - Otherwise, return None. This happens when the given IDL file is a
86 dependency, for which we don't want to generate bindings.
87 """
88 if interface_dependencies_filename is None:
89 return []
90
91 # The format of the interface dependencies file is:
92 #
93 # Document.idl P.idl
94 # Event.idl
95 # Window.idl Q.idl R.idl S.idl
96 # ...
97 #
98 # The above indicates that:
99 # Document.idl depends on P.idl,
100 # Event.idl depends on no other IDL files, and
101 # Window.idl depends on Q.idl, R.idl, and S.idl.
102 #
103 # The head entries (first IDL file on a line) are the files that should
104 # have bindings generated.
105 #
106 # An IDL file that is a dependency of another IDL file (e.g., P.idl in the
107 # above example) does not have its own line in the dependency file:
108 # dependencies do not have bindings generated, and do not have their
109 # own dependencies.
110 with open(interface_dependencies_filename) as interface_dependencies_file:
111 for line in interface_dependencies_file:
112 idl_filename, _, dependency_filenames = line.partition(' ')
113 if os.path.basename(idl_filename) == target_idl_basename:
114 return dependency_filenames.split()
115
116 # additional_idl_files is a list of IDL files which should not be included
117 # in DerivedSources*.cpp, and hence are not listed in the interface
118 # dependencies file, but for which we should generate .cpp and .h files.
119 additional_idl_basenames = set(map(os.path.basename, additional_idl_filename s))
120 if target_idl_basename in additional_idl_basenames:
121 return []
122
123 return None
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698