• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import os
2import subprocess
3import sys
4
5def GetObjcopyCmd(target):
6    """Return a suitable objcopy command."""
7    if target == 'mips32':
8      return 'mipsel-nacl-objcopy'
9    return 'arm-nacl-objcopy'
10
11def GetObjdumpCmd(target):
12    """Return a suitable objdump command."""
13    if target == 'mips32':
14      return 'mipsel-nacl-objdump'
15    return 'arm-nacl-objdump'
16
17def shellcmd(command, echo=True):
18    if not isinstance(command, str):
19        command = ' '.join(command)
20
21    if echo:
22      print >> sys.stderr, '[cmd]'
23      print >> sys.stderr,  command
24      print >> sys.stderr
25
26    stdout_result = subprocess.check_output(command, shell=True)
27    if echo: sys.stdout.write(stdout_result)
28    return stdout_result
29
30def FindBaseNaCl():
31    """Find the base native_client/ directory."""
32    nacl = 'native_client'
33    path_list = os.getcwd().split(os.sep)
34    """Use the executable path if cwd does not contain 'native_client' """
35    path_list = path_list if nacl in path_list else sys.argv[0].split(os.sep)
36    if nacl not in path_list:
37        print "Script must be executed from within 'native_client' directory"
38        exit(1)
39    last_index = len(path_list) - path_list[::-1].index(nacl)
40    return os.sep.join(path_list[:last_index])
41
42def get_sfi_string(args, sb_ret, nonsfi_ret, native_ret):
43    """Return a value depending on args.sandbox and args.nonsfi."""
44    if args.sandbox:
45        assert(not args.nonsfi)
46        return sb_ret
47    if args.nonsfi:
48        return nonsfi_ret
49    return native_ret
50