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

EAPI=8

# Upstream raises rust-version in Cargo.toml; keep this in sync with it.
RUST_MIN_VER="1.100.0"

inherit cargo git-r3

DESCRIPTION="Linter, formatter and static analyzer for PHP, written in Rust"
HOMEPAGE="
	https://mago.carthage.software/
	https://github.com/carthage-software/mago
"
EGIT_REPO_URI="https://github.com/carthage-software/mago.git"

LICENSE="|| ( Apache-2.0 MIT )"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD BSD-2 Boost-1.0 CC0-1.0 CDLA-Permissive-2.0 ISC MIT MPL-2.0
	Unicode-3.0 ZLIB
"
SLOT="0"

RDEPEND="!dev-util/mago-bin"

PATCHES=(
	# Portage owns the binary: keep self-update from overwriting it.
	# TODO: drop when upstream adds a build switch for self-update:
	# https://github.com/carthage-software/mago/issues/2884
	"${FILESDIR}"/mago-disable-self-update.patch
)

src_unpack() {
	git-r3_src_unpack
	cargo_live_src_unpack
}

src_compile() {
	# The upstream release profile strips symbols and sets an RPATH;
	# let Portage strip the binary, and leave the RPATH out.
	export CARGO_PROFILE_RELEASE_STRIP=false
	export CARGO_PROFILE_RELEASE_RPATH=false
	cargo_src_compile --bin mago
}

src_install() {
	dobin "$(cargo_target_dir)/mago"
	einstalldocs
}