Chromium Code Reviews| 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 | |
| 30 %s | |
| 31 | |
| 32 namespace blink { | |
| 33 | |
| 34 void initModulesPartialInterfaces() | |
| 35 { | |
| 36 %s | |
| 37 } | |
| 38 | |
| 39 } // namespace blink | |
| 40 """ | |
| 41 | |
| 42 | |
| 43 def parse_options(): | |
| 44 usage = 'Usage: %prog [options]' | |
| 45 parser = OptionParser(usage=usage) | |
| 46 parser.add_option('--cache-directory', | |
| 47 help='cache directory, defaults to output directory') | |
| 48 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.") | |
| 49 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') | |
| 50 parser.add_option('--interfaces-info') | |
| 51 parser.add_option('--output') | |
| 52 # ensure output comes last, so command line easy to parse via regexes | |
| 53 parser.disable_interspersed_args() | |
|
bashi
2014/10/10 09:48:11
It seems that we have a lot of copy-and-paste code
tasak
2014/10/10 11:43:40
Removed cache-directory, interfaces-info.
| |
| 54 | |
| 55 options, args = parser.parse_args() | |
| 56 if options.output is None: | |
| 57 parser.error('Must specify output file using --output.') | |
| 58 if options.idl_files_list is None: | |
| 59 parser.error('Must specify idl files list file using --idl-files-list.') | |
| 60 if options.interfaces_info is None: | |
| 61 parser.error('Must specify interfaces info using --interfaces-info.') | |
| 62 if options.write_file_only_if_changed is None: | |
| 63 parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.') | |
| 64 options.write_file_only_if_changed = bool(options.write_file_only_if_changed ) | |
| 65 return options | |
| 66 | |
| 67 | |
| 68 def main(): | |
| 69 options = parse_options() | |
| 70 | |
| 71 idl_file_names = read_idl_files_list_from_file(options.idl_files_list) | |
| 72 | |
| 73 with open(options.interfaces_info) as interfaces_info_file: | |
| 74 interfaces_info = pickle.load(interfaces_info_file) | |
| 75 idl_file_names = filter_partial_interface(idl_file_names, interfaces_info, o ptions.cache_directory) | |
| 76 | |
| 77 header_files = [] | |
|
bashi
2014/10/10 09:48:11
unused?
tasak
2014/10/10 11:43:40
Done.
| |
| 78 initialize_calls = [] | |
|
bashi
2014/10/10 09:48:11
remove? (the same as L86)
tasak
2014/10/10 11:43:40
Done.
| |
| 79 meta_data_list = extract_meta_data(idl_file_names) | |
| 80 for meta_data in meta_data_list: | |
| 81 meta_data['interface_name'] = 'V8%sPartial' % meta_data['name'] | |
| 82 | |
| 83 meta_data_list.sort(key=lambda meta_data: meta_data['interface_name']) | |
| 84 | |
| 85 includes = [] | |
| 86 initialize_calls = [] | |
| 87 for meta_data in meta_data_list: | |
| 88 conditional = meta_data['conditional'] | |
| 89 if conditional: | |
| 90 conditional_code = '#if %s' % format_conditional(conditional) | |
| 91 includes.append(conditional_code) | |
| 92 initialize_calls.append(conditional_code) | |
| 93 | |
| 94 includes.append('#include "bindings/modules/v8/%s.h"' % meta_data['inter face_name']) | |
| 95 initialize_calls.append(' %s::initialize();' % meta_data['interface_n ame']) | |
| 96 | |
| 97 if conditional: | |
| 98 includes.append('#endif') | |
| 99 initialize_calls.append('#endif') | |
| 100 | |
| 101 content = _INIT_PARTIAL_INTERFACE % ( | |
| 102 _COPYRIGHT, | |
| 103 '\n'.join(includes), | |
| 104 '\n'.join(initialize_calls)) | |
| 105 | |
| 106 write_file(content, options.output, | |
| 107 only_if_changed=options.write_file_only_if_changed) | |
| 108 | |
| 109 | |
| 110 if __name__ == '__main__': | |
| 111 sys.exit(main()) | |
| OLD | NEW |