# Copyright 2022-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.6.2

EAPI=8

CRATES="
	aho-corasick@1.1.2
	android-tzdata@0.1.1
	android_system_properties@0.1.5
	ansi_term@0.12.1
	anstream@0.6.4
	anstyle-parse@0.2.2
	anstyle-query@1.0.0
	anstyle-wincon@3.0.1
	anstyle@1.0.4
	arrayref@0.3.7
	arrayvec@0.7.4
	assert_cmd@2.0.12
	atty@0.2.14
	autocfg@1.1.0
	bindgen@0.64.0
	bitflags@1.3.2
	bitflags@2.4.1
	blake2b_simd@1.0.2
	blake3@1.5.0
	block-buffer@0.10.4
	bstr@1.8.0
	bumpalo@3.14.0
	cc@1.0.83
	cexpr@0.6.0
	cfg-if@1.0.0
	chrono@0.4.31
	clang-sys@1.6.1
	clap@2.34.0
	clap@4.4.8
	clap_builder@4.4.8
	clap_lex@0.6.0
	colorchoice@1.0.0
	constant_time_eq@0.3.0
	core-foundation-sys@0.8.4
	cpufeatures@0.2.11
	crypto-common@0.1.6
	dashmap@5.5.3
	deranged@0.3.9
	difflib@0.4.0
	digest@0.10.7
	doc-comment@0.3.3
	dunce@1.0.4
	either@1.9.0
	errno@0.3.7
	faccess@0.2.4
	fastrand@2.0.1
	filetime@0.2.22
	float-cmp@0.9.0
	futures-channel@0.3.29
	futures-core@0.3.29
	futures-executor@0.3.29
	futures-io@0.3.29
	futures-sink@0.3.29
	futures-task@0.3.29
	futures-util@0.3.29
	futures@0.3.29
	generic-array@0.14.7
	glob@0.3.1
	hashbrown@0.14.2
	hermit-abi@0.1.19
	hex@0.4.3
	home@0.5.5
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.58
	itertools@0.11.0
	itoa@1.0.9
	js-sys@0.3.65
	keccak@0.1.4
	lazy_static@1.4.0
	lazycell@1.3.0
	libc@0.2.150
	libloading@0.7.4
	linux-raw-sys@0.4.11
	lock_api@0.4.11
	log@0.4.20
	md-5@0.10.6
	memchr@2.6.4
	memoffset@0.7.1
	minimal-lexical@0.2.1
	nix@0.26.4
	nom@7.1.3
	normalize-line-endings@0.3.0
	num-traits@0.2.17
	num_threads@0.1.6
	once_cell@1.18.0
	os_display@0.1.3
	parking_lot@0.12.1
	parking_lot_core@0.9.9
	peeking_take_while@0.1.2
	pin-project-lite@0.2.13
	pin-utils@0.1.0
	pkg-config@0.3.27
	powerfmt@0.2.0
	predicates-core@1.0.6
	predicates-tree@1.0.9
	predicates@3.0.4
	proc-macro2@1.0.69
	quote@1.0.33
	redox_syscall@0.3.5
	redox_syscall@0.4.1
	regex-automata@0.4.3
	regex-syntax@0.8.2
	regex@1.10.2
	rustc-hash@1.1.0
	rustix@0.38.25
	same-file@1.0.6
	scopeguard@1.2.0
	serde@1.0.193
	serde_derive@1.0.193
	serial_test@2.0.0
	serial_test_derive@2.0.0
	sha1@0.10.6
	sha2@0.10.8
	sha3@0.10.8
	shlex@1.2.0
	slab@0.4.9
	sm3@0.4.2
	smallvec@1.11.2
	strsim@0.10.0
	strsim@0.8.0
	syn@1.0.109
	syn@2.0.39
	tempfile@3.8.1
	terminal_size@0.3.0
	termtree@0.4.1
	textwrap@0.11.0
	time-core@0.1.2
	time-macros@0.2.15
	time@0.3.30
	typenum@1.17.0
	unicode-ident@1.0.12
	unicode-width@0.1.11
	utf8parse@0.2.1
	uucore@0.0.20
	uucore_procs@0.0.23
	uuhelp_parser@0.0.23
	vec_map@0.8.2
	version_check@0.9.4
	wait-timeout@0.2.0
	walkdir@2.4.0
	wasm-bindgen-backend@0.2.88
	wasm-bindgen-macro-support@0.2.88
	wasm-bindgen-macro@0.2.88
	wasm-bindgen-shared@0.2.88
	wasm-bindgen@0.2.88
	which@4.4.2
	wild@2.2.0
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.6
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-core@0.51.1
	windows-sys@0.48.0
	windows-targets@0.48.5
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_msvc@0.48.5
	windows_i686_gnu@0.48.5
	windows_i686_msvc@0.48.5
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_msvc@0.48.5
"

# Building onig-sys fails w/ Clang 16 right now, so use the version from git:
# https://github.com/rust-onig/rust-onig/issues/173
declare -A GIT_CRATES=(
	[onig]="https://github.com/rust-onig/rust-onig;fa90c0e97e90a056af89f183b23cd417b59ee6a2;rust-onig-%commit%/onig"
	[onig_sys]="https://github.com/rust-onig/rust-onig;fa90c0e97e90a056af89f183b23cd417b59ee6a2;rust-onig-%commit%/onig_sys"
)

LLVM_MAX_SLOT=17
inherit cargo llvm

DESCRIPTION="GNU findutils rewritten in Rust"
HOMEPAGE="https://uutils.github.io/findutils/ https://github.com/uutils/findutils"

if [[ ${PV} == 9999 ]] ; then
	EGIT_REPO_URI="https://github.com/uutils/findutils"
	inherit git-r3
elif [[ ${PV} == *_p* ]] ; then
	FINDUTILS_COMMIT="59301c788aa610bd9b35d8715af72d87528d07dc"
	SRC_URI="https://github.com/uutils/findutils/archive/${FINDUTILS_COMMIT}.tar.gz -> ${P}.tar.gz"
	SRC_URI+=" ${CARGO_CRATE_URIS}"
	S="${WORKDIR}"/findutils-${FINDUTILS_COMMIT}
else
	SRC_URI="https://github.com/uutils/findutils/archive/refs/tags/${PV}.tar.gz -> ${P}.tar.gz"
	SRC_URI+=" ${CARGO_CRATE_URIS}"
	SRC_URI+=" https://dev.gentoo.org/~sam/distfiles/${CATEGORY}/${PN}/${PN}-0.4.2-update-crates.patch.xz"
	S="${WORKDIR}"/findutils-${PV}
fi

LICENSE="MIT"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD-2 BSD ISC MIT Unicode-DFS-2016"
SLOT="0"
if [[ ${PV} != 9999 ]] ; then
	KEYWORDS="~amd64 ~arm64"
fi

RDEPEND=">=dev-libs/oniguruma-6.9.9:="
DEPEND="${RDEPEND}"
BDEPEND="
	<sys-devel/clang-$((LLVM_MAX_SLOT + 1))
	>=virtual/rust-1.56.0
"

QA_FLAGS_IGNORED=".*"

PATCHES=(
	"${WORKDIR}"/${PN}-0.4.2-update-crates.patch
)

src_unpack() {
	if [[ ${PV} == 9999 ]] ; then
		git-r3_src_unpack
		cargo_live_src_unpack
	else
		cargo_src_unpack
	fi
}

src_configure() {
	export RUSTONIG_SYSTEM_LIBONIG=1
	export PKG_CONFIG_ALLOW_CROSS=1

	cargo_src_configure
}

src_install() {
	cargo_src_install

	rm "${ED}"/usr/bin/testing-commandline || die

	local binary
	for binary in find xargs ; do
		mv "${ED}"/usr/bin/${binary} "${ED}"/usr/bin/uutils-${binary} || die
	done
}