Re: [PATCH] cargo.eclass: separates crate unpacking logic in cargo_src_unpack into a separate function

Michał Górny <[email protected]>
Newsgroups gmane.linux.gentoo.devel
Organization Gentoo
Message-ID <[email protected]>
On Wed, 2026-08-12 at 18:28 +0600, ingenarel (NeoJesus) wrote:
> cargo_src_unpack currently does this:
> goes through ${A}:
>     if it sees something without the .crate extension, unpack it instantly
>     if it sees a crate, then put it in an array of crates
> Unpacks the list of crates
> Calls cargo_gen_config
> 
> Which is fine, but what if the ebuild needs its own unpacking logic?
> But also requires some crates unpacking too?
> 
> This is what I encountered in an ebuild of mine when I was working on a
> npm eclass, and trying to package cinny-desktop, which needs both npm
> stuff, and rust stuff

Thanks for doing this.  It's been annoying me to no end as well, see all
the Python ebuilds combining pypi_src_unpack and cargo_src_unpack, and
therefore wasting time unpacking stuff twice.

> Signed-off-by: ingenarel (NeoJesus) <[email protected]>
> ---
>  eclass/cargo.eclass | 29 +++++++++++++++++++++++------
>  1 file changed, 23 insertions(+), 6 deletions(-)
> 
> diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
> index 185531490a..e9a4b5853f 100644
> --- a/eclass/cargo.eclass
> +++ b/eclass/cargo.eclass
> @@ -518,10 +518,10 @@ cargo_update_crates () {
>  	cargo_env "${@}" || die "Failed to update crates"
>  }
>  
> -# @FUNCTION: cargo_src_unpack
> +# @FUNCTION: cargo_crates_unpack
>  # @DESCRIPTION:
> -# Unpacks the package and the cargo registry.
> -cargo_src_unpack() {
> +# Unpacks the cargo crates only
> +cargo_crates_unpack() {
>  	debug-print-function ${FUNCNAME} "$@"
>  
>  	mkdir -p "${ECARGO_VENDOR}" "${S}" || die
> @@ -533,9 +533,6 @@ cargo_src_unpack() {
>  			*.crate)
>  				crates+=( "${archive}" )
>  				;;
> -			*)
> -				unpack "${archive}"
> -				;;
>  		esac
>  	done
>  
> @@ -572,7 +569,27 @@ cargo_src_unpack() {
>  			eqawarn "'pycargoebuild --crate-tarball' to create one."
>  		fi
>  	fi
> +}
> +
> +# @FUNCTION: cargo_src_unpack
> +# @DESCRIPTION:
> +# Unpacks the package and the cargo registry.
> +cargo_src_unpack() {
> +	debug-print-function ${FUNCNAME} "$@"
> +
> +	mkdir -p "${ECARGO_VENDOR}" "${S}" || die
>  
> +	local archive
> +	for archive in ${A}; do
> +		case "${archive}" in
> +			*.crate)
> +				;;
> +			*)
> +				unpack "${archive}"
> +				;;
> +		esac
> +	done

That's pretty much what `unpack` / `default` does here (except I guess
it normally does verbosely report all of them).

> +	cargo_crates_unpack
>  	cargo_gen_config
>  }
>  

-- 
Best regards,
Michał Górny
signature.asc (application/pgp-signature, 293 B)
-----BEGIN PGP SIGNATURE-----

iKQEABYKAEwWIQQcFD0bEK7NPNmWHtiOMjR69AVa6AUCanxoshsUgAAAAAAEAA5t
YW51MiwyLjUrMS4xMiwyLDISHG1nb3JueUBnZW50b28ub3JnAAoJEI4yNHr0BVro
mlkBAOynVsgzuVmDSVeKCGkagAci52BXJWtqMcO4ZlDwni/9AQCpNwKuwq3kSnwb
7XmfGWc0hw2IArXwdxmvrV3aeuvtAw==
=Vnej
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.