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..558740ec42d6eb06415a330e73efdd4039157f66 |
--- /dev/null |
+++ b/Source/bindings/scripts/generate_init_partial_interfaces.py |
@@ -0,0 +1,111 @@ |
+#!/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" |
+ |
+%s |
+ |
+namespace blink { |
+ |
+void initModulesPartialInterfaces() |
+{ |
+%s |
+} |
+ |
+} // namespace blink |
+""" |
+ |
+ |
+def parse_options(): |
+ usage = 'Usage: %prog [options]' |
+ parser = OptionParser(usage=usage) |
+ parser.add_option('--cache-directory', |
+ 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() |
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.
|
+ |
+ 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 = [] |
bashi
2014/10/10 09:48:11
unused?
tasak
2014/10/10 11:43:40
Done.
|
+ initialize_calls = [] |
bashi
2014/10/10 09:48:11
remove? (the same as L86)
tasak
2014/10/10 11:43:40
Done.
|
+ 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) |
+ 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()) |