Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: build/android/pylib/android_commands.py

Issue 14646030: [Android] Fix md5sum for component build (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tools/android/md5sum/md5sum.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Provides an interface to communicate with the device via the adb command. 5 """Provides an interface to communicate with the device via the adb command.
6 6
7 Assumes adb binary is currently on system path. 7 Assumes adb binary is currently on system path.
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 # Keycode "enum" suitable for passing to AndroidCommands.SendKey(). 55 # Keycode "enum" suitable for passing to AndroidCommands.SendKey().
56 KEYCODE_HOME = 3 56 KEYCODE_HOME = 3
57 KEYCODE_BACK = 4 57 KEYCODE_BACK = 4
58 KEYCODE_DPAD_UP = 19 58 KEYCODE_DPAD_UP = 19
59 KEYCODE_DPAD_DOWN = 20 59 KEYCODE_DPAD_DOWN = 20
60 KEYCODE_DPAD_RIGHT = 22 60 KEYCODE_DPAD_RIGHT = 22
61 KEYCODE_ENTER = 66 61 KEYCODE_ENTER = 66
62 KEYCODE_MENU = 82 62 KEYCODE_MENU = 82
63 63
64 MD5SUM_DEVICE_PATH = '/data/local/tmp/md5sum_bin' 64 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/'
65 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin'
66 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER
65 67
66 def GetEmulators(): 68 def GetEmulators():
67 """Returns a list of emulators. Does not filter by status (e.g. offline). 69 """Returns a list of emulators. Does not filter by status (e.g. offline).
68 70
69 Both devices starting with 'emulator' will be returned in below output: 71 Both devices starting with 'emulator' will be returned in below output:
70 72
71 * daemon not running. starting it now on port 5037 * 73 * daemon not running. starting it now on port 5037 *
72 * daemon started successfully * 74 * daemon started successfully *
73 List of devices attached 75 List of devices attached
74 027c10494100b4d7 device 76 027c10494100b4d7 device
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 def __init__(self, device=None): 207 def __init__(self, device=None):
206 self._adb = adb_interface.AdbInterface() 208 self._adb = adb_interface.AdbInterface()
207 if device: 209 if device:
208 self._adb.SetTargetSerial(device) 210 self._adb.SetTargetSerial(device)
209 self._device = device 211 self._device = device
210 self._logcat = None 212 self._logcat = None
211 self.logcat_process = None 213 self.logcat_process = None
212 self._logcat_tmpoutfile = None 214 self._logcat_tmpoutfile = None
213 self._pushed_files = [] 215 self._pushed_files = []
214 self._device_utc_offset = self.RunShellCommand('date +%z')[0] 216 self._device_utc_offset = self.RunShellCommand('date +%z')[0]
215 self._md5sum_path = '' 217 self._md5sum_build_dir = ''
216 self._external_storage = '' 218 self._external_storage = ''
217 self._util_wrapper = '' 219 self._util_wrapper = ''
218 220
219 def _LogShell(self, cmd): 221 def _LogShell(self, cmd):
220 """Logs the adb shell command.""" 222 """Logs the adb shell command."""
221 if self._device: 223 if self._device:
222 device_repr = self._device[-4:] 224 device_repr = self._device[-4:]
223 else: 225 else:
224 device_repr = '????' 226 device_repr = '????'
225 logging.info('[%s]> %s', device_repr, cmd) 227 logging.info('[%s]> %s', device_repr, cmd)
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 self.RunShellCommand('pm clear ' + package) 665 self.RunShellCommand('pm clear ' + package)
664 666
665 def SendKeyEvent(self, keycode): 667 def SendKeyEvent(self, keycode):
666 """Sends keycode to the device. 668 """Sends keycode to the device.
667 669
668 Args: 670 Args:
669 keycode: Numeric keycode to send (see "enum" at top of file). 671 keycode: Numeric keycode to send (see "enum" at top of file).
670 """ 672 """
671 self.RunShellCommand('input keyevent %d' % keycode) 673 self.RunShellCommand('input keyevent %d' % keycode)
672 674
675 def CheckMd5Sum(self, local_path, device_path):
676 assert os.path.exists(local_path), 'Local path not found %s' % local_path
677
678 if not self._md5sum_build_dir:
679 default_build_type = os.environ.get('BUILD_TYPE', 'Debug')
680 build_dir = '%s/%s/' % (
681 cmd_helper.OutDirectory().get(), default_build_type)
682 md5sum_dist_path = '%s/md5sum_dist' % build_dir
683 if not os.path.exists(md5sum_dist_path):
684 build_dir = '%s/Release/' % cmd_helper.OutDirectory().get()
685 md5sum_dist_path = '%s/md5sum_dist' % build_dir
686 assert os.path.exists(md5sum_dist_path), 'Please build md5sum.'
687 command = 'push %s %s' % (md5sum_dist_path, MD5SUM_DEVICE_FOLDER)
688 assert _HasAdbPushSucceeded(self._adb.SendCommand(command))
689 self._md5sum_build_dir = build_dir
690
691 self._pushed_files.append(device_path)
692 hashes_on_device = _ComputeFileListHash(
693 self.RunShellCommand(MD5SUM_LD_LIBRARY_PATH + ' ' + self._util_wrapper +
694 ' ' + MD5SUM_DEVICE_PATH + ' ' + device_path))
695 assert os.path.exists(local_path), 'Local path not found %s' % local_path
696 md5sum_output = cmd_helper.GetCmdOutput(
697 ['%s/md5sum_bin_host' % self._md5sum_build_dir, local_path])
698 hashes_on_host = _ComputeFileListHash(md5sum_output.splitlines())
699
700 return hashes_on_device == hashes_on_host
701
673 def PushIfNeeded(self, local_path, device_path): 702 def PushIfNeeded(self, local_path, device_path):
674 """Pushes |local_path| to |device_path|. 703 """Pushes |local_path| to |device_path|.
675 704
676 Works for files and directories. This method skips copying any paths in 705 Works for files and directories. This method skips copying any paths in
677 |test_data_paths| that already exist on the device with the same hash. 706 |test_data_paths| that already exist on the device with the same hash.
678 707
679 All pushed files can be removed by calling RemovePushedFiles(). 708 All pushed files can be removed by calling RemovePushedFiles().
680 """ 709 """
681 assert os.path.exists(local_path), 'Local path not found %s' % local_path 710 if self.CheckMd5Sum(local_path, device_path):
682
683 if not self._md5sum_path:
684 default_build_type = os.environ.get('BUILD_TYPE', 'Debug')
685 md5sum_path = '%s/%s/md5sum_bin' % (cmd_helper.OutDirectory.get(),
686 default_build_type)
687 if not os.path.exists(md5sum_path):
688 md5sum_path = '%s/Release/md5sum_bin' % cmd_helper.OutDirectory.get()
689 assert os.path.exists(md5sum_path), 'Please build md5sum.'
690 command = 'push %s %s' % (md5sum_path, MD5SUM_DEVICE_PATH)
691 assert _HasAdbPushSucceeded(self._adb.SendCommand(command))
692 self._md5sum_path = md5sum_path
693
694 self._pushed_files.append(device_path)
695 hashes_on_device = _ComputeFileListHash(
696 self.RunShellCommand(self._util_wrapper + ' ' + MD5SUM_DEVICE_PATH +
697 ' ' + device_path))
698 assert os.path.exists(local_path), 'Local path not found %s' % local_path
699 md5sum_output = cmd_helper.GetCmdOutput(
700 ['%s_host' % self._md5sum_path, local_path])
701 hashes_on_host = _ComputeFileListHash(md5sum_output.splitlines())
702 if hashes_on_device == hashes_on_host:
703 return 711 return
704 712
705 # They don't match, so remove everything first and then create it. 713 # They don't match, so remove everything first and then create it.
706 if os.path.isdir(local_path): 714 if os.path.isdir(local_path):
707 self.RunShellCommand('rm -r %s' % device_path, timeout_time=2 * 60) 715 self.RunShellCommand('rm -r %s' % device_path, timeout_time=2 * 60)
708 self.RunShellCommand('mkdir -p %s' % device_path) 716 self.RunShellCommand('mkdir -p %s' % device_path)
709 717
710 # NOTE: We can't use adb_interface.Push() because it hardcodes a timeout of 718 # NOTE: We can't use adb_interface.Push() because it hardcodes a timeout of
711 # 60 seconds which isn't sufficient for a lot of users of this method. 719 # 60 seconds which isn't sufficient for a lot of users of this method.
712 push_command = 'push %s %s' % (local_path, device_path) 720 push_command = 'push %s %s' % (local_path, device_path)
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 """ 1297 """
1290 def __init__(self, output): 1298 def __init__(self, output):
1291 self._output = output 1299 self._output = output
1292 1300
1293 def write(self, data): 1301 def write(self, data):
1294 data = data.replace('\r\r\n', '\n') 1302 data = data.replace('\r\r\n', '\n')
1295 self._output.write(data) 1303 self._output.write(data)
1296 1304
1297 def flush(self): 1305 def flush(self):
1298 self._output.flush() 1306 self._output.flush()
OLDNEW
« no previous file with comments | « no previous file | tools/android/md5sum/md5sum.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698