Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 IDL dependencies, producing a merged IdlDocument object. | |
|
haraken
2013/07/10 06:22:48
This should be 'interface dependencies', not 'IDL
Nils Barth (inactive)
2013/07/10 07:04:11
Done.
| |
| 30 | |
| 31 This library computes IDL dependencies (partial interfaces and implements), | |
|
haraken
2013/07/10 06:22:48
interface dependencies
Nils Barth (inactive)
2013/07/10 07:04:11
Done.
| |
| 32 reads the dependency files, and merges them to the IdlDocument for the | |
| 33 main IDL file, producing an IdlDocument representing the entire interface. | |
|
haraken
2013/07/10 06:22:48
IdlDocument => InterfaceDefinition
main IDL file =
Nils Barth (inactive)
2013/07/10 07:04:11
How about IdlDefinitions, which is closer to the s
| |
| 34 | |
| 35 It also checks whether a file should have bindings generated, or whether | |
| 36 instead it is just a dependency. | |
| 37 | |
| 38 FIXME: Currently a stub, as part of landing the parser incrementally. | |
| 39 Just computes dependencies, and should always return None, indicating | |
| 40 bindings should not be generated. | |
| 41 Does not read IDL files or merge IdlDocuments yet. | |
| 42 """ | |
| 43 | |
| 44 import os.path | |
| 45 | |
| 46 | |
| 47 def merge_interface_dependencies(idl_document, idl_filename, interface_dependenc ies_filename, additional_idl_filenames): | |
| 48 """Merges dependencies into an existing IDL document. | |
| 49 | |
| 50 Modifies idl_document in place by adding parsed dependencies, and checks | |
| 51 whether bindings should be generated, returning bool. | |
| 52 | |
| 53 FIXME: stub: parser not implemented yet | |
| 54 | |
| 55 Arguments: | |
| 56 idl_document: IdlDocument object, modified in place | |
| 57 idl_filename: filename of main IDL file | |
| 58 interface_dependencies_file: filename of dependencies file (produced by compute_dependencies.py) | |
| 59 additional_idl_files: list of additional files, not listed in interface_ dependencies_file, for which bindings should nonetheless be generated | |
| 60 Returns: | |
| 61 bool, whether bindings should be generated or not. | |
| 62 """ | |
| 63 basename = os.path.basename(idl_filename) | |
| 64 interface_name, _ = os.path.splitext(basename) | |
| 65 | |
| 66 dependency_idl_filenames = compute_dependency_idl_files(basename, interface_ dependencies_filename, additional_idl_filenames) | |
| 67 if dependency_idl_filenames is None: | |
| 68 return False | |
| 69 # FIXME: currently dependency_idl_files *must* be None (indicating that | |
| 70 # dummy .cpp and .h files should be generated), as actual parser not | |
| 71 # present yet. | |
| 72 raise RuntimeError('Stub: parser not implemented yet') | |
| 73 | |
| 74 | |
| 75 def compute_dependency_idl_files(target_idl_basename, interface_dependencies_fil ename, additional_idl_filenames): | |
| 76 """Returns list of IDL file dependencies for a given main IDL file. | |
| 77 | |
| 78 - Returns a list of IDL files on which a given IDL file depends, | |
| 79 possibly empty. | |
| 80 Dependencies consist of partial interface files and files for other | |
| 81 interfaces that the given interface implements. | |
| 82 - Returns an empty list also if the given IDL file is an additional IDL | |
| 83 file. | |
| 84 - Otherwise, return None. This happens when the given IDL file is a | |
| 85 dependency, for which we don't want to generate bindings. | |
| 86 """ | |
| 87 if interface_dependencies_filename is None: | |
| 88 return [] | |
| 89 | |
| 90 # The format of the interface dependencies file is: | |
| 91 # | |
| 92 # Document.idl P.idl | |
| 93 # Event.idl | |
| 94 # Window.idl Q.idl R.idl S.idl | |
| 95 # ... | |
| 96 # | |
| 97 # The above indicates that: | |
| 98 # Document.idl depends on P.idl, | |
| 99 # Event.idl depends on no other IDL files, and | |
| 100 # Window.idl depends on Q.idl, R.idl, and S.idl. | |
| 101 # | |
| 102 # The head entries (first IDL file on a line) are the files that should | |
| 103 # have bindings generated. | |
| 104 # | |
| 105 # An IDL file that is a dependency of another IDL file (e.g., P.idl in the | |
| 106 # above example) does not have its own line in the dependency file: | |
| 107 # dependencies do not have bindings generated, and do not have their | |
| 108 # own dependencies. | |
| 109 with open(interface_dependencies_filename) as interface_dependencies_file: | |
| 110 for line in interface_dependencies_file: | |
| 111 idl_filename, _, dependency_filenames = line.partition(' ') | |
| 112 if os.path.basename(idl_filename) == target_idl_basename: | |
| 113 return dependency_filenames.split() | |
| 114 | |
| 115 # additional_idl_files is a list of IDL files which should not be included | |
| 116 # in DerivedSources*.cpp, and hence are not listed in the interface | |
| 117 # dependencies file, but for which we should generate .cpp and .h files. | |
| 118 additional_idl_basenames = set(map(os.path.basename, additional_idl_filename s)) | |
| 119 if target_idl_basename in additional_idl_basenames: | |
| 120 return [] | |
| 121 | |
| 122 return None | |
| OLD | NEW |