# Maintainer: Joel Holdsworth <jholdsworth@nvidia.com>

_realname=west
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.5.0
pkgrel=1
pkgdesc="The Zephyr RTOS meta-build tool (mingw-w64)"
arch=('any')
mingw_arch=('ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'aur: python-west'
  'purl: pkg:pypi/west'
)
license=('spdx:Apache-2.0')
url='https://docs.zephyrproject.org/latest/develop/west/index.html'
msys2_repository_url='https://github.com/zephyrproject-rtos/west'
msys2_issue_tracker_url='https://github.com/zephyrproject-rtos/west/issues'
msys2_documentation_url='https://docs.zephyrproject.org/latest/develop/west/index.html'
depends=("${MINGW_PACKAGE_PREFIX}-git"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-colorama"
         "${MINGW_PACKAGE_PREFIX}-python-jsonschema"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-pykwalify"
         "${MINGW_PACKAGE_PREFIX}-python-yaml")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz"
        "0001-Use-git-version-that-matches-python-arch.patch")
sha256sums=('7088fe0e9afe0719ebee95c51c529149f7bcfc919d83a8206d35fa9c683ed0a5'
            '7be695ce5c48b437d6efffca40f26cd3aa3b295b9c8b51973267bde48cd6dd39')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -Nbp1 -i "${srcdir}/0001-Use-git-version-that-matches-python-arch.patch"
}

build() {
  cp -r "${_realname}-${pkgver}" "build-${MSYSTEM}" && cd "build-${MSYSTEM}"
  python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "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"
}
