Bug 1527212 [wpt PR 15329] - Don't use mozdownload to download firefox, a=testonly
authorJames Graham <james@hoppipolla.co.uk>
Tue, 05 Mar 2019 11:08:54 +0000
changeset 522391 86c62ded3b663a3a847c86060b783f4f47fca913
parent 522386 2a96d8f9339f49e84789bbe3899699c5d7185406
child 522392 2d9ecd8d27b6de6213a296b8f5f9e2a0cabb6af9
push id10871
push usercbrindusan@mozilla.com
push dateMon, 18 Mar 2019 15:49:32 +0000
treeherdermozilla-beta@018abdd16060 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1527212, 15329
milestone67.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 1527212 [wpt PR 15329] - Don't use mozdownload to download firefox, a=testonly Automatic update from web-platform-tests Don't use mozdownload to download firefox Instead use the same URL that's used by mozilla.org. This hopefully reduces the problem where mozdownload tries to download a file that doesn't exist yet. Note that we are still using mozdownload for geckodriver -- wpt-commits: 803f7f06d6ca49211709dc1c4daa72393e6cb673 wpt-pr: 15329
testing/web-platform/tests/tools/wpt/browser.py
--- a/testing/web-platform/tests/tools/wpt/browser.py
+++ b/testing/web-platform/tests/tools/wpt/browser.py
@@ -1,19 +1,22 @@
 import os
 import platform
 import re
 import shutil
 import stat
 import subprocess
 import tempfile
+import urlparse
 from abc import ABCMeta, abstractmethod
 from datetime import datetime, timedelta
 from distutils.spawn import find_executable
 
+import requests
+
 from utils import call, get, untar, unzip
 
 uname = platform.uname()
 
 
 class Browser(object):
     __metaclass__ = ABCMeta
 
@@ -88,68 +91,84 @@ class Firefox(Browser):
         else:
             bits = ""
 
         return "%s%s" % (self.platform, bits)
 
     def install(self, dest=None, channel="nightly"):
         """Install Firefox."""
 
-        branch = {
-            "nightly": "mozilla-central",
-            "beta": "mozilla-beta",
-            "stable": "mozilla-stable"
-        }
-        scraper = {
-            "nightly": "daily",
-            "beta": "release",
-            "stable": "release"
-        }
-        version = {
-            "stable": "latest",
-            "beta": "latest-beta",
-            "nightly": "latest"
+        import mozinstall
+
+        product = {
+            "nightly": "firefox-nightly-latest-ssl",
+            "beta": "firefox-beta-latest-ssl",
+            "stable": "firefox-beta-latest-ssl"
         }
 
-        if channel not in branch:
+        os_builds = {
+            ("linux", "x86"): "linux",
+            ("linux", "x86_64"): "linux64",
+            ("win", "x86"): "win",
+            ("win", "x86_64"): "win64",
+            ("macos", "x86_64"): "osx",
+        }
+        os_key = (self.platform, uname[4])
+
+        if channel not in product:
             raise ValueError("Unrecognised release channel: %s" % channel)
 
-        from mozdownload import FactoryScraper
-        import mozinstall
-
-        if self.platform is None:
-            raise ValueError("Unable to construct a valid Firefox package name for current platform")
+        if os_key not in os_builds:
+            raise ValueError("Unsupported platform: %s %s" % os_key)
 
         if dest is None:
             # os.getcwd() doesn't include the venv path
             dest = os.path.join(os.getcwd(), "_venv")
 
         dest = os.path.join(dest, "browsers", channel)
 
-        scraper = FactoryScraper(scraper[channel],
-                                 branch=branch[channel],
-                                 version=version[channel],
-                                 destination=dest)
+        if not os.path.exists(dest):
+            os.makedirs(dest)
+
+        url = "https://download.mozilla.org/?product=%s&os=%s&lang=en-US" % (product[channel],
+                                                                             os_builds[os_key])
+        self.logger.info("Downloading Firefox from %s" % url)
+        resp = requests.get(url)
+
+        filename = None
 
-        self.logger.info("Downloading Firefox from %s" % scraper.url)
+        content_disposition = resp.headers.get('content-disposition')
+        if content_disposition:
+            filenames = re.findall("filename=(.+)", content_disposition)
+            if filenames:
+                filename = filenames[0]
 
-        filename = scraper.download()
+        if not filename:
+            filename = urlparse.urlsplit(resp.url).path.rsplit("/", 1)[1]
+
+        if not filename:
+            filename = "firefox.tar.bz2"
+
+        installer_path = os.path.join(dest, filename)
+
+        with open(installer_path, "w") as f:
+            f.write(resp.content)
 
         try:
-            mozinstall.install(filename, dest)
+            mozinstall.install(installer_path, dest)
         except mozinstall.mozinstall.InstallError:
             if self.platform == "macos" and os.path.exists(os.path.join(dest, self.application_name.get(channel, "Firefox Nightly.app"))):
                 # mozinstall will fail if nightly is already installed in the venv because
                 # mac installation uses shutil.copy_tree
                 mozinstall.uninstall(os.path.join(dest, self.application_name.get(channel, "Firefox Nightly.app")))
                 mozinstall.install(filename, dest)
             else:
                 raise
 
-        os.remove(filename)
+        os.remove(installer_path)
         return self.find_binary_path(dest)
 
     def find_binary_path(self,path=None, channel="nightly"):
         """Looks for the firefox binary in the virtual environment"""
 
         if path is None:
             #os.getcwd() doesn't include the venv path
             path = os.path.join(os.getcwd(), "_venv", "browsers", channel)