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

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

Issue 2638233002: Convert make_names and make_event_factory to use json5 config format. (Closed)
Patch Set: fix PLATFORM_EXPORT Created 3 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
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright (C) 2013 Google Inc. All rights reserved. 3 # Copyright (C) 2013 Google Inc. All rights reserved.
4 # 4 #
5 # Redistribution and use in source and binary forms, with or without 5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are 6 # modification, are permitted provided that the following conditions are
7 # met: 7 # met:
8 # 8 #
9 # * Redistributions of source code must retain the above copyright 9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer. 10 # notice, this list of conditions and the following disclaimer.
(...skipping 10 matching lines...) Expand all
21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 30
31 """Generate event interfaces .in file (EventInterfaces.in). 31 """Generate event interfaces .json5 file (EventInterfaces.json5).
32 32
33 The event interfaces .in file contains a list of all Event interfaces, i.e., 33 The event interfaces .json5 file contains a list of all Event interfaces, i.e.,
34 all interfaces that inherit from Event, including Event itself, 34 all interfaces that inherit from Event, including Event itself,
35 together with certain extended attributes. 35 together with certain extended attributes.
36 36
37 Paths are in POSIX format, and relative to Source/. 37 Paths are in POSIX format, and relative to Source/.
38 38
39 This list is used in core/ to generate EventFactory and EventNames. 39 This list is used in core/ to generate EventFactory and EventNames.
40 The .in format is documented in build/scripts/in_file.py. 40 The .json5 format is documented in build/scripts/json5_generator.py.
41 """ 41 """
42 42
43 from optparse import OptionParser 43 from optparse import OptionParser
44 import os 44 import os
45 import posixpath 45 import posixpath
46 import sys 46 import sys
47 47
48 from utilities import get_file_contents, read_file_to_list, write_file, get_inte rface_extended_attributes_from_idl 48 from utilities import get_file_contents, read_file_to_list, write_file, get_inte rface_extended_attributes_from_idl
49 49
50 EXPORTED_EXTENDED_ATTRIBUTES = ( 50 EXPORTED_EXTENDED_ATTRIBUTES = (
(...skipping 14 matching lines...) Expand all
65 if options.event_idl_files_list is None: 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.') 66 parser.error('Must specify a file listing event IDL files using --event- idl-files-list.')
67 if options.event_interfaces_file is None: 67 if options.event_interfaces_file is None:
68 parser.error('Must specify an output file using --event-interfaces-file. ') 68 parser.error('Must specify an output file using --event-interfaces-file. ')
69 if args: 69 if args:
70 parser.error('No arguments allowed, but %d given.' % len(args)) 70 parser.error('No arguments allowed, but %d given.' % len(args))
71 return options 71 return options
72 72
73 73
74 def write_event_interfaces_file(event_idl_files, destination_filename, suffix): 74 def write_event_interfaces_file(event_idl_files, destination_filename, suffix):
75 def extended_attribute_string(name, value):
76 if name == 'RuntimeEnabled':
77 value += 'Enabled'
78 return name + '=' + value
79
80 def interface_line(full_path): 75 def interface_line(full_path):
81 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou rce_dir)) 76 relative_path_local, _ = os.path.splitext(os.path.relpath(full_path, sou rce_dir))
82 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep) 77 relative_path_posix = relative_path_local.replace(os.sep, posixpath.sep)
83 78
84 idl_file_contents = get_file_contents(full_path) 79 idl_file_contents = get_file_contents(full_path)
85 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil e_contents) 80 extended_attributes = get_interface_extended_attributes_from_idl(idl_fil e_contents)
86 extended_attributes_list = [ 81 extended_attributes_list = [
87 extended_attribute_string(name, extended_attributes[name]) 82 (name, extended_attributes[name])
88 for name in EXPORTED_EXTENDED_ATTRIBUTES 83 for name in EXPORTED_EXTENDED_ATTRIBUTES
89 if name in extended_attributes] 84 if name in extended_attributes]
90 85
91 return '%s %s\n' % (relative_path_posix, 86 return (relative_path_posix, extended_attributes_list)
92 ', '.join(extended_attributes_list))
93 87
94 lines = ['namespace="Event"\n'] 88 lines = [
89 '{',
90 'metadata: {',
91 ' namespace: "Event",'
92 ]
95 if suffix: 93 if suffix:
96 lines.append('suffix="' + suffix + '"\n') 94 lines.append(' suffix: "' + suffix + '",')
97 lines.append('export=%s_EXPORT\n' % suffix.upper()) 95 lines.append(' export: "%s_EXPORT",' % suffix.upper())
98 else: 96 else:
99 lines.append('export=CORE_EXPORT\n') 97 lines.append(' export: "CORE_EXPORT",')
100 lines.append('\n') 98 lines.extend([
99 '},',
100 'data: ['
101 ])
101 interface_lines = [interface_line(event_idl_file) 102 interface_lines = [interface_line(event_idl_file)
102 for event_idl_file in event_idl_files] 103 for event_idl_file in event_idl_files]
103 interface_lines.sort() 104 interface_lines.sort()
104 lines.extend(interface_lines) 105 for name, attributes in interface_lines:
105 write_file(''.join(lines), destination_filename) 106 lines.extend([
107 ' {',
108 ' name: "%s",' % name
109 ])
110 for param, value in attributes:
111 if param == 'RuntimeEnabled':
112 value += 'Enabled'
113 lines.append(' %s: "%s",' % (param, value))
114 lines.append(' },')
115 lines.extend([
116 ']',
117 '}'
118 ])
119 write_file('\n'.join(lines), destination_filename)
106 120
107 121
108 ################################################################################ 122 ################################################################################
109 123
110 def main(): 124 def main():
111 options = parse_options() 125 options = parse_options()
112 event_idl_files = read_file_to_list(options.event_idl_files_list) 126 event_idl_files = read_file_to_list(options.event_idl_files_list)
113 write_event_interfaces_file(event_idl_files, 127 write_event_interfaces_file(event_idl_files,
114 options.event_interfaces_file, 128 options.event_interfaces_file,
115 options.suffix) 129 options.suffix)
116 130
117 131
118 if __name__ == '__main__': 132 if __name__ == '__main__':
119 sys.exit(main()) 133 sys.exit(main())
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/bindings/modules/BUILD.gn ('k') | third_party/WebKit/Source/build/scripts/json5_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698