Chromium Code Reviews| Index: Source/bindings/scripts/generate_init_partial_interfaces.py |
| diff --git a/Source/bindings/scripts/generate_init_partial_interfaces.py b/Source/bindings/scripts/generate_init_partial_interfaces.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..4379e5f4775a8351fc2458906d217915b8b38941 |
| --- /dev/null |
| +++ b/Source/bindings/scripts/generate_init_partial_interfaces.py |
| @@ -0,0 +1,112 @@ |
| +#!/usr/bin/python |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Generate initialize .cpp file for modules' partial interfaces of core interfaces. |
| +""" |
| + |
| +import cPickle as pickle |
| +from optparse import OptionParser |
| +import os |
| +import posixpath |
| +import sys |
| +from utilities import write_file |
| + |
| +from aggregate_generated_bindings import extract_meta_data, write_content, format_conditional, filter_partial_interface |
| +from idl_reader import IdlReader |
| +from utilities import read_idl_files_list_from_file |
| + |
| + |
| +_COPYRIGHT = """// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +""" |
| + |
| +_INIT_PARTIAL_INTERFACE = """%s |
| +#include "config.h" |
| +#include "bindings/modules/v8/ModuleBindingsInitializer.h" |
| + |
| +%s |
| + |
| +namespace blink { |
| + |
| +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.
|
| +{ |
| +%s |
| +} |
| + |
| +} // namespace blink |
| +""" |
| + |
| + |
| +def parse_options(): |
| + usage = 'Usage: %prog [options]' |
| + parser = OptionParser(usage=usage) |
| + 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.
|
| + help='cache directory, defaults to output directory') |
| + parser.add_option('--idl-files-list', help="a text file containing the IDL file paths, so the command line doesn't exceed OS length limits.") |
| + 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') |
| + parser.add_option('--interfaces-info') |
| + parser.add_option('--output') |
| + # ensure output comes last, so command line easy to parse via regexes |
| + parser.disable_interspersed_args() |
| + |
| + options, args = parser.parse_args() |
| + if options.output is None: |
| + parser.error('Must specify output file using --output.') |
| + if options.idl_files_list is None: |
| + parser.error('Must specify idl files list file using --idl-files-list.') |
| + if options.interfaces_info is None: |
| + parser.error('Must specify interfaces info using --interfaces-info.') |
| + if options.write_file_only_if_changed is None: |
| + parser.error('Must specify whether file is only written if changed using --write-file-only-if-changed.') |
| + options.write_file_only_if_changed = bool(options.write_file_only_if_changed) |
| + return options |
| + |
| + |
| +def main(): |
| + options = parse_options() |
| + |
| + idl_file_names = read_idl_files_list_from_file(options.idl_files_list) |
| + |
| + with open(options.interfaces_info) as interfaces_info_file: |
| + interfaces_info = pickle.load(interfaces_info_file) |
| + idl_file_names = filter_partial_interface(idl_file_names, interfaces_info, options.cache_directory) |
| + |
| + header_files = [] |
| + initialize_calls = [] |
| + meta_data_list = extract_meta_data(idl_file_names) |
| + for meta_data in meta_data_list: |
| + meta_data['interface_name'] = 'V8%sPartial' % meta_data['name'] |
| + |
| + meta_data_list.sort(key=lambda meta_data: meta_data['interface_name']) |
| + |
| + includes = [] |
| + initialize_calls = [] |
| + for meta_data in meta_data_list: |
| + conditional = meta_data['conditional'] |
| + if conditional: |
| + 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
|
| + includes.append(conditional_code) |
| + initialize_calls.append(conditional_code) |
| + |
| + includes.append('#include "bindings/modules/v8/%s.h"' % meta_data['interface_name']) |
| + initialize_calls.append(' %s::initialize();' % meta_data['interface_name']) |
| + |
| + if conditional: |
| + includes.append('#endif') |
| + initialize_calls.append('#endif') |
| + |
| + content = _INIT_PARTIAL_INTERFACE % ( |
| + _COPYRIGHT, |
| + '\n'.join(includes), |
| + '\n'.join(initialize_calls)) |
| + |
| + write_file(content, options.output, |
| + only_if_changed=options.write_file_only_if_changed) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |