Skip to content

Commit fd2cf65

Browse files
authored
Merge pull request #24146 from drodriguez/android-faster-adb-push
[android] Make ADB push use sync if available.
2 parents 1119b91 + e348f6c commit fd2cf65

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

utils/android/adb/commands.py

Lines changed: 18 additions & 4 deletions
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

Lines changed: 7 additions & 5 deletions
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)