OLD | NEW |
---|---|
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 """Brings in Chrome Android's android_commands module, which itself is a | 4 """Brings in Chrome Android's android_commands module, which itself is a |
5 thin(ish) wrapper around adb.""" | 5 thin(ish) wrapper around adb.""" |
6 import os | 6 import os |
7 import sys | 7 import sys |
8 | 8 |
9 # This is currently a thin wrapper around Chrome Android's | 9 # This is currently a thin wrapper around Chrome Android's |
10 # build scripts, located in chrome/build/android. This file exists mainly to | 10 # build scripts, located in chrome/build/android. This file exists mainly to |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 | 112 |
113 def Pull(self, remote, local): | 113 def Pull(self, remote, local): |
114 return self._adb.Adb().Pull(remote, local) | 114 return self._adb.Adb().Pull(remote, local) |
115 | 115 |
116 def FileExistsOnDevice(self, file_name): | 116 def FileExistsOnDevice(self, file_name): |
117 return self._adb.FileExistsOnDevice(file_name) | 117 return self._adb.FileExistsOnDevice(file_name) |
118 | 118 |
119 def IsRootEnabled(self): | 119 def IsRootEnabled(self): |
120 return self._adb.IsRootEnabled() | 120 return self._adb.IsRootEnabled() |
121 | 121 |
122 def HasForwarder(adb): | 122 |
123 return adb.FileExistsOnDevice('/data/local/tmp/forwarder') | 123 def HasForwarder(adb, buildtype=None): |
124 if not buildtype: | |
125 return (HasForwarder(adb, buildtype='Release') or | |
126 HasForwarder(adb, buildtype='Debug')) | |
127 return (os.path.exists(os.path.join('out', buildtype, 'device_forwarder')) and | |
128 os.path.exists(os.path.join('out', buildtype, 'host_forwarder'))) | |
129 | |
124 | 130 |
125 def HowToInstallForwarder(): | 131 def HowToInstallForwarder(): |
126 return 'adb push out/$BUILD_TYPE/forwarder %s' % ( | 132 return 'adb push out/$BUILD_TYPE/device_forwarder %s' % ( |
127 '/data/local/tmp/forwarder') | 133 '/data/local/tmp/device_forwarder') |
128 | 134 |
129 class Forwarder(object): | 135 class Forwarder(object): |
130 def __init__(self, adb, host_port): | 136 def __init__(self, adb, host_port): |
131 assert HasForwarder(adb) | 137 assert HasForwarder(adb) |
132 | 138 |
133 port_pairs = [(host_port, host_port), ] | 139 port_pairs = [(0, host_port), ] |
tonyg
2012/10/19 00:47:19
Why the 0? I didn't need this in my patch.
bulach
2012/10/22 15:57:14
0 means dynamically allocating the device port. si
| |
134 tool = valgrind_tools.BaseTool() | 140 tool = valgrind_tools.BaseTool() |
135 | 141 |
136 self._host_port = host_port | 142 self._host_port = host_port |
137 | 143 buildtype = 'Debug' |
138 # Currently, Forwarder requires that ../out/Debug/forwarder exists, | 144 if HasForwarder(adb, 'Release'): |
139 # in case it needs to push it to the device. However, to get to here, | 145 buildtype = 'Release' |
140 # android_browser_finder has ensured that device HasForwarder, above. | 146 self._forwarder = forwarder.Forwarder( |
141 # | |
142 # Therefore, here, we just need to instantiate the forwarder, no push | |
143 # needed. | |
144 # | |
145 # To do this, we monkey patch adb.PushIfNeeded to a noop. | |
146 # | |
147 # TODO(nduca): Fix build.android.pylib.Forwarder to not need this. | |
148 real_push_if_needed = adb.Adb().PushIfNeeded | |
149 def FakePush(_, device_path): | |
150 assert adb.FileExistsOnDevice(device_path) | |
151 try: | |
152 adb.Adb().PushIfNeeded = FakePush | |
153 self._forwarder = forwarder.Forwarder( | |
154 adb.Adb(), port_pairs, | 147 adb.Adb(), port_pairs, |
155 tool, 'localhost', 'unused') | 148 tool, '127.0.0.1', buildtype) |
156 finally: | |
157 adb.Adb().PushIfNeeded = real_push_if_needed | |
158 self._device_port = self._forwarder.DevicePortForHostPort(self._host_port) | 149 self._device_port = self._forwarder.DevicePortForHostPort(self._host_port) |
159 | 150 |
160 @property | 151 @property |
161 def url(self): | 152 def url(self): |
162 assert self._forwarder | 153 assert self._forwarder |
163 return 'http://localhost:%i' % self._device_port | 154 return 'http://localhost:%i' % self._device_port |
164 | 155 |
165 def Close(self): | 156 def Close(self): |
166 if self._forwarder: | 157 if self._forwarder: |
167 self._forwarder.Close() | 158 self._forwarder.Close() |
168 self._forwarder = None | 159 self._forwarder = None |
OLD | NEW |