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

Side by Side Diff: bindings/scripts/compute_global_objects.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 2014 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Compute global objects.
8
9 Global objects are defined by interfaces with [Global] or [PrimaryGlobal] on
10 their definition: http://heycam.github.io/webidl/#Global
11
12 Design document: http://www.chromium.org/developers/design-documents/idl-build
13 """
14
15 import optparse
16 import os
17 import cPickle as pickle
18 import sys
19
20 from utilities import get_file_contents, idl_filename_to_interface_name, get_int erface_extended_attributes_from_idl, read_file_to_list, read_pickle_files, write _pickle_file
21
22 GLOBAL_EXTENDED_ATTRIBUTES = frozenset([
23 'Global',
24 'PrimaryGlobal',
25 ])
26
27
28 def parse_options():
29 usage = 'Usage: %prog [options] [GlobalObjectsComponent.pickle]... [GlobalOb jects.pickle]'
30 parser = optparse.OptionParser(usage=usage)
31 parser.add_option('--idl-files-list', help='file listing IDL files')
32 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')
33
34 options, args = parser.parse_args()
35
36 if options.idl_files_list is None:
37 parser.error('Must specify a file listing IDL files using --idl-files-li st.')
38 if options.write_file_only_if_changed is None:
39 parser.error('Must specify whether output files are only written if chan ged using --write-file-only-if-changed.')
40 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
41 if not args:
42 parser.error('Must specify an output pickle filename as argument, '
43 'optionally preceeded by input pickle filenames.')
44
45 return options, args
46
47
48 def dict_union(dicts):
49 return dict((k, v) for d in dicts for k, v in d.iteritems())
50
51
52 def idl_file_to_global_names(idl_filename):
53 """Returns global names, if any, for an IDL file.
54
55 If the [Global] or [PrimaryGlobal] extended attribute is declared with an
56 identifier list argument, then those identifiers are the interface's global
57 names; otherwise, the interface has a single global name, which is the
58 interface's identifier (http://heycam.github.io/webidl/#Global).
59 """
60 interface_name = idl_filename_to_interface_name(idl_filename)
61 full_path = os.path.realpath(idl_filename)
62 idl_file_contents = get_file_contents(full_path)
63 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents)
64
65 global_keys = GLOBAL_EXTENDED_ATTRIBUTES.intersection(
66 extended_attributes.iterkeys())
67 if not global_keys:
68 return
69 if len(global_keys) > 1:
70 raise ValueError('The [Global] and [PrimaryGlobal] extended attributes '
71 'MUST NOT be declared on the same interface.')
72 global_key = next(iter(global_keys))
73
74 global_value = extended_attributes[global_key]
75 if global_value:
76 # FIXME: In spec names are comma-separated, which makes parsing very
77 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959).
78 return global_value.split('&')
79 return [interface_name]
80
81
82 def idl_files_to_interface_name_global_names(idl_files):
83 """Yields pairs (interface_name, global_names) found in IDL files."""
84 for idl_filename in idl_files:
85 interface_name = idl_filename_to_interface_name(idl_filename)
86 global_names = idl_file_to_global_names(idl_filename)
87 if global_names:
88 yield interface_name, global_names
89
90
91 ################################################################################
92
93 def main():
94 options, args = parse_options()
95 # args = Input1, Input2, ..., Output
96 output_global_objects_filename = args.pop()
97 interface_name_global_names = dict_union(
98 existing_interface_name_global_names
99 for existing_interface_name_global_names in read_pickle_files(args))
100
101 # Input IDL files are passed in a file, due to OS command line length
102 # limits. This is generated at GYP time, which is ok b/c files are static.
103 idl_files = read_file_to_list(options.idl_files_list)
104 interface_name_global_names.update(
105 idl_files_to_interface_name_global_names(idl_files))
106
107 write_pickle_file(output_global_objects_filename,
108 interface_name_global_names,
109 options.write_file_only_if_changed)
110
111
112 if __name__ == '__main__':
113 sys.exit(main())
OLDNEW
« no previous file with comments | « bindings/scripts/code_generator_v8.py ('k') | bindings/scripts/compute_interfaces_info_individual.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698