Changeset 219853 in webkit


Ignore:
Timestamp:
Jul 24, 2017 6:42:03 PM (7 years ago)
Author:
commit-queue@webkit.org
Message:

Add functions to autoinstaller needed for Benchmark Runner script
https://bugs.webkit.org/show_bug.cgi?id=174331

Patch by Matthew Stewart <matthew_r_stewart@apple.com> on 2017-07-24
Reviewed by Dean Johnson, Dewei Zhu, Stephanie Lewis.

Adds autoinstaller functions to install selenium and webdriver binaries
which will be used by the browser driver part of Benchmark Runner.

  • Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py:

(BrowserDriver.restore_env):
(BrowserDriver):
(BrowserDriver.get_webdriver_binary_path):

  • Scripts/webkitpy/benchmark_runner/browser_driver/linux_chrome_driver.py:

(LinuxChromeDriver.launch_driver):

  • Scripts/webkitpy/benchmark_runner/browser_driver/linux_firefox_driver.py:

(LinuxFirefoxDriver.launch_driver):

  • Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py:

(OSXChromeDriver.launch_driver):
(OSXChromeCanaryDriver.launch_driver):

  • Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py:

(OSXFirefoxDriver.launch_driver):
(OSXFirefoxNightlyDriver.launch_driver):

  • Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py:
  • Scripts/webkitpy/benchmark_runner/utils.py:

(get_driver_binary_path):

  • Scripts/webkitpy/common/system/autoinstall.py:

(AutoInstaller._unzip):

  • Scripts/webkitpy/thirdparty/init.py:

(AutoinstallImportHook.find_module):
(AutoinstallImportHook._install_selenium):
(AutoinstallImportHook):
(AutoinstallImportHook._install_chromedriver):
(AutoinstallImportHook._install_geckodriver):
(AutoinstallImportHook.get_latest_pypi_url):
(AutoinstallImportHook.install_binary):
(autoinstall_everything):
(get_driver_filename):
(get_os_info):

Location:
trunk/Tools
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r219850 r219853  
     12017-07-24  Matthew Stewart  <matthew_r_stewart@apple.com>
     2
     3        Add functions to autoinstaller needed for Benchmark Runner script
     4        https://bugs.webkit.org/show_bug.cgi?id=174331
     5
     6        Reviewed by Dean Johnson, Dewei Zhu, Stephanie Lewis.
     7
     8        Adds autoinstaller functions to install selenium and webdriver binaries
     9        which will be used by the browser driver part of Benchmark Runner.
     10
     11        * Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py:
     12        (BrowserDriver.restore_env):
     13        (BrowserDriver):
     14        (BrowserDriver.get_webdriver_binary_path):
     15        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_chrome_driver.py:
     16        (LinuxChromeDriver.launch_driver):
     17        * Scripts/webkitpy/benchmark_runner/browser_driver/linux_firefox_driver.py:
     18        (LinuxFirefoxDriver.launch_driver):
     19        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py:
     20        (OSXChromeDriver.launch_driver):
     21        (OSXChromeCanaryDriver.launch_driver):
     22        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py:
     23        (OSXFirefoxDriver.launch_driver):
     24        (OSXFirefoxNightlyDriver.launch_driver):
     25        * Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py:
     26        * Scripts/webkitpy/benchmark_runner/utils.py:
     27        (get_driver_binary_path):
     28        * Scripts/webkitpy/common/system/autoinstall.py:
     29        (AutoInstaller._unzip):
     30        * Scripts/webkitpy/thirdparty/__init__.py:
     31        (AutoinstallImportHook.find_module):
     32        (AutoinstallImportHook._install_selenium):
     33        (AutoinstallImportHook):
     34        (AutoinstallImportHook._install_chromedriver):
     35        (AutoinstallImportHook._install_geckodriver):
     36        (AutoinstallImportHook.get_latest_pypi_url):
     37        (AutoinstallImportHook.install_binary):
     38        (autoinstall_everything):
     39        (get_driver_filename):
     40        (get_os_info):
     41
    1422017-07-24  Matthew Stewart  <matthew_r_stewart@apple.com>
    243
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/browser_driver.py

    r219850 r219853  
    22
    33from abc import ABCMeta, abstractmethod
     4from webkitpy.benchmark_runner.utils import get_driver_binary_path
    45
    56
     
    3334    def restore_env(self):
    3435        pass
     36
     37    @property
     38    def webdriver_binary_path(self):
     39        return get_driver_binary_path(self.browser_name)
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_chrome_driver.py

    r219850 r219853  
    5050            binary_path = os.path.join(browser_build_path, 'chromium-browser')
    5151            options.binary_location = binary_path
    52         driver = webdriver.Chrome(chrome_options=options)
     52        driver_executable = self.webdriver_binary_path
     53        driver = webdriver.Chrome(chrome_options=options, executable_path=driver_executable)
    5354        super(LinuxChromeDriver, self).launch_webdriver(url, driver)
    5455        return driver
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/linux_firefox_driver.py

    r219850 r219853  
    4848            binary_path = os.path.join(browser_build_path, 'firefox-bin')
    4949            options.binary_location = binary_path
    50         driver = webdriver.Firefox(firefox_options=options)
     50        driver_executable = self.webdriver_binary_path
     51        driver = webdriver.Firefox(firefox_options=options, executable_path=driver_executable)
    5152        super(LinuxFirefoxDriver, self).launch_webdriver(url, driver)
    5253        return driver
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_chrome_driver.py

    r219850 r219853  
    33import logging
    44import os
    5 import subprocess
    6 import time
    75
    86from osx_browser_driver import OSXBrowserDriver
     
    3533            binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
    3634            chrome_options.binary_location = binary_path
    37         driver = webdriver.Chrome(chrome_options=chrome_options)
     35        driver_executable = self.webdriver_binary_path
     36        driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
    3837        self._launch_webdriver(url=url, driver=driver)
    3938        return driver
     
    5554        binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
    5655        chrome_options.binary_location = binary_path
    57         driver = webdriver.Chrome(chrome_options=chrome_options)
     56        driver_executable = self.webdriver_binary_path
     57        driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=driver_executable)
    5858        self._launch_webdriver(url=url, driver=driver)
    5959        return driver
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_firefox_driver.py

    r219850 r219853  
    33import logging
    44import os
    5 import subprocess
    6 import time
    75
    86from osx_browser_driver import OSXBrowserDriver
     
    3129            binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
    3230            firefox_options.binary_location = binary_path
    33         driver = webdriver.Firefox(firefox_options=firefox_options)
     31        driver_executable = self.webdriver_binary_path
     32        driver = webdriver.Firefox(firefox_options=firefox_options, executable_path=driver_executable)
    3433        self._launch_webdriver(url=url, driver=driver)
    3534        return driver
     
    5150        binary_path = os.path.join(app_path, "Contents/MacOS", self.process_name)
    5251        firefox_options.binary_location = binary_path
    53         driver = webdriver.Firefox(firefox_options=firefox_options)
     52        driver_executable = self.webdriver_binary_path
     53        driver = webdriver.Firefox(firefox_options=firefox_options, executable_path=driver_executable)
    5454        self._launch_webdriver(url=url, driver=driver)
    5555        return driver
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/browser_driver/osx_safari_driver.py

    r219850 r219853  
    33import logging
    44import os
    5 import re
    65import subprocess
    76import time
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/utils.py

    r209090 r219853  
    88import shutil
    99import sys
     10
     11from webkitpy.common.memoized import memoized
    1012
    1113
     
    4547        _log.info("Error removing %s: %s" % (path, error))
    4648        pass
     49
     50
     51@memoized
     52def get_driver_binary_path(browser_name):
     53    if browser_name.startswith('chrome'):
     54        import webkitpy.thirdparty.autoinstalled.chromedriver
     55        driver_init_file = webkitpy.thirdparty.autoinstalled.chromedriver.__file__
     56        driver_executable = os.path.join(os.path.dirname(os.path.realpath(driver_init_file)), 'chromedriver')
     57        return driver_executable
     58    elif browser_name.startswith('firefox'):
     59        import webkitpy.thirdparty.autoinstalled.geckodriver
     60        driver_init_file = webkitpy.thirdparty.autoinstalled.geckodriver.__file__
     61        driver_executable = os.path.join(os.path.dirname(os.path.realpath(driver_init_file)), 'geckodriver')
     62        return driver_executable
    4763
    4864
  • trunk/Tools/Scripts/webkitpy/common/system/autoinstall.py

    r212852 r219853  
    276276
    277277        try:
    278             self._extract_all(zip_file, scratch_dir)
     278            self._extract_all(zip_file, target_path)
    279279        finally:
    280280            zip_file.close()
  • trunk/Tools/Scripts/webkitpy/thirdparty/__init__.py

    r209216 r219853  
    2727
    2828import codecs
     29import json
    2930import os
     31import re
    3032import sys
    31 
     33import urllib2
     34
     35from collections import namedtuple
     36from distutils import spawn
    3237from webkitpy.common.system.autoinstall import AutoInstaller
    3338from webkitpy.common.system.filesystem import FileSystem
     
    3540_THIRDPARTY_DIR = os.path.dirname(__file__)
    3641_AUTOINSTALLED_DIR = os.path.join(_THIRDPARTY_DIR, "autoinstalled")
     42
     43CHROME_DRIVER_URL = "http://chromedriver.storage.googleapis.com/"
     44FIREFOX_RELEASES_URL = "https://api.github.com/repos/mozilla/geckodriver/releases"
    3745
    3846# Putting the autoinstall code into webkitpy/thirdparty/__init__.py
     
    4755#
    4856#     webkitpy/thirdparty/autoinstalled
     57
    4958fs = FileSystem()
    5059fs.maybe_make_directory(_AUTOINSTALLED_DIR)
     
    92101        elif '.twisted_15_5_0' in fullname:
    93102            self._install_twisted_15_5_0()
     103        elif '.selenium' in fullname:
     104            self._install_selenium()
     105        elif '.chromedriver' in fullname:
     106            self._install_chromedriver()
     107        elif '.geckodriver' in fullname:
     108            self._install_geckodriver()
    94109
    95110    def _install_mechanize(self):
     
    152167        installer.install(url="https://pypi.python.org/packages/source/z/zope.interface/zope.interface-4.1.3.tar.gz#md5=9ae3d24c0c7415deb249dd1a132f0f79", url_subpath="zope.interface-4.1.3/src/zope")
    153168
     169    def _install_selenium(self):
     170        self._ensure_autoinstalled_dir_is_in_sys_path()
     171        url, url_subpath = self.get_latest_pypi_url('selenium')
     172        self._install(url=url, url_subpath=url_subpath)
     173
     174    def _install_chromedriver(self):
     175        filename_postfix = get_driver_filename().chrome
     176        if filename_postfix != "unsupported":
     177            version = urllib2.urlopen(CHROME_DRIVER_URL + 'LATEST_RELEASE').read().strip()
     178            full_chrome_url = "{base_url}{version}/chromedriver_{os}.zip".format(base_url=CHROME_DRIVER_URL, version=version, os=filename_postfix)
     179            self.install_binary(full_chrome_url, 'chromedriver')
     180
     181    def _install_geckodriver(self):
     182        filename_postfix = get_driver_filename().firefox
     183        if filename_postfix != "unsupported":
     184            firefox_releases_blob = urllib2.urlopen(FIREFOX_RELEASES_URL)
     185            firefox_releases_line_separated = json.dumps(json.load(firefox_releases_blob), indent=0).strip()
     186            all_firefox_release_urls = "\n".join(re.findall(r'.*browser_download_url.*', firefox_releases_line_separated))
     187            full_firefox_url = re.findall(r'.*%s.*' % filename_postfix, all_firefox_release_urls)[0].split('"')[3]
     188            self.install_binary(full_firefox_url, 'geckodriver')
     189
    154190    def _install(self, url, url_subpath=None, target_name=None):
    155191        installer = AutoInstaller(target_dir=_AUTOINSTALLED_DIR)
    156192        installer.install(url=url, url_subpath=url_subpath, target_name=target_name)
     193
     194    def get_latest_pypi_url(self, package_name, url_subpath_format='{name}-{version}/{lname}'):
     195        json_url = "https://pypi.python.org/pypi/%s/json" % package_name
     196        response = urllib2.urlopen(json_url)
     197        data = json.load(response)
     198        url = data['urls'][1]['url']
     199        subpath = url_subpath_format.format(name=package_name, version=data['info']['version'], lname=package_name.lower())
     200        return (url, subpath)
     201
     202    def install_binary(self, url, name):
     203        self._install(url=url, target_name=name)
     204        directory = os.path.join(_AUTOINSTALLED_DIR, name)
     205        os.chmod(os.path.join(directory, name), 0755)
     206        open(os.path.join(directory, '__init__.py'), 'w+').close()
    157207
    158208
     
    165215    for method in install_methods:
    166216        getattr(_hook, method)()
     217
     218def get_driver_filename():
     219    os_name, os_type = get_os_info()
     220    chrome_os, filefox_os = 'unsupported', 'unsupported'
     221    if os_name == 'Linux' and os_type == '64':
     222        chrome_os, firefox_os = 'linux64', 'linux64'
     223    elif os_name == 'Linux':
     224        chrome_os, firefox_os = 'linux32', 'linux32'
     225    elif os_name == 'Darwin':
     226        chrome_os, firefox_os = 'mac64', 'macos'
     227    DriverFilenameForBrowser = namedtuple('DriverFilenameForBrowser', ['chrome', 'firefox'])
     228    return DriverFilenameForBrowser(chrome_os, firefox_os)
     229
     230def get_os_info():
     231    import platform
     232    os_name = platform.system()
     233    os_type = platform.machine()[-2:]
     234    return (os_name, os_type)
Note: See TracChangeset for help on using the changeset viewer.