# Chromium binary build, from "Downloading old builds of Chrome / Chromium" of
# https://www.chromium.org/getting-involved/download-chromium
# Currently, only Linux_x64 is supported.


[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 =
  ../alsa/buildout.cfg
  ../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
  ../gtk-3/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-wrapper


[chromium-wrapper]
# Install a chromium wrapper named ${:wrapper-name} in buildout's bin-directory,
# wrapping chromium installed in ${:part}
# This [chromium-wrapper] installs the default chromium with name `chromium` and
# can also be used as a macro to install under a different name.
wrapper-name = chromium
part = ${chromium:location}

recipe = slapos.recipe.build
location = ${buildout:bin-directory}/${:wrapper-name}
install =
  import os
  chromium = options['part']
  part = self.buildout[os.path.basename(chromium)]
  with open(location, 'w') as f:
    f.write("""#!/bin/sh -e
  cd {}
  # this also needs a $FONTCONFIG_FILE set, otherwise system fonts will be used and if
  # no system fonts are available, chrome will refuse to start with this error:
  # FATAL:platform_font_linux.cc(83)] Check failed: InitDefaultFont(). Could not find the default font
  export LD_LIBRARY_PATH=$PWD:{}
  export PATH={}:$PATH
  exec ./chrome --disable-setuid-sandbox --no-sandbox --disable-gpu $@
  """.format(
    chromium,
    ':'.join(part['library'].split()),
    ':'.join(part['path'].split()),
  ))
    os.fchmod(f.fileno(), 0o755)

[chromium-wrapper-91]
<= chromium-wrapper
wrapper-name = chromium-91
part = ${chromium-91:location}

[chromium-wrapper-69]
<= chromium-wrapper
wrapper-name = chromium-69
part = ${chromium-69:location}


[chromium]
<= chromium-91

[chromium-91]
<= chromium-download
version = 91.0.4472.114

revision_x86-64 = 870763
md5sum-x86_64 = 74eab41580469c2b8117cf396db823cb
generation-x86_64 = 1617926496067901


[chromium-69]
<= chromium-download
version = 69.0.3497.0

revision_x86-64 = 576753
md5sum-x86_64 = 08ac27fd40ace4ca8dfbd1db403deccb
generation-x86_64 = 1532051976706023


[chromium-download]
# macro to download a binary build of chromium and generate a
# wrapper as chrome-slapos in the part directory

# the full version tag
version =

# needs the following URL parts:
# revision is from the "base position"
revision_x86-64 =
# generation is in the final download URL
generation-x86_64 =
# this is the md5sum of the downloaded archive
md5sum-x86_64 =


recipe = slapos.recipe.build

x86_64-linux-gnu = https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F${:revision_x86-64}%2Fchrome-linux.zip?generation=${:generation-x86_64}&alt=media ${:md5sum-x86_64}


library =
  ${atk:location}/lib
  ${at-spi2-atk:location}/lib
  ${at-spi2-core:location}/lib
  ${alsa:location}/lib
  ${cairo:location}/lib
  ${cups:location}/lib
  ${cups:location}/lib64
  ${dbus:location}/lib/
  ${dbus-glib:location}/lib/
  ${fontconfig:location}/lib/
  ${gdk-pixbuf:location}/lib
  ${gettext:location}/lib
  ${glib:location}/lib
  ${gtk-3:location}/lib
  ${harfbuzz:location}/lib
  ${libX11:location}/lib
  ${libXau:location}/lib
  ${libXcomposite:location}/lib
  ${libXcursor:location}/lib
  ${libXext:location}/lib
  ${libXi:location}/lib
  ${libXrender:location}/lib/
  ${libXtst:location}/lib
  ${libXScrnSaver:location}/lib
  ${libXrandr:location}/lib
  ${libdrm:location}/lib
  ${libexpat:location}/lib
  ${libffi:location}/lib
  ${libpng:location}/lib
  ${libpng12:location}/lib
  ${libxcb:location}/lib
  ${libxkbcommon:location}/lib
  ${libxshmfence:location}/lib
  ${libxml2:location}/lib
  ${mesa:location}/lib
  ${nspr:location}/lib
  ${nss:location}/lib
  ${pango:location}/lib
  ${pcre:location}/lib
  ${pixman:location}/lib
  ${sqlite3:location}/lib
  ${xdamage:location}/lib
  ${xfixes:location}/lib
  ${zlib:location}/lib
path =
  ${fontconfig:location}/bin
install =
  url, md5sum = self.options[multiarch()].split()
  extract_dir = self.extract(self.download(url, md5sum))
  self.copyTree(guessworkdir(extract_dir), location)
  # XXX adjust some permissions
  import os
  os.system("'${findutils:location}/bin/find' '%s' -type d -exec '${coreutils:location}/bin/chmod' a+rx {} \\;" % location)
  os.system("'${findutils:location}/bin/find' '%s' -type f -executable -exec '${coreutils:location}/bin/chmod' a+rx {} \\;" % location)
  os.system("'${findutils:location}/bin/find' '%s' -type f -exec '${coreutils:location}/bin/chmod' a+r {} \\;" % location)
