| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Pushes native libraries to a device. | 7 """Pushes native libraries to a device. |
| 8 | 8 |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import json | 11 import json |
| 12 import optparse | 12 import optparse |
| 13 import os | 13 import os |
| 14 import sys | 14 import sys |
| 15 | 15 |
| 16 from util import build_device |
| 16 from util import build_utils | 17 from util import build_utils |
| 17 from util import md5_check | 18 from util import md5_check |
| 18 | 19 |
| 19 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') | |
| 20 sys.path.append(BUILD_ANDROID_DIR) | |
| 21 | |
| 22 from pylib import android_commands | |
| 23 | |
| 24 | |
| 25 def DoPush(options): | 20 def DoPush(options): |
| 26 libraries = build_utils.ReadJson(options.libraries_json) | 21 libraries = build_utils.ReadJson(options.libraries_json) |
| 27 | 22 |
| 28 adb = android_commands.AndroidCommands() | 23 bd = build_device.GetBuildDeviceFromPath(options.build_device_configuration) |
| 29 serial_number = adb.Adb().GetSerialNumber() | 24 if not bd: |
| 25 return |
| 26 |
| 27 serial_number = bd.GetSerialNumber() |
| 30 # A list so that it is modifiable in Push below. | 28 # A list so that it is modifiable in Push below. |
| 31 needs_directory = [True] | 29 needs_directory = [True] |
| 32 for lib in libraries: | 30 for lib in libraries: |
| 33 device_path = os.path.join(options.device_dir, lib) | 31 device_path = os.path.join(options.device_dir, lib) |
| 34 host_path = os.path.join(options.libraries_dir, lib) | 32 host_path = os.path.join(options.libraries_dir, lib) |
| 35 | 33 |
| 36 def Push(): | 34 def Push(): |
| 37 if needs_directory: | 35 if needs_directory: |
| 38 adb.RunShellCommand('mkdir -p ' + options.device_dir) | 36 bd.RunShellCommand('mkdir -p ' + options.device_dir) |
| 39 needs_directory[:] = [] # = False | 37 needs_directory[:] = [] # = False |
| 40 adb.PushIfNeeded(host_path, device_path) | 38 bd.PushIfNeeded(host_path, device_path) |
| 41 | 39 |
| 42 record_path = '%s.%s.push.md5.stamp' % (host_path, serial_number) | 40 record_path = '%s.%s.push.md5.stamp' % (host_path, serial_number) |
| 43 md5_check.CallAndRecordIfStale( | 41 md5_check.CallAndRecordIfStale( |
| 44 Push, | 42 Push, |
| 45 record_path=record_path, | 43 record_path=record_path, |
| 46 input_paths=[host_path], | 44 input_paths=[host_path], |
| 47 input_strings=[device_path]) | 45 input_strings=[device_path]) |
| 48 | 46 |
| 49 | 47 |
| 50 def main(argv): | 48 def main(argv): |
| 51 if not build_utils.IsDeviceReady(): | |
| 52 build_utils.PrintBigWarning( | |
| 53 'Zero (or multiple) devices attached. Skipping native library push.') | |
| 54 return | |
| 55 | |
| 56 parser = optparse.OptionParser() | 49 parser = optparse.OptionParser() |
| 57 parser.add_option('--libraries-dir', | 50 parser.add_option('--libraries-dir', |
| 58 help='Directory that contains stripped libraries.') | 51 help='Directory that contains stripped libraries.') |
| 59 parser.add_option('--device-dir', | 52 parser.add_option('--device-dir', |
| 60 help='Device directory to push the libraries to.') | 53 help='Device directory to push the libraries to.') |
| 61 parser.add_option('--libraries-json', | 54 parser.add_option('--libraries-json', |
| 62 help='Path to the json list of native libraries.') | 55 help='Path to the json list of native libraries.') |
| 63 parser.add_option('--stamp', help='Path to touch on success.') | 56 parser.add_option('--stamp', help='Path to touch on success.') |
| 57 parser.add_option('--build-device-configuration', |
| 58 help='Path to build device configuration.') |
| 64 options, _ = parser.parse_args() | 59 options, _ = parser.parse_args() |
| 65 | 60 |
| 66 required_options = ['libraries_dir', 'device_dir', 'libraries_json'] | 61 required_options = ['libraries_dir', 'device_dir', 'libraries_json'] |
| 67 build_utils.CheckOptions(options, parser, required=required_options) | 62 build_utils.CheckOptions(options, parser, required=required_options) |
| 68 | 63 |
| 69 DoPush(options) | 64 DoPush(options) |
| 70 | 65 |
| 71 if options.stamp: | 66 if options.stamp: |
| 72 build_utils.Touch(options.stamp) | 67 build_utils.Touch(options.stamp) |
| 73 | 68 |
| 74 | 69 |
| 75 if __name__ == '__main__': | 70 if __name__ == '__main__': |
| 76 sys.exit(main(sys.argv)) | 71 sys.exit(main(sys.argv)) |
| OLD | NEW |