# Maintainer: Integral <integral@member.fsf.org>
# Maintainer: Hoàng Văn Khải <hvksmr1996@gmail.com>

pkgname=parallel-disk-usage-git
_pkgname=${pkgname%-git}
pkgver=0.24.0.r13.g4f52830
pkgrel=1
pkgdesc="Summarize disk usage of the set of files, recursively for directories."
arch=('x86_64' 'aarch64' 'riscv64')
url="https://github.com/KSXGitHub/${_pkgname}"
license=('Apache-2.0')
makedepends=('git' 'cargo')
checkdepends=('squashfs-tools' 'squashfuse')
conflicts=("${_pkgname}")
provides=("${_pkgname}")
source=("git+${url}.git")
sha256sums=("SKIP")

pkgver() {
	cd "${_pkgname}/"
	git describe --long --tags --abbrev=7 | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
	cd "${_pkgname}/"
	cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
	cd "${_pkgname}/"
	cargo build --bin pdu --frozen --release --all-features
}

check() {
	cd "${_pkgname}/"
	cargo test --frozen --all-features
}

package() {
	cd "${_pkgname}/"
	install -Dm755 target/release/pdu -t "${pkgdir}/usr/bin/"
	install -Dm644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}/"

	cd exports
	install -Dm644 completion.bash "${pkgdir}/usr/share/bash-completion/completions/pdu"
	install -Dm644 completion.fish "${pkgdir}/usr/share/fish/completions/pdu.fish"
	install -Dm644 completion.zsh "${pkgdir}/usr/share/zsh/site-functions/_pdu"
}
