| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Wrapper script for running ncval. | 6 """Wrapper script for running the Native Client validator (ncval). |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import optparse | 9 import argparse |
| 10 import os | 10 import os |
| 11 import subprocess | 11 import subprocess |
| 12 import sys | 12 import sys |
| 13 | 13 |
| 14 import getos | 14 import getos |
| 15 | 15 |
| 16 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 16 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 17 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) | 17 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) |
| 18 | 18 |
| 19 if sys.version_info < (2, 7, 0): | 19 if sys.version_info < (2, 7, 0): |
| 20 sys.stderr.write("python 2.7 or later is required run this script\n") | 20 sys.stderr.write("python 2.7 or later is required run this script\n") |
| 21 sys.exit(1) | 21 sys.exit(1) |
| 22 | 22 |
| 23 class Error(Exception): | 23 class Error(Exception): |
| 24 pass | 24 pass |
| 25 | 25 |
| 26 def Log(msg): | 26 def Log(msg): |
| 27 if Log.verbose: | 27 if Log.verbose: |
| 28 sys.stderr.write(str(msg) + '\n') | 28 sys.stderr.write(str(msg) + '\n') |
| 29 Log.verbose = False | 29 Log.verbose = False |
| 30 | 30 |
| 31 def main(argv): | 31 def main(args): |
| 32 usage = 'Usage: %prog [options] <.nexe | .so>' | 32 parser = argparse.ArgumentParser(description=__doc__) |
| 33 epilog = 'Example: ncval.py my_nexe.nexe' | 33 parser.add_argument('-v', '--verbose', action='store_true', |
| 34 parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog) | 34 help='Verbose output') |
| 35 parser.add_option('-v', '--verbose', action='store_true', | 35 parser.add_argument('nexe', metavar="EXE", help='Executable to validate') |
| 36 help='Verbose output') | |
| 37 | 36 |
| 38 # To enable bash completion for this command first install optcomplete | 37 # To enable bash completion for this command first install optcomplete |
| 39 # and then add this line to your .bashrc: | 38 # and then add this line to your .bashrc: |
| 40 # complete -F _optcomplete ncval.py | 39 # complete -F _optcomplete ncval.py |
| 41 try: | 40 try: |
| 42 import optcomplete | 41 import optcomplete |
| 43 optcomplete.autocomplete(parser) | 42 optcomplete.autocomplete(parser) |
| 44 except ImportError: | 43 except ImportError: |
| 45 pass | 44 pass |
| 46 | 45 |
| 47 options, args = parser.parse_args(argv) | 46 options = parser.parse_args(args) |
| 48 if not args: | 47 nexe = options.nexe |
| 49 parser.error('No executable file specified') | |
| 50 | 48 |
| 51 nexe = args[0] | |
| 52 if options.verbose: | 49 if options.verbose: |
| 53 Log.verbose = True | 50 Log.verbose = True |
| 54 | 51 |
| 55 # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the | 52 # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the |
| 56 # amount of additional checking done here. | 53 # amount of additional checking done here. |
| 57 osname = getos.GetPlatform() | 54 osname = getos.GetPlatform() |
| 58 if not os.path.exists(nexe): | 55 if not os.path.exists(nexe): |
| 59 raise Error('executable not found: %s' % nexe) | 56 raise Error('executable not found: %s' % nexe) |
| 60 if not os.path.isfile(nexe): | 57 if not os.path.isfile(nexe): |
| 61 raise Error('not a file: %s' % nexe) | 58 raise Error('not a file: %s' % nexe) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 85 # By default, don't print anything on success. | 82 # By default, don't print anything on success. |
| 86 Log(proc_out) | 83 Log(proc_out) |
| 87 | 84 |
| 88 | 85 |
| 89 if __name__ == '__main__': | 86 if __name__ == '__main__': |
| 90 try: | 87 try: |
| 91 sys.exit(main(sys.argv[1:])) | 88 sys.exit(main(sys.argv[1:])) |
| 92 except Error as e: | 89 except Error as e: |
| 93 sys.stderr.write(str(e) + '\n') | 90 sys.stderr.write(str(e) + '\n') |
| 94 sys.exit(1) | 91 sys.exit(1) |
| OLD | NEW |