# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>

_realname=watchexec
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.3.2
pkgrel=2
msys2_repository_url="https://github.com/watchexec/watchexec/"
url="https://watchexec.github.io/"
pkgdesc="Executes commands in response to file modifications (mingw-w64)"
license=('spdx:Apache-2.0')
msys2_references=(
  'archlinux: watchexec'
  'purl: pkg:cargo/watchexec-cli'
)
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
options=('!strip')
source=("https://github.com/watchexec/watchexec/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('52201822ab00bfaf6757f953f667870b3aada52f887813e94b4f322f239ff8fb')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "${RUST_CHOST}"
}

build() {
  cd "${_realname}-${pkgver}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo build --release --frozen -p watchexec-cli
}

check() {
  cd "${_realname}-${pkgver}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo test --release --frozen -p watchexec-cli
}

package() {
  cd "${_realname}-${pkgver}"

  WINAPI_NO_BUNDLED_LIBRARIES=1 \
    cargo install \
      --frozen \
      --offline \
      --no-track \
      --path crates/cli \
      --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 completions/bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/watchexec"
  install -Dm644 completions/zsh "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_watchexec"
  install -Dm644 completions/fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/watchexec.fish"
  install -Dm644 doc/watchexec.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/watchexec.1"
  install -Dm644 doc/watchexec.1.md "${pkgdir}${MINGW_PREFIX}/share/doc/watchexec/watchexec.1.md"
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/watchexec/LICENSE"
}
