# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: mio <miyopan@e.email>
maintainer="mio <miyopan@e.email>"
pkgname=task3
pkgver=3.4.1
pkgrel=0
pkgdesc="Command-line to-do list manager"
url="https://taskwarrior.org"
arch="all"
license="MIT"
install="$pkgname.post-install"
makedepends="
	cargo
	cargo-auditable
	clang-libclang
	cmake
	corrosion
	samurai
	sqlite-dev
	util-linux-dev
	"
checkdepends="bash python3"
subpackages="$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
# Release tarball excludes the test suite, extract from the archive tarball
source="https://github.com/GothenburgBitFactory/taskwarrior/releases/download/v$pkgver/task-$pkgver.tar.gz
	https://github.com/GothenburgBitFactory/taskwarrior/archive/v$pkgver/task-archive-$pkgver.tar.gz
	"
builddir="$srcdir"/task-$pkgver

prepare() {
	default_prepare

	cp -r "$srcdir"/taskwarrior-$pkgver/test "$builddir"/

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DSYSTEM_CORROSION=ON
	cmake --build build

	if want_check; then
		cmake --build build --target test_runner --target task_executable
	fi
}

check() {
	# 3.3.0: abbreviation failed on CI, delete failed on builder
	case "$CARCH" in
		armhf|armv7|x86) ctest --test-dir build -E "abbreviation.test.py";;
		loongarch64) ctest --test-dir build -E "delete.test.py";;
		*) ctest --test-dir build;;
	esac
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm644 scripts/bash/task.sh \
		"$pkgdir"/usr/share/bash-completion/completions/task
	install -Dm644 scripts/fish/task.fish \
		"$pkgdir"/usr/share/fish/vendor_completions.d/task.fish
	install -Dm644 scripts/zsh/_task \
		"$pkgdir"/usr/share/zsh/site-functions/_task
}

sha512sums="
5a6479e2afcd5142e88349b792e00fcab4d54f6762db5be00221685a93baa3332a4a410b82f66679c15eff58a43be0e175cea440b2d7befbf4e9b723a695a869  task-3.4.1.tar.gz
1d458a64bffe17eed8eb5c2cbdaf3db11954d76891e240b9caa8135c2eb5b2319c736fc77aec066ae0b28f1293cf9b94944a40a77c6b5eeb5c791bf2c15003d3  task-archive-3.4.1.tar.gz
"
