# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Jan de Groot <jgc@archlinux.org>

pkgbase=gst-python
pkgname=(gst-python gst-python2)
pkgver=1.16.0
pkgrel=1
pkgdesc="GStreamer Python binding overrides"
url="https://gstreamer.freedesktop.org/"
arch=(x86_64)
license=(LGPL)
makedepends=(python-gobject python2-gobject gst-plugins-base-libs git meson)
_commit=7f1b5fe985c2049351d0524e0f293272f63161d5  # tags/1.16.0^0
source=("git+https://gitlab.freedesktop.org/gstreamer/gst-python.git#commit=$_commit"
        "gst-common::git+https://gitlab.freedesktop.org/gstreamer/common.git")
sha256sums=('SKIP'
            'SKIP')

pkgver() {
  cd $pkgbase
  git describe --tags | sed 's/-/+/g'
}

prepare() {
  cd $pkgbase

  git submodule init
  git config --local submodule.common.url "$srcdir/gst-common"
  git submodule update
}

_build() {
  arch-meson $pkgbase build-$1 -D python=/usr/bin/$1
  ninja -C build-$1
}

_check() {
  meson test -C build-$1 --print-errorlogs
}

_package() {
  DESTDIR="$pkgdir" meson install -C build-$1
  $1 -m compileall -d /usr/lib "$pkgdir/usr/lib"
  $1 -O -m compileall -d /usr/lib "$pkgdir/usr/lib"
}

build() {
  _build python
  _build python2
}

check() {
  _check python
  _check python2
}

package_gst-python() {
  pkgdesc="${pkgdesc//Python/Python 3}"
  depends=(python-gobject gst-plugins-base-libs)

  _package python
}

package_gst-python2() {
  pkgdesc="${pkgdesc//Python/Python 2}"
  depends=(python2-gobject gst-plugins-base-libs)

  _package python2

  # Remove conflicting loader
  rm -r "$pkgdir/usr/lib/gstreamer-1.0"
}
