maintainer="Bart Ribbers <bribbers@disroot.org>"
pkgname=fish
pkgver=4.0.2
pkgrel=0
pkgdesc="Modern interactive commandline shell"
url="https://fishshell.com/"
arch="all"
license="GPL-2.0-only"
depends="ncurses-terminfo"
depends_dev="$pkgname-tools"
makedepends="
	cargo
	cargo-auditable
	cmake
	doxygen
	gettext-dev
	pcre2-dev
	py3-sphinx
	samurai
	"
# Ensure that racy tmux tests are skipped, eases debugging when tmux is installed on the builders.
checkdepends="
	!tmux
	bash
	py3-pexpect
	"
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-deinstall"
subpackages="$pkgname-dev $pkgname-doc $pkgname-tools::noarch $pkgname-lang"
options="net"
source="https://github.com/fish-shell/fish-shell/releases/download/$pkgver/fish-$pkgver.tar.xz
	ignore-test_history_races.patch
	disable-flaky-tests.patch
	README.alpine
	cargo
	"

# these were moved to the correct place, but on upgrade, fish would upgrade first,
# which would conflict right before the others move, so we need a replaces= for
# one transaction.
replaces="
	black-fish-completion
	curl-fish-completion
	docker-fish-completion
	flatpak-fish-completion
	helm-fish-completion
	hugo-fish-completion
	kind-fish-completion
	mdbook-fish-completion
	minikube-fish-completion
	ouch-fish-completion
	rclone-fish-completion
	rustup-fish-completion
	starship-fish-completion
	topgrade-fish-completion
	"

# secfixes:
#   3.4.0-r0:
#     - CVE-2022-20001

prepare() {
	default_prepare
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		-DCMAKE_INSTALL_SYSCONFDIR=/etc \
		-DBUILD_DOCS=TRUE \
		-DRust_CARGO="$srcdir/cargo"
	cd build && cargo fetch --target="$CHOST" --locked
}

build() {
	cmake --build build --target all
}

check() {
	CI=1 ninja -C build fish_run_tests
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	rm -fr "$pkgdir"/usr/share/$pkgname/groff

	# Install our README
	install -Dm 644 "$srcdir"/README.alpine -t "$pkgdir"/usr/share/doc/fish

	mkdir -p "$pkgdir"/usr/lib
	mv "$pkgdir"/usr/share/pkgconfig "$pkgdir"/usr/lib
}

doc() {
	default_doc

	amove usr/share/$pkgname/man
}

tools() {
	pkgdesc="$pkgdesc (tools)"
	depends="$pkgname python3 cmd:man"

	amove usr/share/$pkgname/tools
}

sha512sums="
9b95c58884fe139a05043f8bed8d93825237327be3384f4310cbf43f4f1996dbad66eb9ba39b36741f3769e17df46166f1b872a59b2375dbc50aaec536b73c96  fish-4.0.2.tar.xz
82d69fd0f197363dc526ecfd2fc62ac447e856f5c759acb03aec5853607f51156f04463cf99bad4ee06ee9aed3bef137f00732a1b7a6e8d67943f7e83e35848b  ignore-test_history_races.patch
f800b081b96c6bff9f7ac46adc65ae109fea51558fb03bd56ca541f6ae70de85e5dd244f6dee50a86e70ae10d6742a5eb698ec1db7d7c9dcef4532da0b1dd98b  disable-flaky-tests.patch
c28cef48e3d9cde4956d36192dc221e63eca89282a937e2683578ac0958d98a9c54420aea4f1d91d516f5ee2c74589a75865a973305421e1ad0a9e70854dff4f  README.alpine
55af2662bd4b5c071e09f4aca3d0186ecee18d6b573f0d54dca4d97a3cf80556ac327a987cf8be5fe7d09dad2db7b8bc08ef3f675b4ffad53fe760988e1e0edd  cargo
"
