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

Unified Diff: Source/bindings/scripts/generate_bindings.py

Issue 15959019: Rewrite generate-bindings.pl in Python (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/scripts/compare-python-to-perl ('k') | Source/bindings/scripts/idl-to-json.pl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/generate_bindings.py
diff --git a/Source/bindings/scripts/generate_bindings.py b/Source/bindings/scripts/generate_bindings.py
new file mode 100755
index 0000000000000000000000000000000000000000..4f5516a5bd11d2787d951d4a2925014d7a9876f3
--- /dev/null
+++ b/Source/bindings/scripts/generate_bindings.py
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+# Copyright (C) 2013 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import optparse
+import os.path
+import sys
+
+# import blink_idl_parser # FIXME: not checked in yet
+import blink_idl_parser_perl
+import code_generator_v8
+import interface_merger
+import semantic_analyzer
+
+
+def parse_options():
+ parser = optparse.OptionParser()
+ parser.add_option('--include', dest='idl_directories', action='append')
+ parser.add_option('--output-directory')
+ parser.add_option('--output-headers-directory')
+ parser.add_option('--defines')
+ parser.add_option('--filename')
+ parser.add_option('--preprocessor')
+ parser.add_option('--verbose', type='int') # FIXME: replace with flag: action='store_true', default=False
+ parser.add_option('--supplemental-dependency-file')
+ parser.add_option('--additional-idl-files', default='')
+ parser.add_option('--idl-attributes-file')
+ parser.add_option('--write-file-only-if-changed', type='int')
+ parser.add_option('--perl-parser', action='store_true', default=False)
+ parser.disable_interspersed_args() # ensure output comes last, so command line easy to parse via regexes (e.g., sanitize-win-build-log.sed)
+
+ options, args = parser.parse_args()
+ if options.output_directory is None:
+ parser.error('Must specify output directory using --output-directory.')
+ if options.output_headers_directory is None:
+ options.output_headers_directory = options.output_directory
+ if len(args) != 1:
+ parser.error('Must specify exactly 1 input file as argument, but %d given.' % len(args))
+ options.target_idl_file = args[0]
+ return options
+
+
+def parse_file(target_idl_file, defines, preprocessor, use_perl_parser, verbose):
+ """Wrapper function so can switch parser between Perl and Python"""
+ if use_perl_parser:
+ return blink_idl_parser_perl.parse_file(target_idl_file, defines, preprocessor)
+ else:
+ if verbose: # otherwise 'verbose' not used
+ print 'Not implemented yet'
+ # FIXME: not available yet
+ # parser = BlinkIDLParser(verbose=verbose)
+ # FIXME: actually "preprocess and parse"
+ # return parser.Parse(target_idl_file, defines, preprocessor)
+
+
+def main():
+ options = parse_options()
+ target_idl_file = os.path.realpath(options.target_idl_file)
+ target_basename = os.path.basename(options.target_idl_file)
+ target_interface_name, _ = os.path.splitext(target_basename)
+ if options.verbose:
+ print target_idl_file
+
+ # Compute dependencies
+ supplementary_idl_files = []
+ if options.supplemental_dependency_file:
+ try:
+ supplementary_idl_files = interface_merger.compute_supplementary_idl_files(target_basename, options.supplemental_dependency_file, options.additional_idl_files)
+ except interface_merger.IdlNotFoundError:
+ # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created.
+ code_generator_v8.generate_empty_header_and_cpp(target_interface_name, options.output_headers_directory, options.output_directory)
+ return
+
+ # Parse the target IDL file
+ target_document = parse_file(target_idl_file, options.defines, options.preprocessor, options.perl_parser, options.verbose)
+
+ # Post-process: check attributes and merge partial interfaces
+ if options.idl_attributes_file is not None:
+ attribute_checker = semantic_analyzer.IDLAttributeChecker(options.idl_attributes_file)
+ attribute_checker.check_idl_attributes(target_document, target_basename)
+ interface_merger.merge_partial_interfaces(target_document, target_interface_name, target_idl_file, supplementary_idl_files, options)
+
+ # Generate desired output for the target IDL file
+ dependent_idl_files = [target_basename] + supplementary_idl_files
+ code_generator = code_generator_v8.CodeGenerator(target_document, dependent_idl_files, options)
+ code_generator.write_interfaces(options.output_directory, options.output_headers_directory)
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « Source/bindings/scripts/compare-python-to-perl ('k') | Source/bindings/scripts/idl-to-json.pl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698