[buildout]
# chromium binary is linking to libudev, that can be provided by
# component/systemd.  but current component/systemd can be built only
# with Linux kernel >= 3.7. so libudev is not included in
# LD_LIBRARY_PATH below intentionally and libudev should be installed
# in the system.

extends =
  ../coreutils/buildout.cfg
  ../cups/buildout.cfg
  ../dbus/buildout.cfg
  ../findutils/buildout.cfg
  ../fontconfig/buildout.cfg
  ../gettext/buildout.cfg
  ../glib/buildout.cfg
  ../gtk-2/buildout.cfg
  ../libexpat/buildout.cfg
  ../libffi/buildout.cfg
  ../libpng/buildout.cfg
  ../libxml2/buildout.cfg
  ../mesa/buildout.cfg
  ../nspr/buildout.cfg
  ../nss/buildout.cfg
  ../pcre/buildout.cfg
  ../sqlite3/buildout.cfg
  ../xorg/buildout.cfg
  ../zlib/buildout.cfg

parts =
  chromium

[chromium]
recipe = slapos.recipe.build
slapos_promise =
  file:chrome
  file:chrome-wrapper
  file:chrome-slapos

# How to get the revision :
# stable : https://www.googleapis.com/download/storage/v1/b/chromium-browser-continuous/o/Linux_x64%2FLAST_CHANGE?alt=media
# snapshot : https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2FLAST_CHANGE?alt=media
revision_x86 = 382014
revision_x86-64 = 382014
revision_mac = 381909

linux_x86 = https://www.googleapis.com/download/storage/v1/b/chromium-browser-continuous/o/Linux%2F${:revision_x86}%2Fchrome-linux.zip?alt=media
linux_x86-64 = https://www.googleapis.com/download/storage/v1/b/chromium-browser-continuous/o/Linux_x64%2F${:revision_x86-64}%2Fchrome-linux.zip?alt=media ef2c476b1f059e9aa026bbac1872368d
mac_x86-64 = https://www.googleapis.com/download/storage/v1/b/chromium-browser-continuous/o/Mac%2F${:revision_mac}%2Fchrome-linux.zip?alt=media

script =
  #If part directory already exist, will just throw an error.
  import os
  platform = '%%s_%%s' %% (guessOperatingSystem(), guessPlatform())
  if not self.options.get('url'): self.options['url'], self.options['md5sum'] = self.options[platform].split(' ')
  extract_dir = self.extract(self.download(self.options['url'], self.options.get('md5sum')))
  workdir = guessworkdir(extract_dir)
  self.copyTree(workdir, "%(location)s")
  wrapper_location = os.path.join("%(location)s", "chrome-slapos")
  wrapper = open(wrapper_location, 'w')
  wrapper.write("""#!/bin/sh
  export LD_LIBRARY_PATH="%(location)s"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${atk:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${cairo:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${cups:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${dbus:location}/lib/"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${dbus-glib:location}/lib/"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${fontconfig:location}/lib/"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gdk-pixbuf:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gettext:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${glib:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${gtk-2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${harfbuzz:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libX11:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXau:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXcomposite:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXcursor:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXext:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXi:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXrender:location}/lib/"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libXtst:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libexpat:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libffi:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libpng:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libpng12:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libxcb:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${libxml2:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${mesa:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${nspr:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${nss:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pango:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pcre:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pixman:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${sqlite3:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xdamage:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${xfixes:location}/lib"
  export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${zlib:location}/lib"
  exec %(location)s/chrome --disable-setuid-sandbox --disable-gpu $*""")
  wrapper.flush()
  wrapper.close()
  os.system('"${findutils:location}/bin/find" "%(location)s" -type d -exec "${coreutils:location}/bin/chmod" a+rx {} \;')
  os.system('"${findutils:location}/bin/find" "%(location)s" -type f -executable -exec "${coreutils:location}/bin/chmod" a+rx {} \;')
  os.system('"${findutils:location}/bin/find" "%(location)s" -type f -exec "${coreutils:location}/bin/chmod" a+r {} \;')
  os.chmod(wrapper_location, 0755)
