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

Side by Side Diff: build/android/gyp/util/build_device.py

Issue 333933003: [Android] Switch to DeviceUtils version of RunShellCommand. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 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
« no previous file with comments | « build/android/enable_asserts.py ('k') | build/android/host_heartbeat.py » ('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 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 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 """ A simple device interface for build steps. 5 """ A simple device interface for build steps.
6 6
7 """ 7 """
8 8
9 import logging 9 import logging
10 import os 10 import os
(...skipping 13 matching lines...) Expand all
24 24
25 25
26 class BuildDevice(object): 26 class BuildDevice(object):
27 def __init__(self, configuration): 27 def __init__(self, configuration):
28 self.id = configuration['id'] 28 self.id = configuration['id']
29 self.description = configuration['description'] 29 self.description = configuration['description']
30 self.install_metadata = configuration['install_metadata'] 30 self.install_metadata = configuration['install_metadata']
31 self.device = device_utils.DeviceUtils(self.id) 31 self.device = device_utils.DeviceUtils(self.id)
32 32
33 def RunShellCommand(self, *args, **kwargs): 33 def RunShellCommand(self, *args, **kwargs):
34 return self.device.old_interface.RunShellCommand(*args, **kwargs) 34 return self.device.RunShellCommand(*args, **kwargs)
35 35
36 def PushIfNeeded(self, *args, **kwargs): 36 def PushIfNeeded(self, *args, **kwargs):
37 return self.device.old_interface.PushIfNeeded(*args, **kwargs) 37 return self.device.old_interface.PushIfNeeded(*args, **kwargs)
38 38
39 def GetSerialNumber(self): 39 def GetSerialNumber(self):
40 return self.id 40 return self.id
41 41
42 def Install(self, *args, **kwargs): 42 def Install(self, *args, **kwargs):
43 return self.device.old_interface.Install(*args, **kwargs) 43 return self.device.old_interface.Install(*args, **kwargs)
44 44
45 def GetInstallMetadata(self, apk_package): 45 def GetInstallMetadata(self, apk_package):
46 """Gets the metadata on the device for the apk_package apk.""" 46 """Gets the metadata on the device for the apk_package apk."""
47 # Matches lines like: 47 # Matches lines like:
48 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 48 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
49 # org.chromium.chrome.shell.apk 49 # org.chromium.chrome.shell.apk
50 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 50 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \
51 # org.chromium.chrome.shell-1.apk 51 # org.chromium.chrome.shell-1.apk
52 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) 52 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s)
53 matches = filter(apk_matcher, self.install_metadata) 53 matches = filter(apk_matcher, self.install_metadata)
54 return matches[0] if matches else None 54 return matches[0] if matches else None
55 55
56 56
57 def GetConfigurationForDevice(device_id): 57 def GetConfigurationForDevice(device_id):
58 device = device_utils.DeviceUtils(device_id) 58 device = device_utils.DeviceUtils(device_id)
59 configuration = None 59 configuration = None
60 has_root = False 60 has_root = False
61 is_online = device.IsOnline() 61 is_online = device.IsOnline()
62 if is_online: 62 if is_online:
63 cmd = 'ls -l /data/app; getprop ro.build.description' 63 cmd = 'ls -l /data/app; getprop ro.build.description'
64 cmd_output = device.old_interface.RunShellCommand(cmd) 64 cmd_output = device.RunShellCommand(cmd)
65 has_root = not 'Permission denied' in cmd_output[0] 65 has_root = not 'Permission denied' in cmd_output[0]
66 if not has_root: 66 if not has_root:
67 # Disable warning log messages from EnableRoot() 67 # Disable warning log messages from EnableRoot()
68 logging.getLogger().disabled = True 68 logging.getLogger().disabled = True
69 try: 69 try:
70 device.EnableRoot() 70 device.EnableRoot()
71 has_root = True 71 has_root = True
72 except device_errors.CommandFailedError: 72 except device_errors.CommandFailedError:
73 has_root = False 73 has_root = False
74 finally: 74 finally:
75 logging.getLogger().disabled = False 75 logging.getLogger().disabled = False
76 cmd_output = device.old_interface.RunShellCommand(cmd) 76 cmd_output = device.RunShellCommand(cmd)
77 77
78 configuration = { 78 configuration = {
79 'id': device_id, 79 'id': device_id,
80 'description': cmd_output[-1], 80 'description': cmd_output[-1],
81 'install_metadata': cmd_output[:-1], 81 'install_metadata': cmd_output[:-1],
82 } 82 }
83 return configuration, is_online, has_root 83 return configuration, is_online, has_root
84 84
85 85
86 def WriteConfigurations(configurations, path): 86 def WriteConfigurations(configurations, path):
87 # Currently we only support installing to the first device. 87 # Currently we only support installing to the first device.
88 build_utils.WriteJson(configurations[:1], path, only_if_changed=True) 88 build_utils.WriteJson(configurations[:1], path, only_if_changed=True)
89 89
90 90
91 def ReadConfigurations(path): 91 def ReadConfigurations(path):
92 return build_utils.ReadJson(path) 92 return build_utils.ReadJson(path)
93 93
94 94
95 def GetBuildDevice(configurations): 95 def GetBuildDevice(configurations):
96 assert len(configurations) == 1 96 assert len(configurations) == 1
97 return BuildDevice(configurations[0]) 97 return BuildDevice(configurations[0])
98 98
99 99
100 def GetBuildDeviceFromPath(path): 100 def GetBuildDeviceFromPath(path):
101 configurations = ReadConfigurations(path) 101 configurations = ReadConfigurations(path)
102 if len(configurations) > 0: 102 if len(configurations) > 0:
103 return GetBuildDevice(ReadConfigurations(path)) 103 return GetBuildDevice(ReadConfigurations(path))
104 return None 104 return None
105 105
OLDNEW
« no previous file with comments | « build/android/enable_asserts.py ('k') | build/android/host_heartbeat.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698