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

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

parts =
  chromedriver-wrapper



[chromedriver-wrapper-2.41]
<= chromedriver-wrapper
wrapper-name = chromedriver-2.41
part = ${chromedriver-2.41:location}

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

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


[chromedriver]
<= chromedriver-2.41

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


[chromedriver-download]
# Installs chromedriver ${version}.
# This chromedriver is not usable directly, it needs a wrapper.
version =
md5sum-x86_64 =

recipe = slapos.recipe.build
x86-64 = https://chromedriver.storage.googleapis.com/${:version}/chromedriver_linux64.zip ${:md5sum-x86_64}
library =
  ${nss:location}/lib
  ${nspr:location}/lib
path =
install =
  import os, shutil
  extract_dir = self.extract(self.download(*options[guessPlatform()].split()))
  os.mkdir(location)
  shutil.copy(os.path.join(extract_dir, 'chromedriver'), location)

