# Maintainer: Naveen M K <naveen521kk@gmail.com>

_realname=skia-pathops
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=0.8.0.post2
pkgrel=1
pkgdesc='Python access to operations on paths using the Skia library (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url="https://github.com/fonttools/skia-pathops"
msys2_references=(
  'purl: pkg:pypi/skia-pathops'
)
license=('spdx:BSD-3-Clause')
depends=(
  "${MINGW_PACKAGE_PREFIX}-cc-libs"
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-skia"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-python-build"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools"
  "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
  "${MINGW_PACKAGE_PREFIX}-cython"
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-pkgconf"
)
options=('!strip')
source=("https://github.com/fonttools/skia-pathops/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-mingw-setup-fixes.patch")
sha256sums=('f005181bcfd269d9dbd67198199dd5e0d41604aedb29d48e45c26e881dcc77eb'
            '33fa2af008f72ae9949448ac93836d8c61ff448be2feba76b22fb69a7f11e414')

prepare() {
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}

  patch -p1 -i ../001-mingw-setup-fixes.patch
}

build() {
  cd "python-build-${MSYSTEM}"

  BUILD_SKIA_FROM_SOURCE=0 \
    python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
