| Index: Source/bindings/scripts/compare-python-to-perl
|
| diff --git a/Source/bindings/scripts/compare-python-to-perl b/Source/bindings/scripts/compare-python-to-perl
|
| new file mode 100755
|
| index 0000000000000000000000000000000000000000..e15b39eb5abb45181b5fc2ecbfe5d3f8a2aafdc0
|
| --- /dev/null
|
| +++ b/Source/bindings/scripts/compare-python-to-perl
|
| @@ -0,0 +1,147 @@
|
| +#!/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 errno
|
| +import filecmp
|
| +import fnmatch
|
| +import optparse
|
| +import os
|
| +import os.path
|
| +import shutil
|
| +import subprocess
|
| +import sys
|
| +
|
| +
|
| +test_output_dir = os.path.join(os.curdir, 'test_output')
|
| +perl_dir = os.path.join(test_output_dir, 'perl')
|
| +python_dir = os.path.join(test_output_dir, 'python')
|
| +
|
| +
|
| +def parse_options():
|
| + """Parse options.
|
| +
|
| + Arguments are list of IDL file basenames to test;
|
| + if absent, test all IDL files.
|
| +
|
| + Options are:
|
| + --clean: clean up (delete output directories)
|
| + --generate-only: generate but do not compare (good for manual testing)
|
| + --verbose
|
| +
|
| + Returns:
|
| + options, files: arguments are list of files to test
|
| + """
|
| + parser = optparse.OptionParser()
|
| + parser.add_option('--clean', action='store_true', default=False)
|
| + parser.add_option('--generate-only', action='store_true', default=False)
|
| + parser.add_option('--verbose', action='store_true', default=False)
|
| + parser.disable_interspersed_args()
|
| +
|
| + return parser.parse_args()
|
| +
|
| +
|
| +def find_idl_files(basename_list):
|
| + module_path, _ = os.path.split(__file__)
|
| + source_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, 'Source')
|
| + idl_list = []
|
| + for root, _, filenames in os.walk(source_dir):
|
| + for filename in filenames:
|
| + if os.path.basename(filename) in basename_list:
|
| + idl_list.append(os.path.join(root, filename))
|
| + return idl_list
|
| +
|
| +
|
| +def all_idl_files():
|
| + module_path, _ = os.path.split(__file__)
|
| + source_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, 'Source')
|
| + idl_list = []
|
| + for root, _, filenames in os.walk(source_dir):
|
| + for filename in fnmatch.filter(filenames, '*.idl'):
|
| + idl_list.append(os.path.join(root, filename))
|
| + return idl_list
|
| +
|
| +
|
| +def make_output_dirs():
|
| + for path in [perl_dir, python_dir]:
|
| + try:
|
| + os.makedirs(path)
|
| + except OSError as exception:
|
| + if exception.errno != errno.EEXIST:
|
| + raise
|
| +
|
| +
|
| +def cleanup():
|
| + shutil.rmtree(test_output_dir)
|
| +
|
| +
|
| +def generate_perl(idl_file_list):
|
| + for idl_file in idl_file_list:
|
| + cmd = ['perl', '-w',
|
| + '-I../../core/scripts',
|
| + 'generate-bindings.pl',
|
| + '--outputDir', perl_dir,
|
| + idl_file]
|
| + subprocess.check_call(cmd)
|
| +
|
| +
|
| +def generate_python(idl_file_list):
|
| + for idl_file in idl_file_list:
|
| + cmd = ['python',
|
| + 'generate_bindings.py',
|
| + '--perl-parser',
|
| + '--output-dir', python_dir,
|
| + idl_file]
|
| + subprocess.check_call(cmd)
|
| +
|
| +
|
| +def compare_output():
|
| + dir_cmp = filecmp.dircmp(perl_dir, python_dir)
|
| + print dir_cmp.report()
|
| +
|
| +
|
| +def main():
|
| + options, idl_files_basenames = parse_options()
|
| + if options.clean:
|
| + cleanup()
|
| + return
|
| + if idl_files_basenames:
|
| + idl_files = find_idl_files(idl_files_basenames)
|
| + else:
|
| + idl_files = all_idl_files()
|
| + make_output_dirs()
|
| + generate_perl(idl_files)
|
| + generate_python(idl_files)
|
| + if options.generate_only:
|
| + return
|
| + compare_output()
|
| +
|
| +
|
| +if __name__ == '__main__':
|
| + sys.exit(main())
|
|
|