Skip to content

[android] Make ADB push use sync if available. #24146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions utils/android/adb/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,24 @@ def rmdir(path):
shell(['rm', '-rf', '{}/*'.format(path)])


def push(local_path, device_path):
"""Move the file at the given local path to the path on the device."""
return subprocess.check_output(['adb', 'push', local_path, device_path],
stderr=subprocess.STDOUT).strip()
def push(local_paths, device_path):
"""Move the files at the given local paths to the path on the device."""
if isinstance(local_paths, str):
local_paths = [local_paths]
try:
# In recent versions of ADB, push supports --sync, which checksums the
# files to be transmitted and skip the ones that haven't changed, which
# improves the effective transfer speed.
return subprocess.check_output(
['adb', 'push', '--sync'] + local_paths + [device_path],
stderr=subprocess.STDOUT).strip()
except subprocess.CalledProcessError as e:
if "unrecognized option '--sync'" in e.output:
return subprocess.check_output(
['adb', 'push'] + local_paths + [device_path],
stderr=subprocess.STDOUT).strip()
else:
raise e


def reboot():
Expand Down
12 changes: 7 additions & 5 deletions utils/android/adb_push_built_products/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ def argument_parser():
return parser


def _push(source, destination):
print('Pushing "{}" to device path "{}".'.format(source, destination))
print(adb.commands.push(source, destination))
def _push(sources, destination):
print('Pushing "{}" to device path "{}".'.format(sources, destination))
print(adb.commands.push(sources, destination))


def main():
Expand All @@ -70,8 +70,10 @@ def main():

for path in args.paths:
if os.path.isdir(path):
for basename in glob.glob(os.path.join(path, '*.so')):
_push(os.path.join(path, basename), args.destination)
full_paths = [
os.path.join(path, basename)
for basename in glob.glob(os.path.join(path, '*.so'))]
_push(full_paths, args.destination)
else:
_push(path, args.destination)

Expand Down