# ChromeDriver - Webdriver for Chrome
# https://chromedriver.chromium.org/
# This is a binary download with wrapper scripts.

[buildout]
extends =
  ../chromium/buildout.cfg
  ../glib/buildout.cfg
  ../nspr/buildout.cfg
  ../nss/buildout.cfg
  ../pcre2/buildout.cfg
  ../xorg/buildout.cfg

parts =
  chromedriver-wrapper


[chromedriver-wrapper-120]
<= chromedriver-wrapper
part = chromedriver-120

[chromedriver-wrapper-91]
<= chromedriver-wrapper
part = chromedriver-91


[chromedriver-wrapper]
# generate a wrapper named ${:wrapper-name} setting $LD_LIBRARY_PATH
# to run chromedriver installed from ${:part}
part = chromedriver

recipe = slapos.recipe.build
location = ${buildout:bin-directory}/${:part}
init =
  self.buildout[options['part']]
install =
  import os
  part = self.buildout[options['part']]
  with open(location, 'w') as f:
    f.write("""#!/bin/sh -e
  export LD_LIBRARY_PATH=%s
  exec %s/chromedriver "$@"
  """ % (':'.join(part['library'].split()), part['location']))
    os.fchmod(f.fileno(), 0o755)


[chromedriver]
<= chromedriver-120

[chromedriver-120]
<= chromedriver-download
version = 120.0.6099.109
revision-x86_64 = 1217362
generation-x86_64 = 1698717838856458
md5sum-x86_64 = 5cb8d386f01052cfc58c80ec63477db0

[chromedriver-91]
<= chromedriver-download
url = https://chromedriver.storage.googleapis.com/${:version}/chromedriver_linux64.zip
version = 91.0.4472.101
md5sum-x86_64 = cc43ba0babbfff7f22b48165ec8e8c81

[chromedriver-download]
# Installs chromedriver ${version}.
# This chromedriver is not usable directly, it needs a wrapper.
recipe = slapos.recipe.build:download-unpacked

library =
  ${glib:location}/lib
  ${libX11:location}/lib
  ${libXau:location}/lib
  ${libxcb:location}/lib
  ${libXdmcp:location}/lib
  ${nspr:location}/lib
  ${nss:location}/lib
  ${pcre2:location}/lib

[chromedriver-download:getattr(sys,'_multiarch',None)=='x86_64-linux-gnu']
url = https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${:revision-x86_64}%2Fchromedriver_linux64.zip?generation=${:generation-x86_64}&alt=media
md5sum = ${:md5sum-x86_64}
