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

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

parts =
  chromedriver-wrapper


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

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

[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-91

[chromedriver-2.41]
<= chromedriver-download
version = 2.41
# Supports Chrome v67-69
md5sum-x86_64 = fbd8b9561575054e0e7e9cc53b680a70

[chromedriver-91]
<= chromedriver-download
version = 91.0.4472.101
# Supports Chrome v91
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
url = https://chromedriver.storage.googleapis.com/${:version}/chromedriver_${:_url}.zip
library =
  ${nss:location}/lib
  ${nspr:location}/lib
  ${libX11:location}/lib

[chromedriver-download:getattr(sys,'_multiarch',None)=='x86_64-linux-gnu']
_url = linux64
md5sum = ${:md5sum-x86_64}
