# Copyright 2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# shellcheck shell=bash
# shellcheck disable=SC2034

EAPI=8

CRATES="
	addr2line@0.25.1
	adler2@2.0.1
	aho-corasick@1.1.4
	android_system_properties@0.1.5
	anstream@0.6.21
	anstyle-parse@0.2.7
	anstyle-query@1.1.5
	anstyle-wincon@3.0.11
	anstyle@1.0.13
	arbitrary@1.4.2
	arc-swap@1.7.1
	async-broadcast@0.7.2
	async-channel@2.5.0
	async-executor@1.13.3
	async-io@2.6.0
	async-lock@3.4.1
	async-process@2.5.0
	async-recursion@1.1.1
	async-signal@0.2.13
	async-task@4.7.1
	async-trait@0.1.89
	atomic-waker@1.1.2
	autocfg@1.5.0
	backtrace@0.3.76
	base62@2.2.3
	base64@0.22.1
	base64ct@1.7.3
	bitflags@1.3.2
	bitflags@2.10.0
	block-buffer@0.10.4
	block2@0.6.2
	blocking@1.6.2
	bstr@1.12.1
	bumpalo@3.19.0
	byteorder@1.5.0
	bytes@1.11.0
	cc@1.2.47
	cfg-if@1.0.4
	cfg_aliases@0.2.1
	chrono@0.4.42
	clap-cargo@0.15.2
	clap@4.5.53
	clap_builder@4.5.53
	clap_complete@4.5.61
	clap_derive@4.5.49
	clap_lex@0.7.6
	clap_mangen@0.2.31
	color-eyre@0.6.5
	color-spantrace@0.3.0
	colorchoice@1.0.4
	concurrent-queue@2.5.0
	console@0.15.11
	console@0.16.1
	const-oid@0.9.6
	const-random-macro@0.1.16
	const-random@0.1.18
	core-foundation-sys@0.8.7
	cpufeatures@0.2.17
	crc32fast@1.5.0
	crossbeam-deque@0.8.6
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.21
	crunchy@0.2.4
	crypto-common@0.1.7
	curve25519-dalek-derive@0.1.1
	curve25519-dalek@4.1.3
	der@0.7.10
	deranged@0.5.5
	derive_arbitrary@1.4.2
	digest@0.10.7
	dirs-sys@0.5.0
	dirs@6.0.0
	dispatch2@0.3.0
	displaydoc@0.2.5
	dlv-list@0.5.2
	ed25519-dalek@2.2.0
	ed25519@2.2.3
	either@1.15.0
	encode_unicode@1.0.0
	endi@1.1.0
	enumflags2@0.7.12
	enumflags2_derive@0.7.12
	env_home@0.1.0
	equivalent@1.0.2
	errno@0.3.14
	etcetera@0.10.0
	event-listener-strategy@0.5.4
	event-listener@5.4.1
	eyre@0.6.12
	fastrand@2.3.0
	fiat-crypto@0.2.9
	filetime@0.2.26
	find-msvc-tools@0.1.5
	flate2@1.1.5
	fnv@1.0.7
	form_urlencoded@1.2.2
	freedesktop-desktop-entry@0.7.19
	futures-channel@0.3.31
	futures-core@0.3.31
	futures-executor@0.3.31
	futures-io@0.3.31
	futures-lite@2.6.1
	futures-macro@0.3.31
	futures-sink@0.3.31
	futures-task@0.3.31
	futures-util@0.3.31
	futures@0.3.31
	generic-array@0.14.7
	getrandom@0.2.16
	getrandom@0.3.4
	gimli@0.32.3
	glob@0.3.3
	globset@0.4.16
	globwalk@0.8.1
	h2@0.4.12
	hashbrown@0.14.5
	hashbrown@0.16.1
	heck@0.5.0
	hermit-abi@0.5.2
	hex@0.4.3
	home@0.5.11
	http-body-util@0.1.3
	http-body@1.0.1
	http@1.3.1
	httparse@1.10.1
	hyper-rustls@0.27.7
	hyper-util@0.1.18
	hyper@1.8.1
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.64
	icu_collections@2.1.1
	icu_locale_core@2.1.1
	icu_normalizer@2.1.1
	icu_normalizer_data@2.1.1
	icu_properties@2.1.1
	icu_properties_data@2.1.1
	icu_provider@2.1.1
	idna@1.1.0
	idna_adapter@1.2.1
	ignore@0.4.23
	indenter@0.3.4
	indexmap@2.12.1
	indicatif@0.17.11
	ipnet@2.11.0
	iri-string@0.7.9
	is_elevated@0.1.2
	is_terminal_polyfill@1.70.2
	itertools@0.11.0
	itoa@1.0.15
	jetbrains-toolbox-updater@5.4.6
	js-sys@0.3.82
	lazy_static@1.5.0
	libc@0.2.177
	libredox@0.1.10
	linux-raw-sys@0.11.0
	litemap@0.8.1
	log@0.4.28
	lru-slab@0.1.2
	matchers@0.2.0
	memchr@2.7.6
	memoffset@0.9.1
	merge@0.1.0
	merge_derive@0.1.0
	miniz_oxide@0.8.9
	mio@1.1.0
	nix@0.30.1
	normpath@1.5.0
	notify-rust@4.11.7
	ntapi@0.4.1
	nu-ansi-term@0.50.3
	num-conv@0.1.0
	num-traits@0.2.19
	number_prefix@0.4.0
	objc2-core-foundation@0.3.2
	objc2-encode@4.1.0
	objc2-foundation@0.3.2
	objc2-io-kit@0.3.2
	objc2@0.6.3
	object@0.37.3
	once_cell@1.21.3
	once_cell_polyfill@1.70.2
	option-ext@0.2.0
	ordered-multimap@0.7.3
	ordered-stream@0.2.0
	owo-colors@4.2.3
	parking@2.2.1
	parselnk@0.1.1
	percent-encoding@2.3.2
	pin-project-lite@0.2.16
	pin-utils@0.1.0
	piper@0.2.4
	pkcs8@0.10.2
	polling@3.11.0
	portable-atomic@1.11.1
	potential_utf@0.1.4
	powerfmt@0.2.0
	ppv-lite86@0.2.21
	proc-macro-crate@3.4.0
	proc-macro-error-attr@1.0.4
	proc-macro-error@1.0.4
	proc-macro2@1.0.103
	quick-xml@0.37.5
	quinn-proto@0.11.13
	quinn-udp@0.5.14
	quinn@0.11.9
	quote@1.0.42
	r-efi@5.3.0
	rand@0.9.2
	rand_chacha@0.9.0
	rand_core@0.6.4
	rand_core@0.9.3
	redox_syscall@0.5.18
	redox_users@0.5.2
	regex-automata@0.4.13
	regex-split@0.1.0
	regex-syntax@0.8.8
	regex@1.12.2
	reqwest@0.12.24
	ring@0.17.14
	roff@0.2.2
	rust-i18n-macro@3.1.5
	rust-i18n-support@3.1.5
	rust-i18n@3.1.5
	rust-ini@0.21.3
	rustc-demangle@0.1.26
	rustc-hash@2.1.1
	rustc_version@0.4.1
	rustix@1.1.2
	rustls-pki-types@1.13.0
	rustls-webpki@0.103.8
	rustls@0.23.35
	rustversion@1.0.22
	ryu@1.0.20
	same-file@1.0.6
	self-replace@1.5.0
	self_update@0.42.0
	semver@1.0.27
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.145
	serde_repr@0.1.20
	serde_spanned@0.6.9
	serde_spanned@1.0.3
	serde_urlencoded@0.7.1
	serde_yaml@0.9.34+deprecated
	sha2@0.10.9
	sharded-slab@0.1.7
	shell-words@1.1.0
	shellexpand@3.1.1
	shlex@1.3.0
	signal-hook-registry@1.4.7
	signature@2.2.0
	simd-adler32@0.3.7
	siphasher@1.0.1
	slab@0.4.11
	smallvec@1.15.1
	socket2@0.6.1
	spki@0.7.3
	stable_deref_trait@1.2.1
	static_assertions@1.1.0
	strsim@0.11.1
	strum@0.27.2
	strum_macros@0.27.2
	subtle@2.6.1
	syn@1.0.109
	syn@2.0.111
	sync_wrapper@1.0.2
	synstructure@0.13.2
	sys-locale@0.3.2
	sysinfo@0.36.1
	tar@0.4.44
	tauri-winrt-notification@0.7.2
	tempfile@3.23.0
	thiserror-impl@1.0.69
	thiserror-impl@2.0.17
	thiserror@1.0.69
	thiserror@2.0.17
	thread_local@1.1.9
	time-core@0.1.6
	time-macros@0.2.24
	time@0.3.44
	tiny-keccak@2.0.2
	tinystr@0.8.2
	tinyvec@1.10.0
	tinyvec_macros@0.1.1
	tokio-rustls@0.26.4
	tokio-util@0.7.17
	tokio@1.48.0
	toml@0.8.23
	toml@0.9.8
	toml_datetime@0.6.11
	toml_datetime@0.7.3
	toml_edit@0.22.27
	toml_edit@0.23.7
	toml_parser@1.0.4
	toml_write@0.1.2
	toml_writer@1.0.4
	tower-http@0.6.6
	tower-layer@0.3.3
	tower-service@0.3.3
	tower@0.5.2
	tracing-attributes@0.1.30
	tracing-core@0.1.34
	tracing-error@0.2.1
	tracing-log@0.2.0
	tracing-subscriber@0.3.20
	tracing@0.1.41
	triomphe@0.1.15
	try-lock@0.2.5
	typenum@1.19.0
	uds_windows@1.1.0
	unicase@2.8.1
	unicode-ident@1.0.22
	unicode-width@0.2.2
	unsafe-libyaml@0.2.11
	untrusted@0.9.0
	url@2.5.7
	urlencoding@2.1.3
	utf8_iter@1.0.4
	utf8parse@0.2.2
	uuid@1.18.1
	valuable@0.1.1
	version_check@0.9.5
	walkdir@2.5.0
	want@0.3.1
	wasi@0.11.1+wasi-snapshot-preview1
	wasip2@1.0.1+wasi-0.2.4
	wasm-bindgen-futures@0.4.55
	wasm-bindgen-macro-support@0.2.105
	wasm-bindgen-macro@0.2.105
	wasm-bindgen-shared@0.2.105
	wasm-bindgen@0.2.105
	web-sys@0.3.82
	web-time@1.1.0
	webpki-roots@1.0.4
	which@8.0.0
	widestring@0.4.3
	wildmatch@2.6.1
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.11
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-collections@0.2.0
	windows-collections@0.3.2
	windows-core@0.61.2
	windows-core@0.62.2
	windows-future@0.2.1
	windows-future@0.3.2
	windows-implement@0.60.2
	windows-interface@0.59.3
	windows-link@0.1.3
	windows-link@0.2.1
	windows-numerics@0.2.0
	windows-numerics@0.3.1
	windows-registry@0.6.1
	windows-result@0.3.4
	windows-result@0.4.1
	windows-strings@0.4.2
	windows-strings@0.5.1
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.2
	windows-targets@0.52.6
	windows-targets@0.53.5
	windows-threading@0.1.0
	windows-threading@0.2.1
	windows-version@0.1.7
	windows@0.61.3
	windows@0.62.2
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.1
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.1
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.1
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.1
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.1
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.1
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.1
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.1
	winnow@0.7.13
	winsafe@0.0.19
	wit-bindgen@0.46.0
	writeable@0.6.2
	xattr@1.6.1
	xdg@3.0.0
	yoke-derive@0.8.1
	yoke@0.8.1
	zbus@5.12.0
	zbus_macros@5.12.0
	zbus_names@4.2.0
	zerocopy-derive@0.8.28
	zerocopy@0.8.28
	zerofrom-derive@0.1.6
	zerofrom@0.1.6
	zeroize@1.8.2
	zerotrie@0.2.3
	zerovec-derive@0.11.2
	zerovec@0.11.5
	zip@2.4.2
	zipsign-api@0.1.5
	zopfli@0.8.3
	zvariant@5.8.0
	zvariant_derive@5.8.0
	zvariant_utils@3.2.1
"

declare -A GIT_CRATES=(
	[mac-notification-sys]='https://github.com/h4llow3En/mac-notification-sys;7798ad033f3422b0fc9cdd25c17d3c400f4b7ef0;mac-notification-sys-%commit%'
)

RUST_MIN_VER="1.84.1"

inherit cargo shell-completion

DESCRIPTION="Upgrade all the things"
HOMEPAGE="https://github.com/topgrade-rs/topgrade"
SRC_URI="
	https://github.com/topgrade-rs/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
	${CARGO_CRATE_URIS}
"

LICENSE="GPL-3"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD CC0-1.0 GPL-3 ISC MIT
	MPL-2.0 Unicode-3.0
"
# owo-colors license file
LICENSE+="MIT"
SLOT="0"
KEYWORDS="~amd64"

QA_FLAGS_IGNORED="usr/bin/topgrade"

src_prepare() {
	default

	# replace upstream crate substitution with our crate substitution, sigh
	# stolen from dev-python/uv::gentoo
	local pkg
	# shellcheck disable=SC2043
	for pkg in mac-notification-sys; do
		# shellcheck disable=SC2155
		local dep=$(grep "^${pkg}" "${ECARGO_HOME}"/config.toml || die)
		sed -i -e "/\[patch\.crates-io\]/,\$s;^${pkg}.*$;${dep};" Cargo.toml || die
	done
}

src_compile() {
	cargo_src_compile

	(
		# shellcheck disable=SC2155
		export PATH="$(cargo_target_dir)"
		for shell in bash fish zsh; do
			topgrade --gen-completion "${shell}" > "${T}/${shell}.completion" || die
		done
		topgrade --gen-manpage > "${T}/manpage.1" || die
	)
}

src_install() {
	cargo_src_install

	newbashcomp "${T}/bash.completion" "${PN}"
	newzshcomp "${T}/zsh.completion" "_${PN}"
	newfishcomp "${T}/fish.completion" "${PN}.fish"
	newman "${T}/manpage.1" "${PN}.1"
}