# Maintainer: Maksim Bondarenkov <maksapple2306@gmail.com>
# Co-Maintainer: Peltoche <dev@halium.fr>
# Co-maintainer: Andrea Pascal <andrea@anodium.net>
# Co-Maintainer: Deeraurty at github

_realname=lsd
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.0
pkgrel=1
pkgdesc="The next gen ls command (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/lsd-rs/lsd"
msys2_references=(
  'purl: pkg:cargo/lsd'
)
license=("spdx:Apache-2.0")
makedepends=("${MINGW_PACKAGE_PREFIX}-rust" "${MINGW_PACKAGE_PREFIX}-pkgconf")
options=('!strip')
depends=("${MINGW_PACKAGE_PREFIX}-libgit2")
optdepends=("${MINGW_PACKAGE_PREFIX}-ttf-font-nerd: popular collections such as Font Awesome & fonts such as Hack")
           #'powerline-fonts: powerline symbols for terminals')
source=("https://github.com/lsd-rs/lsd/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('dae8d43087686a4a1de0584922608e9cbab00727d0f72e4aa487860a9cbfeefa')

_env() {
  export LIBGIT2_NO_VENDOR=1
  export WINAPI_NO_BUNDLED_LIBRARIES=1
  export SHELL_COMPLETIONS_DIR="$PWD/completions"
}

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

  cargo update -p cc --precise 1.1.10
  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

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

  _env
  cargo build --release --frozen
}

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

  # Unset lower-cased envs temp and tmp
  # that points to AppData/Local/Temp
  # to pass
  #   - test_list_almost_all_empty_directory
  #   - test_list_all_empty_directory
  unset temp
  unset tmp

  _env
  cargo test --release --frozen
}

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

  _env
  cargo install \
    --offline \
    --no-track \
    --frozen \
    --path . \
    --root "${pkgdir}${MINGW_PREFIX}"

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
  install -Dm644 completions/_lsd "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_lsd"
  install -Dm644 completions/lsd.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/lsd"
  install -Dm644 completions/lsd.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/lsd.fish"
}
