Gentoo Archives: gentoo-commits

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Sat, 03 Jul 2021 07:03:12
Message-Id: 1625295550.772ae1adf22085b5bdb61566c420839525fc7feb.gyakovlev@gentoo
1 commit: 772ae1adf22085b5bdb61566c420839525fc7feb
2 Author: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jul 3 05:51:54 2021 +0000
4 Commit: Georgy Yakovlev <gyakovlev <AT> gentoo <DOT> org>
5 CommitDate: Sat Jul 3 06:59:10 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=772ae1ad
7
8 cargo.eclass: make CRATES pre-inherit
9
10 also make first arg to cargo_crate_uris optional
11 die if CRATES variable is not defined in EAPI=8
12
13 Signed-off-by: Georgy Yakovlev <gyakovlev <AT> gentoo.org>
14
15 eclass/cargo.eclass | 24 +++++++++++++++++++++---
16 1 file changed, 21 insertions(+), 3 deletions(-)
17
18 diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
19 index 50237d302ce..938511e410f 100644
20 --- a/eclass/cargo.eclass
21 +++ b/eclass/cargo.eclass
22 @@ -34,6 +34,11 @@ case "${EAPI:-0}" in
23 # 1.52 may need setting RUSTC_BOOTSTRAP envvar for some crates
24 # 1.53 added cargo update --offline, can be used to update vulnerable crates from pre-fetched registry without editing toml
25 RUST_DEPEND=">=virtual/rust-1.53"
26 +
27 + if [[ -z ${CRATES} && "${PV}" != *9999* ]]; then
28 + eerror "undefined CRATES variable in non-live EAPI=8 ebuild"
29 + die "CRATES variable not defined"
30 + fi
31 ;;
32 *)
33 die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
34 @@ -54,6 +59,7 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
35
36 # @ECLASS-VARIABLE: CRATES
37 # @DEFAULT_UNSET
38 +# @PRE_INHERIT
39 # @DESCRIPTION:
40 # bash string containing all crates package wants to download
41 # used by cargo_crate_uris()
42 @@ -66,7 +72,7 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
43 # "
44 # inherit cargo
45 # ...
46 -# SRC_URI="$(cargo_crate_uris ${CRATES})"
47 +# SRC_URI="$(cargo_crate_uris)"
48 # @CODE
49
50 # @ECLASS-VARIABLE: CARGO_OPTIONAL
51 @@ -131,10 +137,22 @@ ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
52 # @FUNCTION: cargo_crate_uris
53 # @DESCRIPTION:
54 # Generates the URIs to put in SRC_URI to help fetch dependencies.
55 +# Uses first argument as crate list.
56 +# If no argument provided, uses CRATES variable.
57 cargo_crate_uris() {
58 local -r regex='^([a-zA-Z0-9_\-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$'
59 - local crate
60 - for crate in "$@"; do
61 + local crate crates
62 +
63 + if [[ -n ${@} ]]; then
64 + crates="$@"
65 + elif [[ -n ${CRATES} ]]; then
66 + crates="${CRATES}"
67 + else
68 + eerror "CRATES variable is not defined and nothing passed as argument"
69 + die "Can't generate SRC_URI from empty input"
70 + fi
71 +
72 + for crate in ${crates}; do
73 local name version url
74 [[ $crate =~ $regex ]] || die "Could not parse name and version from crate: $crate"
75 name="${BASH_REMATCH[1]}"