# Contributor: Michał Polański <michal@polanski.me>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: mio <miyopan@e.email>
maintainer="mio <miyopan@e.email>"
pkgname=task3
pkgver=3.2.0
pkgrel=0
pkgdesc="Command-line to-do list manager"
url="https://taskwarrior.org"
arch="all"
license="MIT"
install="$pkgname.post-install"
makedepends="
	cargo
	cmake
	corrosion
	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 \
		-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.2.0: failed tests on CI
	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="
c9b86ba2cd331846c18e89e7f2938934a8bd3fd8a148ad0a2319f19a04d4bc8308ae79d97c679b573e5d65cdcabd95bf92f6a0b168f8b4299deabf66bb4131ef  task-3.2.0.tar.gz
7889db681299da2aa1270a891dd8a05e2d554b92618093a95f8d91bab7b63b7b27b5364bc20d6c857712f0e6035cd5d4428de8954eeb6a1c3c05a893e7ea2bf9  task-archive-3.2.0.tar.gz
"
