| 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 |
| 31 import errno |
| 32 import filecmp |
| 33 import fnmatch |
| 34 import optparse |
| 35 import os |
| 36 import os.path |
| 37 import shutil |
| 38 import subprocess |
| 39 import sys |
| 40 |
| 41 |
| 42 test_output_dir = os.path.join(os.curdir, 'test_output') |
| 43 perl_dir = os.path.join(test_output_dir, 'perl') |
| 44 python_dir = os.path.join(test_output_dir, 'python') |
| 45 |
| 46 |
| 47 def parse_options(): |
| 48 """Parse options. |
| 49 |
| 50 Arguments are list of IDL file basenames to test; |
| 51 if absent, test all IDL files. |
| 52 |
| 53 Options are: |
| 54 --clean: clean up (delete output directories) |
| 55 --generate-only: generate but do not compare (good for manual testing) |
| 56 --verbose |
| 57 |
| 58 Returns: |
| 59 options, files: arguments are list of files to test |
| 60 """ |
| 61 parser = optparse.OptionParser() |
| 62 parser.add_option('--clean', action='store_true', default=False) |
| 63 parser.add_option('--generate-only', action='store_true', default=False) |
| 64 parser.add_option('--verbose', action='store_true', default=False) |
| 65 parser.disable_interspersed_args() |
| 66 |
| 67 return parser.parse_args() |
| 68 |
| 69 |
| 70 def find_idl_files(basename_list): |
| 71 module_path, _ = os.path.split(__file__) |
| 72 source_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, 'Sou
rce') |
| 73 idl_list = [] |
| 74 for root, _, filenames in os.walk(source_dir): |
| 75 for filename in filenames: |
| 76 if os.path.basename(filename) in basename_list: |
| 77 idl_list.append(os.path.join(root, filename)) |
| 78 return idl_list |
| 79 |
| 80 |
| 81 def all_idl_files(): |
| 82 module_path, _ = os.path.split(__file__) |
| 83 source_dir = os.path.join(module_path, os.pardir, os.pardir, os.pardir, 'Sou
rce') |
| 84 idl_list = [] |
| 85 for root, _, filenames in os.walk(source_dir): |
| 86 for filename in fnmatch.filter(filenames, '*.idl'): |
| 87 idl_list.append(os.path.join(root, filename)) |
| 88 return idl_list |
| 89 |
| 90 |
| 91 def make_output_dirs(): |
| 92 for path in [perl_dir, python_dir]: |
| 93 try: |
| 94 os.makedirs(path) |
| 95 except OSError as exception: |
| 96 if exception.errno != errno.EEXIST: |
| 97 raise |
| 98 |
| 99 |
| 100 def cleanup(): |
| 101 shutil.rmtree(test_output_dir) |
| 102 |
| 103 |
| 104 def generate_perl(idl_file_list): |
| 105 for idl_file in idl_file_list: |
| 106 cmd = ['perl', '-w', |
| 107 '-I../../core/scripts', |
| 108 'generate-bindings.pl', |
| 109 '--outputDir', perl_dir, |
| 110 idl_file] |
| 111 subprocess.check_call(cmd) |
| 112 |
| 113 |
| 114 def generate_python(idl_file_list): |
| 115 for idl_file in idl_file_list: |
| 116 cmd = ['python', |
| 117 'generate_bindings.py', |
| 118 '--perl-parser', |
| 119 '--output-dir', python_dir, |
| 120 idl_file] |
| 121 subprocess.check_call(cmd) |
| 122 |
| 123 |
| 124 def compare_output(): |
| 125 dir_cmp = filecmp.dircmp(perl_dir, python_dir) |
| 126 print dir_cmp.report() |
| 127 |
| 128 |
| 129 def main(): |
| 130 options, idl_files_basenames = parse_options() |
| 131 if options.clean: |
| 132 cleanup() |
| 133 return |
| 134 if idl_files_basenames: |
| 135 idl_files = find_idl_files(idl_files_basenames) |
| 136 else: |
| 137 idl_files = all_idl_files() |
| 138 make_output_dirs() |
| 139 generate_perl(idl_files) |
| 140 generate_python(idl_files) |
| 141 if options.generate_only: |
| 142 return |
| 143 compare_output() |
| 144 |
| 145 |
| 146 if __name__ == '__main__': |
| 147 sys.exit(main()) |
| OLD | NEW |