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

Side by Side Diff: sky/engine/bindings2/scripts/generate_event_interfaces.py

Issue 915293003: Rename sky/engine/bindings2 to sky/engine/bindings (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: more better Created 5 years, 10 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
(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 """Generate event interfaces .in file (EventInterfaces.in).
32
33 The event interfaces .in file contains a list of all Event interfaces, i.e.,
34 all interfaces that inherit from Event, including Event itself,
35 together with certain extended attributes.
36
37 Paths are in POSIX format, and relative to engine/.
38
39 This list is used in core/ to generate EventFactory and EventNames.
40 The .in format is documented in build/scripts/in_file.py.
41 """
42
43 from optparse import OptionParser
44 import os
45 import posixpath
46 import sys
47
48 from utilities import get_file_contents, read_file_to_list, write_file, get_inte rface_extended_attributes_from_idl
49
50 EXPORTED_EXTENDED_ATTRIBUTES = (
51 'ImplementedAs',
52 )
53 module_path = os.path.dirname(os.path.realpath(__file__))
54 source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
55
56
57 def parse_options():
58 parser = OptionParser()
59 parser.add_option('--event-idl-files-list', help='file listing event IDL fil es')
60 parser.add_option('--event-interfaces-file', help='output file')
61 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')
62 parser.add_option('--suffix', help='specify a suffix to the namespace, i.e., "Modules". Default is None.')
63
64 options, args = parser.parse_args()
65 if options.event_idl_files_list is None:
66 parser.error('Must specify a file listing event IDL files using --event- idl-files-list.')
67 if options.event_interfaces_file is None:
68 parser.error('Must specify an output file using --event-interfaces-file. ')
69 if options.write_file_only_if_changed is None:
70 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.')
71 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
72 if args:
73 parser.error('No arguments allowed, but %d given.' % len(args))
74 return options
75
76
77 def write_event_interfaces_file(event_idl_files, destination_filename, only_if_c hanged, suffix):
78 def extended_attribute_string(name, value):
79 return name + '=' + value
80
81 def interface_line(full_path):
82 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou rce_dir))
83 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)
84
85 idl_file_contents = get_file_contents(full_path)
86 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil e_contents)
87 extended_attributes_list = [
88 extended_attribute_string(name, extended_attributes[name])
89 for name in EXPORTED_EXTENDED_ATTRIBUTES
90 if name in extended_attributes]
91
92 return '%s %s\n' % (relative_path_posix,
93 ', '.join(extended_attributes_list))
94
95 lines = ['namespace="Event"\n']
96 if suffix:
97 lines.append('suffix="' + suffix + '"\n')
98 lines.append('\n')
99 interface_lines = [interface_line(event_idl_file)
100 for event_idl_file in event_idl_files]
101 interface_lines.sort()
102 lines.extend(interface_lines)
103 write_file(''.join(lines), destination_filename, only_if_changed)
104
105
106 ################################################################################
107
108 def main():
109 options = parse_options()
110 event_idl_files = read_file_to_list(options.event_idl_files_list)
111 write_event_interfaces_file(event_idl_files,
112 options.event_interfaces_file,
113 options.write_file_only_if_changed,
114 options.suffix)
115
116
117 if __name__ == '__main__':
118 sys.exit(main())
OLDNEW
« no previous file with comments | « sky/engine/bindings2/scripts/dart_utilities.py ('k') | sky/engine/bindings2/scripts/idl_definitions.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698