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

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

Issue 309793002: IDL build: Split global objects computation from global constructors computation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Tweak Created 6 years, 6 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 sys
18
19 from utilities import get_file_contents, idl_filename_to_interface_name, get_int erface_extended_attributes_from_idl, read_file_to_list, write_pickle_file
20
21 GLOBAL_EXTENDED_ATTRIBUTES = frozenset([
22 'Global',
23 'PrimaryGlobal',
24 ])
25
26
27 def parse_options():
28 parser = optparse.OptionParser()
29 parser.add_option('--idl-files-list', help='file listing IDL files')
30 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')
31
32 options, args = parser.parse_args()
33
34 if options.idl_files_list is None:
35 parser.error('Must specify a file listing IDL files using --idl-files-li st.')
36 if options.write_file_only_if_changed is None:
37 parser.error('Must specify whether output files are only written if chan ged using --write-file-only-if-changed.')
38 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
39 if len(args) != 1:
40 parser.error('Must specify a single output pickle filename as argument.' )
41
42 return options, args[0]
43
44
45 def idl_file_to_global_names(idl_filename):
46 """Returns global names, if any, for an IDL file.
47
48 If the [Global] or [PrimaryGlobal] extended attribute is declared with an
49 identifier list argument, then those identifiers are the interface's global
50 names; otherwise, the interface has a single global name, which is the
51 interface's identifier (http://heycam.github.io/webidl/#Global).
52 """
53 interface_name = idl_filename_to_interface_name(idl_filename)
54 full_path = os.path.realpath(idl_filename)
55 idl_file_contents = get_file_contents(full_path)
56 extended_attributes = get_interface_extended_attributes_from_idl(idl_file_co ntents)
57
58 global_keys = GLOBAL_EXTENDED_ATTRIBUTES.intersection(
59 extended_attributes.iterkeys())
60 if not global_keys:
61 return
62 if len(global_keys) > 1:
63 raise ValueError('The [Global] and [PrimaryGlobal] extended attributes '
haraken 2014/06/02 07:41:30 Is it worth supporting extended attribute values f
Nils Barth (inactive) 2014/06/02 07:55:13 It's defined as such in the spec: """The [Global]
64 'MUST NOT be declared on the same interface.')
65 global_key = next(iter(global_keys))
haraken 2014/06/02 07:41:30 Nit: Can we write: global_key = global_keys[0] ?
Nils Barth (inactive) 2014/06/02 07:55:13 No, b/c it's a (frozen) set. We could do list(glob
66
67 global_value = extended_attributes[global_key]
68 if global_value:
69 # FIXME: In spec names are comma-separated, which makes parsing very
70 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959).
71 return global_value.split('&')
72 return [interface_name]
73
74
75 def interface_name_global_names(idl_files):
76 """Yields pairs (interface_name, global_names) found in IDL files."""
77 for idl_filename in idl_files:
78 interface_name = idl_filename_to_interface_name(idl_filename)
79 global_names = idl_file_to_global_names(idl_filename)
80 if global_names:
81 yield interface_name, global_names
82
83
84 ################################################################################
85
86 def main():
87 options, global_objects_filename = parse_options()
88
89 # Input IDL files are passed in a file, due to OS command line length
90 # limits. This is generated at GYP time, which is ok b/c files are static.
91 idl_files = read_file_to_list(options.idl_files_list)
92
93 write_pickle_file(global_objects_filename,
94 dict(interface_name_global_names(idl_files)),
95 options.write_file_only_if_changed)
96
97
98 if __name__ == '__main__':
99 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/scripts/aggregate_generated_bindings.py ('k') | Source/bindings/scripts/compute_interfaces_info_individual.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698