OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 | |
6 """Generate initialize .cpp file for modules' partial interfaces of core interfa ces. | |
7 """ | |
8 | |
9 import cPickle as pickle | |
10 from optparse import OptionParser | |
11 import os | |
12 import posixpath | |
13 import sys | |
14 from utilities import write_file | |
15 | |
16 from aggregate_generated_bindings import extract_meta_data, write_content, forma t_conditional, filter_partial_interface | |
17 from idl_reader import IdlReader | |
18 from utilities import read_idl_files_list_from_file | |
19 | |
20 | |
21 _COPYRIGHT = """// Copyright 2014 The Chromium Authors. All rights reserved. | |
22 // Use of this source code is governed by a BSD-style license that can be | |
23 // found in the LICENSE file. | |
24 | |
25 """ | |
26 | |
27 _INIT_PARTIAL_INTERFACE = """%s | |
28 #include "config.h" | |
29 #include "bindings/modules/v8/ModuleBindingsInitializer.h" | |
30 | |
31 %s | |
32 | |
33 namespace blink { | |
34 | |
35 void ModuleBindingsInitializer::initPartialInterface() | |
haraken
2014/10/09 04:24:00
It's a bit hacky to define ModuleBindingsInitializ
tasak
2014/10/10 07:52:22
Done.
| |
36 { | |
37 %s | |
38 } | |
39 | |
40 } // namespace blink | |
41 """ | |
42 | |
43 | |
44 def parse_options(): | |
45 usage = 'Usage: %prog [options]' | |
46 parser = OptionParser(usage=usage) | |
47 parser.add_option('--cache-directory', | |
haraken
2014/10/09 04:24:00
Is --cache-directory used?
tasak
2014/10/10 07:52:22
IdlReader uses.
| |
48 help='cache directory, defaults to output directory') | |
49 parser.add_option('--idl-files-list', help="a text file containing the IDL f ile paths, so the command line doesn't exceed OS length limits.") | |
50 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') | |
51 parser.add_option('--interfaces-info') | |
52 parser.add_option('--output') | |
53 # ensure output comes last, so command line easy to parse via regexes | |
54 parser.disable_interspersed_args() | |
55 | |
56 options, args = parser.parse_args() | |
57 if options.output is None: | |
58 parser.error('Must specify output file using --output.') | |
59 if options.idl_files_list is None: | |
60 parser.error('Must specify idl files list file using --idl-files-list.') | |
61 if options.interfaces_info is None: | |
62 parser.error('Must specify interfaces info using --interfaces-info.') | |
63 if options.write_file_only_if_changed is None: | |
64 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.') | |
65 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) | |
66 return options | |
67 | |
68 | |
69 def main(): | |
70 options = parse_options() | |
71 | |
72 idl_file_names = read_idl_files_list_from_file(options.idl_files_list) | |
73 | |
74 with open(options.interfaces_info) as interfaces_info_file: | |
75 interfaces_info = pickle.load(interfaces_info_file) | |
76 idl_file_names = filter_partial_interface(idl_file_names, interfaces_info, o ptions.cache_directory) | |
77 | |
78 header_files = [] | |
79 initialize_calls = [] | |
80 meta_data_list = extract_meta_data(idl_file_names) | |
81 for meta_data in meta_data_list: | |
82 meta_data['interface_name'] = 'V8%sPartial' % meta_data['name'] | |
83 | |
84 meta_data_list.sort(key=lambda meta_data: meta_data['interface_name']) | |
85 | |
86 includes = [] | |
87 initialize_calls = [] | |
88 for meta_data in meta_data_list: | |
89 conditional = meta_data['conditional'] | |
90 if conditional: | |
91 conditional_code = '#if %s' % format_conditional(conditional) | |
haraken
2014/10/09 04:24:00
Do you need to support conditional? Conditional is
tasak
2014/10/10 07:52:22
I think, it would be better to remove all conditio
| |
92 includes.append(conditional_code) | |
93 initialize_calls.append(conditional_code) | |
94 | |
95 includes.append('#include "bindings/modules/v8/%s.h"' % meta_data['inter face_name']) | |
96 initialize_calls.append(' %s::initialize();' % meta_data['interface_n ame']) | |
97 | |
98 if conditional: | |
99 includes.append('#endif') | |
100 initialize_calls.append('#endif') | |
101 | |
102 content = _INIT_PARTIAL_INTERFACE % ( | |
103 _COPYRIGHT, | |
104 '\n'.join(includes), | |
105 '\n'.join(initialize_calls)) | |
106 | |
107 write_file(content, options.output, | |
108 only_if_changed=options.write_file_only_if_changed) | |
109 | |
110 | |
111 if __name__ == '__main__': | |
112 sys.exit(main()) | |
OLD | NEW |