Skip to content

Commit e348f6c

Browse files
committed
[android] Make ADB push use sync if available.
In recent adb versions, the push command supports a new option --sync which performs checksumming of the files to transmit against the files already in the device. This increases the effective transmission speed of the inital step in the test for Android. It should not affect the speed of each tests, since they are pushed to different folders, and also they are removed when they are successful. However, the test executables are small compared to the size of the libraries from the stadard library and dependencies. This should exclusively affect Android and only to people testing the executable tests (not CI).
1 parent fa43e3b commit e348f6c

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

utils/android/adb/commands.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,24 @@ def rmdir(path):
4444
shell(['rm', '-rf', '{}/*'.format(path)])
4545

4646

47-
def push(local_path, device_path):
48-
"""Move the file at the given local path to the path on the device."""
49-
return subprocess.check_output(['adb', 'push', local_path, device_path],
50-
stderr=subprocess.STDOUT).strip()
47+
def push(local_paths, device_path):
48+
"""Move the files at the given local paths to the path on the device."""
49+
if isinstance(local_paths, str):
50+
local_paths = [local_paths]
51+
try:
52+
# In recent versions of ADB, push supports --sync, which checksums the
53+
# files to be transmitted and skip the ones that haven't changed, which
54+
# improves the effective transfer speed.
55+
return subprocess.check_output(
56+
['adb', 'push', '--sync'] + local_paths + [device_path],
57+
stderr=subprocess.STDOUT).strip()
58+
except subprocess.CalledProcessError as e:
59+
if "unrecognized option '--sync'" in e.output:
60+
return subprocess.check_output(
61+
['adb', 'push'] + local_paths + [device_path],
62+
stderr=subprocess.STDOUT).strip()
63+
else:
64+
raise e
5165

5266

5367
def reboot():

utils/android/adb_push_built_products/main.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def argument_parser():
5353
return parser
5454

5555

56-
def _push(source, destination):
57-
print('Pushing "{}" to device path "{}".'.format(source, destination))
58-
print(adb.commands.push(source, destination))
56+
def _push(sources, destination):
57+
print('Pushing "{}" to device path "{}".'.format(sources, destination))
58+
print(adb.commands.push(sources, destination))
5959

6060

6161
def main():
@@ -70,8 +70,10 @@ def main():
7070

7171
for path in args.paths:
7272
if os.path.isdir(path):
73-
for basename in glob.glob(os.path.join(path, '*.so')):
74-
_push(os.path.join(path, basename), args.destination)
73+
full_paths = [
74+
os.path.join(path, basename)
75+
for basename in glob.glob(os.path.join(path, '*.so'))]
76+
_push(full_paths, args.destination)
7577
else:
7678
_push(path, args.destination)
7779

0 commit comments

Comments
 (0)