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

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

Issue 540533002: Roll IDL to Dartium37 (r181268) (Closed) Base URL: https://dart.googlecode.com/svn/third_party/WebCore
Patch Set: Created 6 years, 3 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 Paths are in POSIX format, and relative to Source/.
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 'Conditional',
52 'ImplementedAs',
53 'RuntimeEnabled',
54 )
55 module_path = os.path.dirname(os.path.realpath(__file__))
56 source_dir = os.path.normpath(os.path.join(module_path, os.pardir, os.pardir))
57
58
59 def parse_options():
60 parser = OptionParser()
61 parser.add_option('--event-idl-files-list', help='file listing event IDL fil es')
62 parser.add_option('--event-interfaces-file', help='output file')
63 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')
64 parser.add_option('--suffix', help='specify a suffix to the namespace, i.e., "Modules". Default is None.')
65
66 options, args = parser.parse_args()
67 if options.event_idl_files_list is None:
68 parser.error('Must specify a file listing event IDL files using --event- idl-files-list.')
69 if options.event_interfaces_file is None:
70 parser.error('Must specify an output file using --event-interfaces-file. ')
71 if options.write_file_only_if_changed is None:
72 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.')
73 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
74 if args:
75 parser.error('No arguments allowed, but %d given.' % len(args))
76 return options
77
78
79 def write_event_interfaces_file(event_idl_files, destination_filename, only_if_c hanged, suffix):
80 def extended_attribute_string(name, value):
81 if name == 'RuntimeEnabled':
82 value += 'Enabled'
83 return name + '=' + value
84
85 def interface_line(full_path):
86 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou rce_dir))
87 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)
88
89 idl_file_contents = get_file_contents(full_path)
90 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil e_contents)
91 extended_attributes_list = [
92 extended_attribute_string(name, extended_attributes[name])
93 for name in EXPORTED_EXTENDED_ATTRIBUTES
94 if name in extended_attributes]
95
96 return '%s %s\n' % (relative_path_posix,
97 ', '.join(extended_attributes_list))
98
99 lines = ['namespace="Event"\n']
100 if suffix:
101 lines.append('suffix="' + suffix + '"\n')
102 lines.append('\n')
103 interface_lines = [interface_line(event_idl_file)
104 for event_idl_file in event_idl_files]
105 interface_lines.sort()
106 lines.extend(interface_lines)
107 write_file(''.join(lines), destination_filename, only_if_changed)
108
109
110 ################################################################################
111
112 def main():
113 options = parse_options()
114 event_idl_files = read_file_to_list(options.event_idl_files_list)
115 write_event_interfaces_file(event_idl_files,
116 options.event_interfaces_file,
117 options.write_file_only_if_changed,
118 options.suffix)
119
120
121 if __name__ == '__main__':
122 sys.exit(main())
OLDNEW
« no previous file with comments | « bindings/scripts/compute_interfaces_info_overall.py ('k') | bindings/scripts/generate_global_constructors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698