Chromium Code Reviews| 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, 6, 0): | 19 if sys.version_info < (2, 6, 0): |
| 20 sys.stderr.write("python 2.6 or later is required run this script\n") | 20 sys.stderr.write("python 2.6 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('args', metavar="EXE", nargs='+', |
|
binji
2014/11/13 23:57:04
exes?
Sam Clegg
2014/11/30 17:55:13
Done.
| |
| 36 help='Verbose output') | 36 help='Executable to validate') |
| 37 | 37 |
| 38 # To enable bash completion for this command first install optcomplete | 38 # To enable bash completion for this command first install optcomplete |
| 39 # and then add this line to your .bashrc: | 39 # and then add this line to your .bashrc: |
| 40 # complete -F _optcomplete ncval.py | 40 # complete -F _optcomplete ncval.py |
| 41 try: | 41 try: |
| 42 import optcomplete | 42 import optcomplete |
| 43 optcomplete.autocomplete(parser) | 43 optcomplete.autocomplete(parser) |
| 44 except ImportError: | 44 except ImportError: |
| 45 pass | 45 pass |
| 46 | 46 |
| 47 options, args = parser.parse_args(argv) | 47 options = parser.parse_args(args) |
| 48 if not args: | |
| 49 parser.error('No executable file specified') | |
| 50 | 48 |
| 51 nexe = args[0] | 49 nexe = options.args[0] |
| 52 if options.verbose: | 50 if options.verbose: |
| 53 Log.verbose = True | 51 Log.verbose = True |
| 54 | 52 |
| 55 # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the | 53 # TODO(binji): http://crbug.com/321791. Fix ncval upstream to reduce the |
| 56 # amount of additional checking done here. | 54 # amount of additional checking done here. |
| 57 osname = getos.GetPlatform() | 55 osname = getos.GetPlatform() |
| 58 if not os.path.exists(nexe): | 56 if not os.path.exists(nexe): |
| 59 raise Error('executable not found: %s' % nexe) | 57 raise Error('executable not found: %s' % nexe) |
| 60 if not os.path.isfile(nexe): | 58 if not os.path.isfile(nexe): |
| 61 raise Error('not a file: %s' % nexe) | 59 raise Error('not a file: %s' % nexe) |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 85 # By default, don't print anything on success. | 83 # By default, don't print anything on success. |
| 86 Log(proc_out) | 84 Log(proc_out) |
| 87 | 85 |
| 88 | 86 |
| 89 if __name__ == '__main__': | 87 if __name__ == '__main__': |
| 90 try: | 88 try: |
| 91 sys.exit(main(sys.argv[1:])) | 89 sys.exit(main(sys.argv[1:])) |
| 92 except Error as e: | 90 except Error as e: |
| 93 sys.stderr.write(str(e) + '\n') | 91 sys.stderr.write(str(e) + '\n') |
| 94 sys.exit(1) | 92 sys.exit(1) |
| OLD | NEW |