Gentoo Archives: gentoo-dev

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-dev@l.g.o
Cc: rust@g.o, Georgy Yakovlev <gyakovlev@g.o>
Subject: [gentoo-dev] [PATCH] cargo.eclass: add cargo_live_src_unpack()
Date: Thu, 29 Aug 2019 05:26:41
Message-Id: 20190829052613.56890-1-gyakovlev@gentoo.org
1 This function will allow using 'cargo fetch' during src_fetch
2 Since only new cargo supports that, all live packages will
3 have to depend on >=rust-1.37.0
4
5 This enables us to ship live rust packages,
6 cargo fetch will download all crates and vendor them for offline
7 phases.
8
9 here's an example of src_unpack()
10
11 src_unpack() {
12 if [[ "${PV}" == *9999* ]]; then
13 git-r3_src_unpack
14 cargo_live_src_unpack
15 else
16 cargo_src_unpack
17 fi
18 }
19
20 Signed-off-by: Georgy Yakovlev <gyakovlev@g.o>
21 ---
22 eclass/cargo.eclass | 27 ++++++++++++++++++++++++++-
23 1 file changed, 26 insertions(+), 1 deletion(-)
24
25 diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
26 index b16e0e9d633..44d11cdb838 100644
27 --- a/eclass/cargo.eclass
28 +++ b/eclass/cargo.eclass
29 @@ -12,7 +12,12 @@
30 if [[ -z ${_CARGO_ECLASS} ]]; then
31 _CARGO_ECLASS=1
32
33 -CARGO_DEPEND="virtual/cargo"
34 +if [[ ${PV} == *9999* ]]; then
35 + # we need at least this for cargo vendor subommand
36 + CARGO_DEPEND=">=virtual/cargo-1.37.0"
37 +else
38 + CARGO_DEPEND="virtual/cargo"
39 +fi
40
41 case ${EAPI} in
42 6) DEPEND="${CARGO_DEPEND}";;
43 @@ -97,6 +102,26 @@ cargo_src_unpack() {
44 cargo_gen_config
45 }
46
47 +# @FUNCTION: cargo_live_src_unpack
48 +# @DESCRIPTION:
49 +# Runs 'cargo fetch' and vendors downloaded crates for offline use, used in live ebuilds
50 +
51 +cargo_live_src_unpack() {
52 + debug-print-function ${FUNCNAME} "$@"
53 +
54 + [[ "${PV}" == *9999* ]] || die "${FUNCNAME} only allowed in live/9999 ebuilds"
55 + [[ "${EBUILD_PHASE}" == unpack ]] || die "${FUNCNAME} only allowed in src_unpack"
56 +
57 + mkdir -p "${S}" || die
58 +
59 + pushd "${S}" > /dev/null || die
60 + CARGO_HOME="${ECARGO_HOME}" cargo fetch || die
61 + CARGO_HOME="${ECARGO_HOME}" cargo vendor "${ECARGO_VENDOR}" || die
62 + popd > /dev/null || die
63 +
64 + cargo_gen_config
65 +}
66 +
67 # @FUNCTION: cargo_gen_config
68 # @DESCRIPTION:
69 # Generate the $CARGO_HOME/config necessary to use our local registry
70 --
71 2.23.0

Replies