| OLD | NEW |
| (Empty) | |
| 1 #!/usr/bin/python |
| 2 # Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 # |
| 4 # Redistribution and use in source and binary forms, with or without |
| 5 # modification, are permitted provided that the following conditions are |
| 6 # met: |
| 7 # |
| 8 # * Redistributions of source code must retain the above copyright |
| 9 # notice, this list of conditions and the following disclaimer. |
| 10 # * Redistributions in binary form must reproduce the above |
| 11 # copyright notice, this list of conditions and the following disclaimer |
| 12 # in the documentation and/or other materials provided with the |
| 13 # distribution. |
| 14 # * Neither the name of Google Inc. nor the names of its |
| 15 # contributors may be used to endorse or promote products derived from |
| 16 # this software without specific prior written permission. |
| 17 # |
| 18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 |
| 30 import optparse |
| 31 import os.path |
| 32 import sys |
| 33 |
| 34 # import blink_idl_parser # FIXME: not checked in yet |
| 35 import blink_idl_parser_perl |
| 36 import code_generator_v8 |
| 37 import interface_merger |
| 38 import semantic_analyzer |
| 39 |
| 40 |
| 41 def parse_options(): |
| 42 parser = optparse.OptionParser() |
| 43 parser.add_option('--include', dest='idl_directories', action='append') |
| 44 parser.add_option('--output-directory') |
| 45 parser.add_option('--output-headers-directory') |
| 46 parser.add_option('--defines') |
| 47 parser.add_option('--filename') |
| 48 parser.add_option('--preprocessor') |
| 49 parser.add_option('--verbose', type='int') # FIXME: replace with flag: acti
on='store_true', default=False |
| 50 parser.add_option('--supplemental-dependency-file') |
| 51 parser.add_option('--additional-idl-files', default='') |
| 52 parser.add_option('--idl-attributes-file') |
| 53 parser.add_option('--write-file-only-if-changed', type='int') |
| 54 parser.add_option('--perl-parser', action='store_true', default=False) |
| 55 parser.disable_interspersed_args() # ensure output comes last, so command l
ine easy to parse via regexes (e.g., sanitize-win-build-log.sed) |
| 56 |
| 57 options, args = parser.parse_args() |
| 58 if options.output_directory is None: |
| 59 parser.error('Must specify output directory using --output-directory.') |
| 60 if options.output_headers_directory is None: |
| 61 options.output_headers_directory = options.output_directory |
| 62 if len(args) != 1: |
| 63 parser.error('Must specify exactly 1 input file as argument, but %d give
n.' % len(args)) |
| 64 options.target_idl_file = args[0] |
| 65 return options |
| 66 |
| 67 |
| 68 def parse_file(target_idl_file, defines, preprocessor, use_perl_parser, verbose)
: |
| 69 """Wrapper function so can switch parser between Perl and Python""" |
| 70 if use_perl_parser: |
| 71 return blink_idl_parser_perl.parse_file(target_idl_file, defines, prepro
cessor) |
| 72 else: |
| 73 if verbose: # otherwise 'verbose' not used |
| 74 print 'Not implemented yet' |
| 75 # FIXME: not available yet |
| 76 # parser = BlinkIDLParser(verbose=verbose) |
| 77 # FIXME: actually "preprocess and parse" |
| 78 # return parser.Parse(target_idl_file, defines, preprocessor) |
| 79 |
| 80 |
| 81 def main(): |
| 82 options = parse_options() |
| 83 target_idl_file = os.path.realpath(options.target_idl_file) |
| 84 target_basename = os.path.basename(options.target_idl_file) |
| 85 target_interface_name, _ = os.path.splitext(target_basename) |
| 86 if options.verbose: |
| 87 print target_idl_file |
| 88 |
| 89 # Compute dependencies |
| 90 supplementary_idl_files = [] |
| 91 if options.supplemental_dependency_file: |
| 92 try: |
| 93 supplementary_idl_files = interface_merger.compute_supplementary_idl
_files(target_basename, options.supplemental_dependency_file, options.additional
_idl_files) |
| 94 except interface_merger.IdlNotFoundError: |
| 95 # We generate empty .h and .cpp files just to tell build scripts tha
t .h and .cpp files are created. |
| 96 code_generator_v8.generate_empty_header_and_cpp(target_interface_nam
e, options.output_headers_directory, options.output_directory) |
| 97 return |
| 98 |
| 99 # Parse the target IDL file |
| 100 target_document = parse_file(target_idl_file, options.defines, options.prepr
ocessor, options.perl_parser, options.verbose) |
| 101 |
| 102 # Post-process: check attributes and merge partial interfaces |
| 103 if options.idl_attributes_file is not None: |
| 104 attribute_checker = semantic_analyzer.IDLAttributeChecker(options.idl_at
tributes_file) |
| 105 attribute_checker.check_idl_attributes(target_document, target_basename) |
| 106 interface_merger.merge_partial_interfaces(target_document, target_interface_
name, target_idl_file, supplementary_idl_files, options) |
| 107 |
| 108 # Generate desired output for the target IDL file |
| 109 dependent_idl_files = [target_basename] + supplementary_idl_files |
| 110 code_generator = code_generator_v8.CodeGenerator(target_document, dependent_
idl_files, options) |
| 111 code_generator.write_interfaces(options.output_directory, options.output_hea
ders_directory) |
| 112 |
| 113 |
| 114 if __name__ == '__main__': |
| 115 sys.exit(main()) |
| OLD | NEW |