Bug 1416006 - Offer to update host-utils from mach; r=jmaher
authorGeoff Brown <gbrown@mozilla.com>
Fri, 10 Nov 2017 07:03:40 -0700
changeset 444450 9a893359648926e407c658ebcfded9efd6af0c04
parent 444449 7c0d68d62e5fb5eef01972e3fa922dad3cb491ab
child 444451 aca928db9dd6a64c71cf976ce1c8060f81f523dc
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs1416006
milestone58.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1416006 - Offer to update host-utils from mach; r=jmaher
testing/mozbase/mozrunner/mozrunner/devices/android_device.py
--- a/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
+++ b/testing/mozbase/mozrunner/mozrunner/devices/android_device.py
@@ -4,16 +4,17 @@
 
 from __future__ import absolute_import, print_function
 
 import fileinput
 import glob
 import os
 import platform
 import psutil
+import re
 import shutil
 import signal
 import sys
 import telnetlib
 import time
 import urlparse
 import urllib2
 from distutils.spawn import find_executable
@@ -88,16 +89,87 @@ AVD_DICT = {
                        ['-debug',
                         'init,console,gles,memcheck,adbserver,adbclient,adb,avd_config,socket',
                         '-ranchu',
                         '-qemu', '-m', '2048'],
                        True)
 }
 
 
+def _install_host_utils(build_obj):
+    _log_info("Installing host utilities. This may take a while...")
+    installed = False
+    host_platform = _get_host_platform()
+    if host_platform:
+        path = os.path.join(MANIFEST_PATH, host_platform, 'hostutils.manifest')
+        _get_tooltool_manifest(build_obj.substs, path, EMULATOR_HOME_DIR,
+                               'releng.manifest')
+        _tooltool_fetch()
+        xre_path = glob.glob(os.path.join(EMULATOR_HOME_DIR, 'host-utils*'))
+        for path in xre_path:
+            if os.path.isdir(path) and os.path.isfile(os.path.join(path, 'xpcshell')):
+                os.environ['MOZ_HOST_BIN'] = path
+                installed = True
+                break
+        if not installed:
+            _log_warning("Unable to install host utilities.")
+    else:
+        _log_warning(
+            "Unable to install host utilities -- your platform is not supported!")
+
+
+def _maybe_update_host_utils(build_obj):
+    """
+       Compare the installed host-utils to the version name in the manifest;
+       if the installed version is older, offer to update.
+    """
+
+    # Determine existing/installed version
+    existing_path = None
+    xre_paths = glob.glob(os.path.join(EMULATOR_HOME_DIR, 'host-utils*'))
+    for path in xre_paths:
+        if os.path.isdir(path) and os.path.isfile(os.path.join(path, 'xpcshell')):
+            existing_path = path
+            break
+    if existing_path is None:
+        # if not installed, no need to upgrade (new version will be installed)
+        return
+    existing_version = os.path.basename(existing_path)
+
+    # Determine manifest version
+    manifest_version = None
+    host_platform = _get_host_platform()
+    if host_platform:
+        # Extract tooltool file name from manifest, something like:
+        #     "filename": "host-utils-58.0a1.en-US-linux-x86_64.tar.gz",
+        manifest_path = os.path.join(MANIFEST_PATH, host_platform, 'hostutils.manifest')
+        with open(manifest_path, 'r') as f:
+            for line in f.readlines():
+                m = re.search('.*\"(host-utils-.*)\"', line)
+                if m:
+                    manifest_version = m.group(1)
+                    break
+
+    # Compare, prompt, update
+    if existing_version and manifest_version:
+        manifest_version = manifest_version[:len(existing_version)]
+        if existing_version < manifest_version:
+            _log_info("Your host utilities are out of date!")
+            _log_info("You have %s installed, but %s is available" %
+                      (existing_version, manifest_version))
+            response = raw_input(
+                "Update host utilities? (Y/n) ").strip()
+            if response.lower().startswith('y') or response == '':
+                parts = os.path.split(existing_path)
+                backup_dir = '_backup-' + parts[1]
+                backup_path = os.path.join(parts[0], backup_dir)
+                shutil.move(existing_path, backup_path)
+                _install_host_utils(build_obj)
+
+
 def verify_android_device(build_obj, install=False, xre=False, debugger=False, verbose=False):
     """
        Determine if any Android device is connected via adb.
        If no device is found, prompt to start an emulator.
        If a device is found or an emulator started and 'install' is
        specified, also check whether Firefox is installed on the
        device; if not, prompt to install Firefox.
        If 'xre' is specified, also check with MOZ_HOST_BIN is set
@@ -151,52 +223,36 @@ def verify_android_device(build_obj, ins
                                     ensure_exit_code=False)
 
     if device_verified and xre:
         # Check whether MOZ_HOST_BIN has been set to a valid xre; if not,
         # prompt to install one.
         xre_path = os.environ.get('MOZ_HOST_BIN')
         err = None
         if not xre_path:
-            err = "environment variable MOZ_HOST_BIN is not set to a directory" \
+            err = "environment variable MOZ_HOST_BIN is not set to a directory " \
                   "containing host xpcshell"
         elif not os.path.isdir(xre_path):
             err = '$MOZ_HOST_BIN does not specify a directory'
         elif not os.path.isfile(os.path.join(xre_path, 'xpcshell')):
             err = '$MOZ_HOST_BIN/xpcshell does not exist'
         if err:
+            _maybe_update_host_utils(build_obj)
             xre_path = glob.glob(os.path.join(EMULATOR_HOME_DIR, 'host-utils*'))
             for path in xre_path:
                 if os.path.isdir(path) and os.path.isfile(os.path.join(path, 'xpcshell')):
                     os.environ['MOZ_HOST_BIN'] = path
                     err = None
                     break
         if err:
             _log_info("Host utilities not found: %s" % err)
             response = raw_input(
                 "Download and setup your host utilities? (Y/n) ").strip()
             if response.lower().startswith('y') or response == '':
-                _log_info("Installing host utilities. This may take a while...")
-                host_platform = _get_host_platform()
-                if host_platform:
-                    path = os.path.join(MANIFEST_PATH, host_platform, 'hostutils.manifest')
-                    _get_tooltool_manifest(build_obj.substs, path, EMULATOR_HOME_DIR,
-                                           'releng.manifest')
-                    _tooltool_fetch()
-                    xre_path = glob.glob(os.path.join(EMULATOR_HOME_DIR, 'host-utils*'))
-                    for path in xre_path:
-                        if os.path.isdir(path) and os.path.isfile(os.path.join(path, 'xpcshell')):
-                            os.environ['MOZ_HOST_BIN'] = path
-                            err = None
-                            break
-                    if err:
-                        _log_warning("Unable to install host utilities.")
-                else:
-                    _log_warning(
-                        "Unable to install host utilities -- your platform is not supported!")
+                _install_host_utils(build_obj)
 
     if debugger:
         # Optionally set up JimDB. See https://wiki.mozilla.org/Mobile/Fennec/Android/GDB.
         build_platform = _get_device_platform(build_obj.substs)
         jimdb_path = os.path.join(EMULATOR_HOME_DIR, 'jimdb-%s' % build_platform)
         jimdb_utils_path = os.path.join(jimdb_path, 'utils')
         gdb_path = os.path.join(jimdb_path, 'bin', 'gdb')
         err = None