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

# Autogenerated by pycargoebuild 0.13.1

EAPI=8

CRATES="
	ahash@0.7.6
	aho-corasick@1.0.5
	assert_cmd@2.0.5
	atty@0.2.14
	autocfg@1.1.0
	bitflags@1.3.2
	bitflags@2.4.1
	bstr@0.2.17
	bstr@1.6.0
	bumpalo@3.11.1
	bytecount@0.6.2
	cc@1.0.83
	cfg-if@1.0.0
	clap@3.1.18
	clap_lex@0.2.0
	const_format@0.2.23
	const_format_proc_macros@0.2.22
	crossbeam-channel@0.5.8
	crossbeam-deque@0.8.1
	crossbeam-epoch@0.9.8
	crossbeam-utils@0.8.8
	crossterm@0.27.0
	crossterm_winapi@0.9.1
	ctor@0.1.22
	diff@0.1.12
	difflib@0.4.0
	doc-comment@0.3.3
	either@1.6.1
	env_logger@0.10.0
	errno@0.3.5
	fixedbitset@0.4.1
	float-cmp@0.9.0
	fnv@1.0.7
	getrandom@0.2.9
	glob@0.3.1
	globset@0.4.13
	hashbrown@0.11.2
	hashbrown@0.12.3
	heck@0.4.1
	hermit-abi@0.1.19
	hermit-abi@0.3.3
	humansize@2.1.3
	humantime@2.1.0
	ignore@0.4.18
	indexmap@1.7.0
	io-lifetimes@1.0.11
	is-terminal@0.4.7
	itertools@0.10.3
	itertools@0.11.0
	itoa@1.0.9
	lazy_static@1.4.0
	libc@0.2.149
	libm@0.2.7
	libmimalloc-sys@0.1.24
	line-numbers@0.3.0
	linux-raw-sys@0.3.8
	lock_api@0.4.9
	log@0.4.17
	memchr@2.5.0
	memoffset@0.6.5
	mimalloc@0.1.28
	minimal-lexical@0.2.1
	mio@0.8.5
	nom@7.1.1
	normalize-line-endings@0.3.0
	num-traits@0.2.15
	num_cpus@1.13.1
	once_cell@1.17.1
	os_str_bytes@6.0.1
	output_vt100@0.1.3
	owo-colors@3.5.0
	parking_lot@0.12.1
	parking_lot_core@0.9.6
	petgraph@0.6.1
	predicates-core@1.0.3
	predicates-tree@1.0.5
	predicates@2.1.1
	pretty_assertions@1.3.0
	pretty_env_logger@0.5.0
	proc-macro2@1.0.66
	quote@1.0.32
	radix-heap@0.4.2
	rayon-core@1.11.0
	rayon@1.7.0
	redox_syscall@0.2.16
	regex-automata@0.1.10
	regex-automata@0.3.7
	regex-syntax@0.7.5
	regex@1.9.4
	rustc-hash@1.1.0
	rustix@0.37.27
	rustversion@1.0.12
	ryu@1.0.15
	same-file@1.0.6
	scopeguard@1.1.0
	serde@1.0.176
	serde_derive@1.0.176
	serde_json@1.0.104
	signal-hook-mio@0.2.3
	signal-hook-registry@1.4.0
	signal-hook@0.3.17
	smallvec@1.10.0
	strsim@0.10.0
	strum@0.25.0
	strum_macros@0.25.1
	syn@1.0.95
	syn@2.0.27
	termcolor@1.1.3
	terminal_size@0.1.17
	termtree@0.2.4
	textwrap@0.15.0
	thread_local@1.1.7
	tree-sitter@0.20.10
	typed-arena@2.0.2
	unicode-ident@1.0.0
	unicode-width@0.1.9
	unicode-xid@0.2.3
	version_check@0.9.4
	wait-timeout@0.2.0
	walkdir@2.3.3
	wasi@0.11.0+wasi-snapshot-preview1
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.5
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-sys@0.42.0
	windows-sys@0.48.0
	windows-targets@0.48.5
	windows_aarch64_gnullvm@0.42.1
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_msvc@0.42.1
	windows_aarch64_msvc@0.48.5
	windows_i686_gnu@0.42.1
	windows_i686_gnu@0.48.5
	windows_i686_msvc@0.42.1
	windows_i686_msvc@0.48.5
	windows_x86_64_gnu@0.42.1
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnullvm@0.42.1
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_msvc@0.42.1
	windows_x86_64_msvc@0.48.5
	wu-diff@0.1.2
	yansi@0.5.1
"

declare -A GIT_CRATES=(
	[tree_magic_mini]='https://github.com/Wilfred/tree_magic;13dd6dda15c7062bd8f7dd5bc9bb5b16ce9ee613;tree_magic-%commit%'
)

inherit cargo

DESCRIPTION="A structural diff that understands syntax."
HOMEPAGE="http://difftastic.wilfred.me.uk/"
SRC_URI="
	${CARGO_CRATE_URIS}
	https://github.com/Wilfred/${PN}/archive/refs/tags/${PV}.tar.gz -> ${P}.gh.tar.gz
"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+=" Apache-2.0 MIT ZLIB"
# owo-colors
LICENSE+=" MIT"

SLOT="0"
KEYWORDS="~amd64 ~arm64"

QA_FLAGS_IGNORED="usr/bin/difft"

PATCHES=(
	# some tests don't work with sandbox
	"${FILESDIR}/difftastic-0.54.0-tests.patch"
)

DOCS=(
	CHANGELOG.md
	README.md
	manual/
)

src_prepare() {
	rm manual/.gitignore || die

	# since upstream is using the patch syntax here, the patch syntax in the user cargo config isn't working
	local crate commit path _uri sedexpr
	local -a sedexpr
	for crate in "${!GIT_CRATES[@]}"; do
		IFS=";" read -r _uri commit path <<< "${GIT_CRATES[${crate}]}"
		sedexpr+=(
			"s@^(${crate}[[:space:]]*=[[:space:]]*[{].*)([[:space:]]*git[[:space:]]*=[[:space:]]*'[[:graph:]]+'[[:space:]]*)(.*[}])@\1path = '${WORKDIR}/${path//%commit%/${commit}}'\3@ ;"
			"s@^(${crate}[[:space:]]*=[[:space:]]*[{].*)([,][[:space:]]*branch[[:space:]]*=[[:space:]]*'[[:graph:]]+'[[:space:]]*)(.*[}])@\1\3@ ;"
		)
	done
	sed -r -i "${sedexpr[*]}" "${S}/Cargo.toml" || die

	default
}

src_test() {
	cargo_src_test
}

src_install() {
	cargo_src_install
	dodoc -r "${DOCS[@]}"
}