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

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

Issue 185303008: Split generate_event_interfaces.py from compute_interfaces_info.py (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 """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 This list is used in core/ to generate EventFactory and EventNames.
38 The .in format is documented in build/scripts/in_file.py.
39 """
40
41 import optparse
42 import cPickle as pickle
43 import os
44 import posixpath
45 import sys
46
47 from utilities import get_file_contents, write_file, get_interface_extended_attr ibutes_from_idl
48
49 interfaces_info = {}
50 extended_attributes_by_interface = {} # interface name -> extended attributes
51
52
53 def parse_options():
54 parser = optparse.OptionParser()
55 parser.add_option('--event-names-file', help='output file')
56 parser.add_option('--interfaces-info-file', help='output pickle file')
57 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')
58
59 options, args = parser.parse_args()
60 if options.event_names_file is None:
61 parser.error('Must specify an output file using --event-names-file.')
62 if options.interfaces_info_file is None:
63 parser.error('Must specify an input file using --interfaces-info-file.')
64 if options.write_file_only_if_changed is None:
65 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.')
66 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
67 if args:
68 parser.error('No arguments allowed, but %d given.' % len(args))
69 return options
70
71
72 def store_event_extended_attributes():
73 event_interfaces = set(
74 interface_name
75 for interface_name, interface_info in interfaces_info.iteritems()
76 if (interface_name == 'Event' or
77 ('ancestors' in interface_info and
78 interface_info['ancestors'][-1] == 'Event')))
79 for interface_name in event_interfaces:
80 interface_info = interfaces_info[interface_name]
81 idl_file_contents = get_file_contents(interface_info['full_path'])
82 extended_attributes_by_interface[interface_name] = get_interface_extende d_attributes_from_idl(idl_file_contents)
83
84
85 def write_event_names_file(destination_filename, only_if_changed):
86 event_names = set(
87 interface_name
88 for interface_name, interface_info in interfaces_info.iteritems()
89 if (interface_name == 'Event' or
90 ('ancestors' in interface_info and
91 interface_info['ancestors'][-1] == 'Event')))
92
93 def extended_attribute_string(name):
94 value = extended_attributes[name]
95 if name == 'RuntimeEnabled':
96 value += 'Enabled'
97 return name + '=' + value
98
99 source_dir, _ = os.path.split(os.getcwd())
100 lines = []
101 lines.append('namespace="Event"\n')
102 lines.append('\n')
103 for filename, extended_attributes in sorted(
104 (interface_info['full_path'],
105 extended_attributes_by_interface[interface_name])
106 for interface_name, interface_info in interfaces_info.iteritems()
107 if interface_name in event_names):
108 refined_filename, _ = os.path.splitext(os.path.relpath(filename, source_ dir))
109 refined_filename = refined_filename.replace(os.sep, posixpath.sep)
110 extended_attributes_list = [
111 extended_attribute_string(name)
112 for name in 'Conditional', 'ImplementedAs', 'RuntimeEnabled'
113 if name in extended_attributes]
114 lines.append('%s %s\n' % (refined_filename, ', '.join(extended_attribute s_list)))
115 write_file(lines, destination_filename, only_if_changed)
116
117
118 ################################################################################
119
120 def main():
121 options = parse_options()
122 with open(options.interfaces_info_file) as interfaces_info_file:
123 interfaces_info.update(pickle.load(interfaces_info_file))
124 store_event_extended_attributes()
125 write_event_names_file(options.event_names_file,
126 options.write_file_only_if_changed)
127
128
129 if __name__ == '__main__':
130 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/scripts/compute_interfaces_info.py ('k') | Tools/Scripts/webkitpy/bindings/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698