| 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 launching application within the sel_ldr. | 6 """Wrapper script for launching application within the sel_ldr. |
| 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 create_nmf | 14 import create_nmf |
| 15 import getos | 15 import getos |
| 16 | 16 |
| 17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 17 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 18 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) | 18 NACL_SDK_ROOT = os.path.dirname(SCRIPT_DIR) |
| 19 | 19 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 42 # See if qemu is in any of these locations. | 42 # See if qemu is in any of these locations. |
| 43 qemu_bin = None | 43 qemu_bin = None |
| 44 for loc in qemu_locations: | 44 for loc in qemu_locations: |
| 45 if os.path.isfile(loc) and os.access(loc, os.X_OK): | 45 if os.path.isfile(loc) and os.access(loc, os.X_OK): |
| 46 qemu_bin = loc | 46 qemu_bin = loc |
| 47 break | 47 break |
| 48 return qemu_bin | 48 return qemu_bin |
| 49 | 49 |
| 50 | 50 |
| 51 def main(argv): | 51 def main(argv): |
| 52 usage = 'Usage: %prog [options] <.nexe>' | |
| 53 epilog = 'Example: sel_ldr.py my_nexe.nexe' | 52 epilog = 'Example: sel_ldr.py my_nexe.nexe' |
| 54 parser = optparse.OptionParser(usage, description=__doc__, epilog=epilog) | 53 parser = argparse.ArgumentParser(description=__doc__, epilog=epilog) |
| 55 parser.add_option('-v', '--verbose', action='store_true', | 54 parser.add_argument('-v', '--verbose', action='store_true', |
| 56 help='Verbose output') | 55 help='Verbose output') |
| 57 parser.add_option('-d', '--debug', action='store_true', | 56 parser.add_argument('-d', '--debug', action='store_true', |
| 58 help='Enable debug stub') | 57 help='Enable debug stub') |
| 59 parser.add_option('--debug-libs', action='store_true', | 58 parser.add_argument('--debug-libs', action='store_true', |
| 60 help='For dynamic executables, reference debug ' | 59 help='For dynamic executables, reference debug ' |
| 61 'libraries rather then release') | 60 'libraries rather then release') |
| 61 parser.add_argument('executable', help='executable (.nexe) to run') |
| 62 parser.add_argument('args', nargs='*', help='argument to pass to exectuable') |
| 62 | 63 |
| 63 # To enable bash completion for this command first install optcomplete | 64 # To enable bash completion for this command first install optcomplete |
| 64 # and then add this line to your .bashrc: | 65 # and then add this line to your .bashrc: |
| 65 # complete -F _optcomplete sel_ldr.py | 66 # complete -F _optcomplete sel_ldr.py |
| 66 try: | 67 try: |
| 67 import optcomplete | 68 import optcomplete |
| 68 optcomplete.autocomplete(parser) | 69 optcomplete.autocomplete(parser) |
| 69 except ImportError: | 70 except ImportError: |
| 70 pass | 71 pass |
| 71 | 72 |
| 72 options, args = parser.parse_args(argv) | 73 options = parser.parse_args(argv) |
| 73 if not args: | |
| 74 parser.error('No executable file specified') | |
| 75 | 74 |
| 76 nexe = args[0] | |
| 77 if options.verbose: | 75 if options.verbose: |
| 78 Log.verbose = True | 76 Log.verbose = True |
| 79 | 77 |
| 80 osname = getos.GetPlatform() | 78 osname = getos.GetPlatform() |
| 81 if not os.path.exists(nexe): | 79 if not os.path.exists(options.executable): |
| 82 raise Error('executable not found: %s' % nexe) | 80 raise Error('executable not found: %s' % options.executable) |
| 83 if not os.path.isfile(nexe): | 81 if not os.path.isfile(options.executable): |
| 84 raise Error('not a file: %s' % nexe) | 82 raise Error('not a file: %s' % options.executable) |
| 85 | 83 |
| 86 arch, dynamic = create_nmf.ParseElfHeader(nexe) | 84 arch, dynamic = create_nmf.ParseElfHeader(options.executable) |
| 87 | 85 |
| 88 if arch == 'arm' and osname != 'linux': | 86 if arch == 'arm' and osname != 'linux': |
| 89 raise Error('Cannot run ARM executables under sel_ldr on ' + osname) | 87 raise Error('Cannot run ARM executables under sel_ldr on ' + osname) |
| 90 | 88 |
| 91 arch_suffix = arch.replace('-', '_') | 89 arch_suffix = arch.replace('-', '_') |
| 92 | 90 |
| 93 sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) | 91 sel_ldr = os.path.join(SCRIPT_DIR, 'sel_ldr_%s' % arch_suffix) |
| 94 irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) | 92 irt = os.path.join(SCRIPT_DIR, 'irt_core_%s.nexe' % arch_suffix) |
| 95 if osname == 'win': | 93 if osname == 'win': |
| 96 sel_ldr += '.exe' | 94 sel_ldr += '.exe' |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 else: | 141 else: |
| 144 sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32') | 142 sdk_lib_dir = os.path.join(sdk_lib_dir, 'lib32') |
| 145 ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so') | 143 ldso = os.path.join(sdk_lib_dir, 'runnable-ld.so') |
| 146 cmd.append(ldso) | 144 cmd.append(ldso) |
| 147 Log('LD.SO = %s' % ldso) | 145 Log('LD.SO = %s' % ldso) |
| 148 libpath += ':' + sdk_lib_dir | 146 libpath += ':' + sdk_lib_dir |
| 149 cmd.append('--library-path') | 147 cmd.append('--library-path') |
| 150 cmd.append(libpath) | 148 cmd.append(libpath) |
| 151 | 149 |
| 152 | 150 |
| 153 if args: | 151 # Append arguments for the executable itself. |
| 154 # Append arguments for the executable itself. | 152 cmd += options.args |
| 155 cmd += args | |
| 156 | 153 |
| 157 Log(cmd) | 154 Log(cmd) |
| 158 rtn = subprocess.call(cmd) | 155 rtn = subprocess.call(cmd) |
| 159 return rtn | 156 return rtn |
| 160 | 157 |
| 161 | 158 |
| 162 if __name__ == '__main__': | 159 if __name__ == '__main__': |
| 163 try: | 160 try: |
| 164 sys.exit(main(sys.argv[1:])) | 161 sys.exit(main(sys.argv[1:])) |
| 165 except Error as e: | 162 except Error as e: |
| 166 sys.stderr.write(str(e) + '\n') | 163 sys.stderr.write(str(e) + '\n') |
| 167 sys.exit(1) | 164 sys.exit(1) |
| OLD | NEW |