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

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

Issue 2069113002: [build/android] Switch hand-rolled 'ls' to StatDirectory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
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 10 matching lines...) Expand all
21 def GetAttachedDevices(): 21 def GetAttachedDevices():
22 return [a.GetDeviceSerial() 22 return [a.GetDeviceSerial()
23 for a in adb_wrapper.AdbWrapper.Devices()] 23 for a in adb_wrapper.AdbWrapper.Devices()]
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 assert all(isinstance(entry, dict) for entry in self.install_metadata), (
32 'Invalid BuildDevice configuration')
perezju 2016/06/15 14:54:45 This will break hard if there are old config files
31 self.device = device_utils.DeviceUtils(self.id) 33 self.device = device_utils.DeviceUtils(self.id)
32 34
33 def RunShellCommand(self, *args, **kwargs): 35 def RunShellCommand(self, *args, **kwargs):
34 return self.device.RunShellCommand(*args, **kwargs) 36 return self.device.RunShellCommand(*args, **kwargs)
35 37
36 def PushChangedFiles(self, *args, **kwargs): 38 def PushChangedFiles(self, *args, **kwargs):
37 return self.device.PushChangedFiles(*args, **kwargs) 39 return self.device.PushChangedFiles(*args, **kwargs)
38 40
39 def GetSerialNumber(self): 41 def GetSerialNumber(self):
40 return self.id 42 return self.id
41 43
42 def Install(self, *args, **kwargs): 44 def Install(self, *args, **kwargs):
43 return self.device.Install(*args, **kwargs) 45 return self.device.Install(*args, **kwargs)
44 46
45 def InstallSplitApk(self, *args, **kwargs): 47 def InstallSplitApk(self, *args, **kwargs):
46 return self.device.InstallSplitApk(*args, **kwargs) 48 return self.device.InstallSplitApk(*args, **kwargs)
47 49
48 def GetInstallMetadata(self, apk_package): 50 def GetInstallMetadata(self, apk_package, refresh=False):
49 """Gets the metadata on the device for the apk_package apk.""" 51 """Gets the metadata on the device for a given apk.
50 # Matches lines like: 52
51 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 53 Args:
52 # org.chromium.chrome.apk 54 apk_package: A string with the package name for which to get metadata.
53 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ 55 refresh: A boolean indicating whether to re-read package metadata from
54 # org.chromium.chrome-1.apk 56 the device, or use the values from the current configuration.
55 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) 57 """
56 matches = filter(apk_matcher, self.install_metadata) 58 if refresh:
57 return matches[0] if matches else None 59 self.install_metadata = self.device.StatDirectory(
60 '/data/app/', as_root=True)
61 # Matches names like: org.chromium.chrome.apk, org.chromium.chrome-1.apk
62 apk_pattern = re.compile('%s(-[0-9]*)?(.apk)?$' % re.escape(apk_package))
perezju 2016/06/15 14:54:45 Wondering when/if this is actually being run. Note
jbudorick 2016/06/15 20:47:36 Good (?) news -- apk_install.py was only used in g
63 return next(
64 (entry for entry in self.install_metadata
65 if apk_pattern.match(entry['filename'])),
66 None)
58 67
59 68
60 def GetConfigurationForDevice(device_id): 69 def GetConfigurationForDevice(device_id):
61 device = device_utils.DeviceUtils(device_id) 70 device = device_utils.DeviceUtils(device_id)
62 configuration = None 71 configuration = None
63 has_root = False 72 has_root = False
64 is_online = device.IsOnline() 73 is_online = device.IsOnline()
65 if is_online: 74 if is_online:
66 cmd = 'ls -l /data/app; getprop ro.build.description' 75 has_root = device.HasRoot()
67 cmd_output = device.RunShellCommand(cmd)
68 has_root = not 'Permission denied' in cmd_output[0]
69 if not has_root:
70 # Disable warning log messages from EnableRoot()
71 logging.getLogger().disabled = True
72 try:
73 device.EnableRoot()
74 has_root = True
75 except device_errors.CommandFailedError:
76 has_root = False
77 finally:
78 logging.getLogger().disabled = False
79 cmd_output = device.RunShellCommand(cmd)
80
81 configuration = { 76 configuration = {
82 'id': device_id, 77 'id': device_id,
83 'description': cmd_output[-1], 78 'description': device.build_description,
84 'install_metadata': cmd_output[:-1], 79 'install_metadata': device.StatDirectory('/data/app/', as_root=True),
85 } 80 }
86 return configuration, is_online, has_root 81 return configuration, is_online, has_root
87 82
88 83
89 def WriteConfigurations(configurations, path): 84 def WriteConfigurations(configurations, path):
90 # Currently we only support installing to the first device. 85 # Currently we only support installing to the first device.
91 build_utils.WriteJson(configurations[:1], path, only_if_changed=True) 86 build_utils.WriteJson(configurations[:1], path, only_if_changed=True)
92 87
93 88
94 def ReadConfigurations(path): 89 def ReadConfigurations(path):
95 return build_utils.ReadJson(path) 90 return build_utils.ReadJson(path)
96 91
97 92
98 def GetBuildDevice(configurations): 93 def GetBuildDevice(configurations):
99 assert len(configurations) == 1 94 assert len(configurations) == 1
100 return BuildDevice(configurations[0]) 95 return BuildDevice(configurations[0])
101 96
102 97
103 def GetBuildDeviceFromPath(path): 98 def GetBuildDeviceFromPath(path):
104 configurations = ReadConfigurations(path) 99 configurations = ReadConfigurations(path)
105 if len(configurations) > 0: 100 if len(configurations) > 0:
106 return GetBuildDevice(ReadConfigurations(path)) 101 return GetBuildDevice(ReadConfigurations(path))
107 return None 102 return None
108
OLDNEW
« build/android/gyp/apk_install.py ('K') | « build/android/gyp/apk_install.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698