# Maintainer: Chris Gorman <chrisjohgorman@gmail.com>

_realname=cmakelang
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.6.13
pkgrel=1
pkgdesc="Source code formater for CMake listfiles (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/cheshirekow/cmake_format'
license=('GPL-3.0-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "git")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-jinja"
            "${MINGW_PACKAGE_PREFIX}-python-yaml"
            "${MINGW_PACKAGE_PREFIX}-python-argcomplete")
options=('!strip')
_commit='904c42da298f7fda932d9ac774517c20e2667fb8'
source=("${_realname}"::"git+https://github.com/cheshirekow/cmake_format.git#commit=${_commit}")
sha256sums=('db1cdeb4bc4bac7896285f3b4bfa5b0af25cd187ca7454eeacfc8bb97d700e66')

build() {
  cp -r "cmakelang" "python-build-${MSYSTEM}" && cd "python-build-${MSYSTEM}"

  # if we don't rename the jinja.py files the build process includes them and then we get an
  # error in packaging.  step 1 rename the files to not have .py extensions.
  find cmakelang -name "*.jinja.py" -exec sh -c 'mv "$1" "${1%.py}"' _ {} \;

  python cmakelang/pypi/setup.py bdist_wheel

  # step 2 move the renamed .jinja files back to having .py extensions.
  find cmakelang -name "*.jinja" -exec mv {} {}.py \;

}

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

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

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

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

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

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