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

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

Issue 17572008: WIP IDL compiler rewrite (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: non-callback headers working Created 7 years, 6 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/generate-bindings.pl ('k') | Source/bindings/scripts/header.template » ('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 100644
index 0000000000000000000000000000000000000000..269a4110ad579346f6acd1ebbb5eae5640e5f695
--- /dev/null
+++ b/Source/bindings/scripts/generate_bindings.py
@@ -0,0 +1,120 @@
+#!/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 pickle
+import sys
+
+# import blink_idl_parser # FIXME: not checked in yet
+# import json_import_export # FIXME: not using JSON
+import code_generator_v8
+# import interface_merger # FIXME: not checked in yet
+# import semantic_analyzer # FIXME: not checked in yet
+
+
+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('--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('--no_h', default=None)
+ parser.add_option('--no_cpp', default=None)
+ 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 read_pickled_idl(interface_name):
+ # Assume pickled file in current directory;
+ # feel free to customize as desired
+ pickle_filename = "/mnt/hdd/PKL-GOOD/" + interface_name + '.pkl'
+ with open(pickle_filename, 'rb') as pickle_file:
+ return pickle.load(pickle_file)
+ raise Exception("[read_pickled_idl] %s NOT FOUND" % interface_name)
+ return None
+
+
+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 = []
+ # FIXME: turn on
+ #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 = json_import_export.parse_file(target_idl_file) # Actual read JSON
+ target_document = read_pickled_idl(target_interface_name)
+ # FIXME: switch to Python parser
+ # parser = BlinkIDLParser(verbose=options.verbose)
+ # return parser.Parse(target_idl_file, defines)
+
+ # FIXME: turn on
+ # 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 = [options.target_idl_file] + supplementary_idl_files
+ code_generator = code_generator_v8.code_generator_v8(target_document, ["../modules", "../core", "../../../../out/Release/gen/webkit"], dependent_idl_files, options)
+ code_generator.write_interfaces()
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « Source/bindings/scripts/generate-bindings.pl ('k') | Source/bindings/scripts/header.template » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698