Skip to content

Commit

Permalink
Add support for just downloading browser
Browse files Browse the repository at this point in the history
  • Loading branch information
jgraham committed Nov 27, 2019
1 parent 4469c5c commit b980ca9
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 25 deletions.
107 changes: 89 additions & 18 deletions tools/wpt/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ class Browser(object):
def __init__(self, logger):
self.logger = logger

@abstractmethod
def download(self, dest=None, channel=None):
"""Download a package or installer for the browser"""
return NotImplemented

@abstractmethod
def install(self, dest=None):
"""Install the browser."""
Expand Down Expand Up @@ -116,11 +121,19 @@ def platform_string_geckodriver(self):

return "%s%s" % (self.platform, bits)

def install(self, dest=None, channel="nightly"):
"""Install Firefox."""
def _get_dest(self, dest, channel):
if dest is None:
# os.getcwd() doesn't include the venv path
dest = os.path.join(os.getcwd(), "_venv")

import mozinstall
dest = os.path.join(dest, "browsers", channel)

if not os.path.exists(dest):
os.makedirs(dest)

return dest

def download(self, dest=None, channel="nightly"):
product = {
"nightly": "firefox-nightly-latest-ssl",
"beta": "firefox-beta-latest-ssl",
Expand All @@ -136,21 +149,15 @@ def install(self, dest=None, channel="nightly"):
}
os_key = (self.platform, uname[4])

if dest is None:
dest = self._get_dest(None, channel)

if channel not in product:
raise ValueError("Unrecognised release channel: %s" % channel)

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)

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)
Expand All @@ -175,6 +182,18 @@ def install(self, dest=None, channel="nightly"):
with open(installer_path, "wb") as f:
f.write(resp.content)

return installer_path

def install(self, dest=None, channel="nightly"):
"""Install Firefox."""
import mozinstall

dest = self._get_dest(dest, channel)

filename = os.path.basename(dest)

installer_path = self.download(dest, channel)

try:
mozinstall.install(installer_path, dest)
except mozinstall.mozinstall.InstallError:
Expand Down Expand Up @@ -422,7 +441,7 @@ class FirefoxAndroid(Browser):
product = "firefox_android"
requirements = "requirements_firefox.txt"

def install(self, dest=None, channel=None):
def download(self, dest=None, channel=None):
if dest is None:
dest = os.pwd

Expand Down Expand Up @@ -452,6 +471,9 @@ def install(self, dest=None, channel=None):

return apk_path

def install(self, dest=None, channel=None):
return self.download(dest, channel)

def install_prefs(self, binary, dest=None, channel=None):
fx_browser = Firefox(self.logger)
return fx_browser.install_prefs(binary, dest, channel)
Expand All @@ -478,6 +500,9 @@ class Chrome(Browser):
product = "chrome"
requirements = "requirements_chrome.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -633,6 +658,9 @@ def __init__(self, logger):
super(ChromeAndroidBase, self).__init__(logger)
self.device_serial = None

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -724,6 +752,9 @@ class ChromeiOS(Browser):
product = "chrome_ios"
requirements = "requirements_chrome_ios.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -757,6 +788,9 @@ def binary(self):
self.logger.warning("Unable to find the browser binary.")
return None

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -826,6 +860,9 @@ class EdgeChromium(Browser):
edgedriver_name = "msedgedriver"
requirements = "requirements_edge_chromium.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -922,6 +959,9 @@ class Edge(Browser):
product = "edge"
requirements = "requirements_edge.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -953,6 +993,9 @@ class InternetExplorer(Browser):
product = "ie"
requirements = "requirements_ie.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand All @@ -978,6 +1021,9 @@ class Safari(Browser):
product = "safari"
requirements = "requirements_safari.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -1037,17 +1083,33 @@ def platform_components(self):

return (platform, extension, decompress)

def install(self, dest=None, channel="nightly"):
"""Install latest Browser Engine."""
def _get(self, channel="nightly"):
if channel != "nightly":
raise ValueError("Only nightly versions of Servo are available")

platform, extension, _ = self.platform_components()
url = "https://download.servo.org/nightly/%s/servo-latest%s" % (platform, extension)
return get(url)

def download(self, dest=None, channel="nightly"):
if dest is None:
dest = os.pwd

platform, extension, decompress = self.platform_components()
url = "https://download.servo.org/nightly/%s/servo-latest%s" % (platform, extension)
resp = self._get(dest, channel)
_, extension, _ = self.platform_components()

with open(os.path.join(dest, "servo-latest%s" % (extension,)), "w") as f:
f.write(resp.content)

def install(self, dest=None, channel="nightly"):
"""Install latest Browser Engine."""
if dest is None:
dest = os.pwd

_, _, decompress = self.platform_components()

decompress(get(url).raw, dest=dest)
resp = self._get(dest, channel)
decompress(resp.raw, dest=dest)
path = find_executable("servo", os.path.join(dest, "servo"))
st = os.stat(path)
os.chmod(path, st.st_mode | stat.S_IEXEC)
Expand Down Expand Up @@ -1083,6 +1145,9 @@ class Sauce(Browser):
product = "sauce"
requirements = "requirements_sauce.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand All @@ -1105,6 +1170,9 @@ class WebKit(Browser):
product = "webkit"
requirements = "requirements_webkit.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down Expand Up @@ -1168,6 +1236,9 @@ class Epiphany(Browser):
product = "epiphany"
requirements = "requirements_epiphany.txt"

def download(self, dest=None, channel=None):
raise NotImplementedError

def install(self, dest=None, channel=None):
raise NotImplementedError

Expand Down
17 changes: 10 additions & 7 deletions tools/wpt/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def get_parser():
'the latest available development release. For WebDriver installs, '
'we attempt to select an appropriate, compatible, version for the '
'latest browser release on the selected channel.')
parser.add_argument('--download-only', action="store_true",
help="Download the selected component but don't install it")
parser.add_argument('-d', '--destination',
help='filesystem directory to place the component')
return parser
Expand Down Expand Up @@ -73,21 +75,22 @@ def run(venv, **kwargs):
raise argparse.ArgumentError(None,
"No --destination argument, and no default for the environment")

install(browser, kwargs["component"], destination, channel)
install(browser, kwargs["component"], destination, channel,
download_only=kwargs["download_only"])


def install(name, component, destination, channel="nightly", logger=None):
def install(name, component, destination, channel="nightly", logger=None, download_only=False):
if logger is None:
import logging
logger = logging.getLogger("install")

if component == 'webdriver':
method = 'install_webdriver'
else:
method = 'install'
prefix = "download" if download_only else "install"
suffix = "_webdriver" if component == 'webdriver' else ""

method = prefix + suffix

subclass = getattr(browser, name.title())
sys.stdout.write('Now installing %s %s...\n' % (name, component))
path = getattr(subclass(logger), method)(dest=destination, channel=channel)
if path:
sys.stdout.write('Binary installed as %s\n' % (path,))
sys.stdout.write('Binary %s as %s\n' % ("downloaded" if download_only else "installed", path,))

0 comments on commit b980ca9

Please sign in to comment.