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

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

Issue 315003004: IDL build: Split global object computation into core and modules (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move modules_global_objects to core/generated to eliminate circular dependency of GYP files 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
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2014 The Chromium Authors. All rights reserved. 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 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 """Compute global objects. 7 """Compute global objects.
8 8
9 Global objects are defined by interfaces with [Global] or [PrimaryGlobal] on 9 Global objects are defined by interfaces with [Global] or [PrimaryGlobal] on
10 their definition: http://heycam.github.io/webidl/#Global 10 their definition: http://heycam.github.io/webidl/#Global
11 11
12 Design document: http://www.chromium.org/developers/design-documents/idl-build 12 Design document: http://www.chromium.org/developers/design-documents/idl-build
13 """ 13 """
14 14
15 import optparse 15 import optparse
16 import os 16 import os
17 import cPickle as pickle
17 import sys 18 import sys
18 19
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 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
20 21
21 GLOBAL_EXTENDED_ATTRIBUTES = frozenset([ 22 GLOBAL_EXTENDED_ATTRIBUTES = frozenset([
22 'Global', 23 'Global',
23 'PrimaryGlobal', 24 'PrimaryGlobal',
24 ]) 25 ])
25 26
26 27
27 def parse_options(): 28 def parse_options():
28 parser = optparse.OptionParser() 29 usage = 'Usage: %prog [options] [GlobalObjectsComponent.pickle]... [GlobalOb jects.pickle]'
30 parser = optparse.OptionParser(usage=usage)
29 parser.add_option('--idl-files-list', help='file listing IDL files') 31 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') 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')
31 33
32 options, args = parser.parse_args() 34 options, args = parser.parse_args()
33 35
34 if options.idl_files_list is None: 36 if options.idl_files_list is None:
35 parser.error('Must specify a file listing IDL files using --idl-files-li st.') 37 parser.error('Must specify a file listing IDL files using --idl-files-li st.')
36 if options.write_file_only_if_changed is None: 38 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.') 39 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 ) 40 options.write_file_only_if_changed = bool(options.write_file_only_if_changed )
39 if len(args) != 1: 41 if not args:
40 parser.error('Must specify a single output pickle filename as argument.' ) 42 parser.error('Must specify an output pickle filename as argument, '
43 'optionally preceeded by input pickle filenames.')
41 44
42 return options, args[0] 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())
43 50
44 51
45 def idl_file_to_global_names(idl_filename): 52 def idl_file_to_global_names(idl_filename):
46 """Returns global names, if any, for an IDL file. 53 """Returns global names, if any, for an IDL file.
47 54
48 If the [Global] or [PrimaryGlobal] extended attribute is declared with an 55 If the [Global] or [PrimaryGlobal] extended attribute is declared with an
49 identifier list argument, then those identifiers are the interface's global 56 identifier list argument, then those identifiers are the interface's global
50 names; otherwise, the interface has a single global name, which is the 57 names; otherwise, the interface has a single global name, which is the
51 interface's identifier (http://heycam.github.io/webidl/#Global). 58 interface's identifier (http://heycam.github.io/webidl/#Global).
52 """ 59 """
(...skipping 12 matching lines...) Expand all
65 global_key = next(iter(global_keys)) 72 global_key = next(iter(global_keys))
66 73
67 global_value = extended_attributes[global_key] 74 global_value = extended_attributes[global_key]
68 if global_value: 75 if global_value:
69 # FIXME: In spec names are comma-separated, which makes parsing very 76 # FIXME: In spec names are comma-separated, which makes parsing very
70 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959). 77 # difficult (https://www.w3.org/Bugs/Public/show_bug.cgi?id=24959).
71 return global_value.split('&') 78 return global_value.split('&')
72 return [interface_name] 79 return [interface_name]
73 80
74 81
75 def interface_name_global_names(idl_files): 82 def idl_files_to_interface_name_global_names(idl_files):
76 """Yields pairs (interface_name, global_names) found in IDL files.""" 83 """Yields pairs (interface_name, global_names) found in IDL files."""
77 for idl_filename in idl_files: 84 for idl_filename in idl_files:
78 interface_name = idl_filename_to_interface_name(idl_filename) 85 interface_name = idl_filename_to_interface_name(idl_filename)
79 global_names = idl_file_to_global_names(idl_filename) 86 global_names = idl_file_to_global_names(idl_filename)
80 if global_names: 87 if global_names:
81 yield interface_name, global_names 88 yield interface_name, global_names
82 89
83 90
84 ################################################################################ 91 ################################################################################
85 92
86 def main(): 93 def main():
87 options, global_objects_filename = parse_options() 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))
88 100
89 # Input IDL files are passed in a file, due to OS command line length 101 # 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. 102 # 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) 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))
92 106
93 write_pickle_file(global_objects_filename, 107 write_pickle_file(output_global_objects_filename,
94 dict(interface_name_global_names(idl_files)), 108 interface_name_global_names,
95 options.write_file_only_if_changed) 109 options.write_file_only_if_changed)
96 110
97 111
98 if __name__ == '__main__': 112 if __name__ == '__main__':
99 sys.exit(main()) 113 sys.exit(main())
OLDNEW
« no previous file with comments | « Source/bindings/modules/modules.gypi ('k') | Source/bindings/scripts/compute_interfaces_info_overall.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698