|
17 | 17 |
|
18 | 18 | from __future__ import print_function
|
19 | 19 |
|
| 20 | +import os |
20 | 21 | import subprocess
|
21 | 22 | import tempfile
|
22 | 23 | import uuid
|
23 | 24 |
|
24 | 25 |
|
25 | 26 | # A temporary directory on the Android device.
|
26 | 27 | DEVICE_TEMP_DIR = '/data/local/tmp'
|
| 28 | +ENV_PREFIX = 'ANDROID_CHILD_' |
27 | 29 |
|
28 | 30 |
|
29 | 31 | def shell(args):
|
@@ -93,16 +95,21 @@ def execute_on_device(executable_path, executable_arguments):
|
93 | 95 | executable = '{}/__executable'.format(uuid_dir)
|
94 | 96 | push(executable_path, executable)
|
95 | 97 |
|
| 98 | + child_environment = ['{}="{}"'.format(k.replace(ENV_PREFIX, '', 1), v) |
| 99 | + for (k, v) in os.environ.items() |
| 100 | + if k.startswith(ENV_PREFIX)] |
| 101 | + |
96 | 102 | # When running the executable on the device, we need to pass it the same
|
97 | 103 | # arguments, as well as specify the correct LD_LIBRARY_PATH. Save these
|
98 | 104 | # to a file we can easily call multiple times.
|
99 | 105 | executable_with_args = '{}/__executable_with_args'.format(uuid_dir)
|
100 | 106 | _create_executable_on_device(
|
101 | 107 | executable_with_args,
|
102 | 108 | 'LD_LIBRARY_PATH={uuid_dir}:{tmp_dir} '
|
103 |
| - '{executable} {executable_arguments}'.format( |
| 109 | + '{child_environment} {executable} {executable_arguments}'.format( |
104 | 110 | uuid_dir=uuid_dir,
|
105 | 111 | tmp_dir=DEVICE_TEMP_DIR,
|
| 112 | + child_environment=' '.join(child_environment), |
106 | 113 | executable=executable,
|
107 | 114 | executable_arguments=' '.join(executable_arguments)))
|
108 | 115 |
|
@@ -146,7 +153,7 @@ def execute_on_device(executable_path, executable_arguments):
|
146 | 153 | # the executable on the device.
|
147 | 154 | return 1
|
148 | 155 |
|
149 |
| - print(stdout) |
| 156 | + print(stdout, end='') |
150 | 157 |
|
151 | 158 | shell(['rm', '-rf', uuid_dir])
|
152 | 159 | return 0
|
0 commit comments