Commit 510252d7 authored by tonyg@chromium.org's avatar tonyg@chromium.org

[Telemetry] Make prebuilt binary installation a little more robust.

BUG=

Review URL: https://codereview.chromium.org/74283003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235816 0039d316-1c4b-4281-b951-d872f2087c98
parent f5c85ae3
9fcd00e2a167d957928b2311d0deef12
f90849b2d19138da35fcf030ef4b89c4a3960eae
\ No newline at end of file
......@@ -170,17 +170,29 @@ class AdbCommands(object):
def GoHome(self):
return self._adb.GoHome()
def RestartAdbdOnDevice(self):
return self._adb.RestartAdbdOnDevice()
def SetupPrebuiltTools(device):
def GetBuildTypeOfPath(path):
if not path:
return None
for build_dir, build_type in util.GetBuildDirectories():
if os.path.join(build_dir, build_type) in path:
return build_type
return None
def SetupPrebuiltTools(adb):
# TODO(bulach): build the host tools for mac, and the targets for x86/mips.
# Prebuilt tools from r226197.
has_prebuilt = sys.platform.startswith('linux')
if has_prebuilt:
adb = AdbCommands(device)
abi = adb.RunShellCommand('getprop ro.product.cpu.abi')
has_prebuilt = abi and abi[0].startswith('armeabi')
if not has_prebuilt:
logging.error('Prebuilt tools only available for ARM.')
logging.error(
'Prebuilt android tools only available for Linux host and ARM device.')
return False
prebuilt_tools = [
......@@ -190,29 +202,30 @@ def SetupPrebuiltTools(device):
'md5sum_bin_host',
'purge_ashmem',
]
build_type = None
for t in prebuilt_tools:
src = os.path.basename(t)
android_prebuilt_profiler_helper.GetIfChanged(src)
bin_path = util.FindSupportBinary(t)
if not build_type:
build_type = GetBuildTypeOfPath(bin_path) or 'Release'
constants.SetBuildType(build_type)
dest = os.path.join(constants.GetOutDirectory(), t)
if not os.path.exists(dest):
if not bin_path:
logging.warning('Setting up prebuilt %s', dest)
if not os.path.exists(os.path.dirname(dest)):
os.makedirs(os.path.dirname(dest))
shutil.copyfile(android_prebuilt_profiler_helper.GetHostPath(src), dest)
prebuilt_path = android_prebuilt_profiler_helper.GetHostPath(src)
if not os.path.exists(prebuilt_path):
raise NotImplementedError("""
%s must be checked into cloud storage.
Instructions:
http://www.chromium.org/developers/telemetry/upload_to_cloud_storage
""" % t)
shutil.copyfile(prebuilt_path, dest)
os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
return True
def HasForwarder(buildtype=None):
if not buildtype:
return (HasForwarder(buildtype='Release') or
HasForwarder(buildtype='Debug'))
device_forwarder = os.path.join(
constants.GetOutDirectory(build_type=buildtype),
'forwarder_dist', 'device_forwarder')
host_forwarder = os.path.join(
constants.GetOutDirectory(build_type=buildtype), 'host_forwarder')
return os.path.exists(device_forwarder) and os.path.exists(host_forwarder)
class Forwarder(object):
def __init__(self, adb, *port_pairs):
......@@ -223,12 +236,6 @@ class Forwarder(object):
for port_pair in port_pairs]
self._port_pairs = new_port_pairs
if HasForwarder('Release'):
constants.SetBuildType('Release')
elif HasForwarder('Debug'):
constants.SetBuildType('Debug')
else:
raise Exception('Build forwarder2')
forwarder.Forwarder.Map(new_port_pairs, self._adb)
@property
......
......@@ -203,13 +203,8 @@ def FindAllAvailableBrowsers(finder_options, logging=real_logging):
# report that the device is offline. Our working theory is that killing
# the process and allowing it to be automatically relaunched will allow us
# to run for longer before it hangs.
if not finder_options.keep_test_server_ports:
# This would break forwarder connections, so we cannot do this if
# instructed to keep server ports open.
logging.info('Killing adbd on device')
adb.KillAll('adbd')
logging.info('Waiting for adbd to restart')
adb.Adb().Adb().SendCommand('wait-for-device')
if not os.environ.get('BUILDBOT_BUILDERNAME'):
adb.RestartAdbdOnDevice()
packages = adb.RunShellCommand('pm list packages')
possible_browsers = []
......@@ -225,16 +220,13 @@ def FindAllAvailableBrowsers(finder_options, logging=real_logging):
if 'package:' + package in packages or b.HaveLocalAPK():
possible_browsers.append(b)
# See if the "forwarder" is installed -- we need this to host content locally
# but make it accessible to the device.
if (len(possible_browsers) and not finder_options.android_rndis and
not adb_commands.HasForwarder()):
logging.warn('telemetry detected an android device. However,')
logging.warn('Chrome\'s port-forwarder app is not available.')
logging.warn('Falling back to prebuilt binaries, but to build locally: ')
logging.warn(' ninja -C out/Release android_tools')
logging.warn('')
logging.warn('')
if not adb_commands.SetupPrebuiltTools(device):
if possible_browsers:
installed_prebuilt_tools = adb_commands.SetupPrebuiltTools(adb)
if not installed_prebuilt_tools:
logging.error(
'Android device detected, however prebuilt android tools could not '
'be used. To run on Android you must build them first:\n'
' $ ninja -C out/Release android_tools')
return []
return possible_browsers
......@@ -67,6 +67,9 @@ class AdbCommandsModuleStub(object):
def IsRootEnabled(self):
return self.is_root_enabled
def RestartAdbdOnDevice(self):
pass
def __init__(self):
self.attached_devices = []
self.shell_command_handlers = {}
......@@ -86,6 +89,9 @@ class AdbCommandsModuleStub(object):
def HasForwarder(_=None):
return True
def SetupPrebuiltTools(self, _):
return True
class CloudStorageModuleStub(object):
INTERNAL_BUCKET = None
......@@ -227,7 +233,7 @@ class SubprocessModuleStub(object):
self.PIPE = None
def call(self, *args, **kwargs):
raise NotImplementedError()
pass
class SysModuleStub(object):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment