1#!/usr/bin/python 2 3import os, sys, subprocess, tempfile 4from android_common import * 5 6ANDROID_TMPDIR = '/data/local/tmp/Output' 7 8here = os.path.abspath(os.path.dirname(sys.argv[0])) 9device_binary = os.path.join(ANDROID_TMPDIR, os.path.basename(sys.argv[0])) 10 11def build_env(): 12 args = [] 13 # Android linker ignores RPATH. Set LD_LIBRARY_PATH to Output dir. 14 args.append('LD_LIBRARY_PATH=%s:%s' % 15 (ANDROID_TMPDIR, os.environ.get('LD_LIBRARY_PATH', ''))) 16 for (key, value) in os.environ.items(): 17 if key in ['ASAN_OPTIONS', 'ASAN_ACTIVATION_OPTIONS']: 18 args.append('%s="%s"' % (key, value)) 19 return ' '.join(args) 20 21is_64bit = (subprocess.check_output(['file', sys.argv[0] + '.real']).find('64-bit') != -1) 22asanwrapper = "" if is_64bit else "asanwrapper " 23 24device_env = build_env() 25device_args = ' '.join(sys.argv[1:]) # FIXME: escape? 26device_stdout = device_binary + '.stdout' 27device_stderr = device_binary + '.stderr' 28device_exitcode = device_binary + '.exitcode' 29ret = adb(['shell', 'cd %s && %s %s%s %s >%s 2>%s ; echo $? >%s' % 30 (ANDROID_TMPDIR, device_env, asanwrapper, device_binary, device_args, 31 device_stdout, device_stderr, device_exitcode)]) 32if ret != 0: 33 sys.exit(ret) 34 35sys.stdout.write(pull_from_device(device_stdout)) 36sys.stderr.write(pull_from_device(device_stderr)) 37sys.exit(int(pull_from_device(device_exitcode))) 38