Gentoo Archives: gentoo-commits

From: Doug Goldstein <cardoe@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Wed, 30 Nov 2016 17:19:08
Message-Id: 1480526271.29ee4443ea44db1227b22e0b68b1351686a22c5a.cardoe@gentoo
1 commit: 29ee4443ea44db1227b22e0b68b1351686a22c5a
2 Author: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
3 AuthorDate: Fri Nov 25 15:46:24 2016 +0000
4 Commit: Doug Goldstein <cardoe <AT> gentoo <DOT> org>
5 CommitDate: Wed Nov 30 17:17:51 2016 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=29ee4443
7
8 eclass/cargo: support cargo dependency vendoring
9
10 Add support for newer dependency vendoring which allows us to download
11 the dependencies with the package manager and just have cargo use that
12 to compile the package.
13
14 Signed-off-by: Doug Goldstein <cardoe <AT> gentoo.org>
15
16 eclass/cargo.eclass | 57 +++++++++++++++++++++++++++++++++++------------------
17 1 file changed, 38 insertions(+), 19 deletions(-)
18
19 diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
20 index 19c66c8..f2b2b12 100644
21 --- a/eclass/cargo.eclass
22 +++ b/eclass/cargo.eclass
23 @@ -22,11 +22,7 @@ EXPORT_FUNCTIONS src_unpack src_compile src_install
24 IUSE="${IUSE} debug"
25
26 ECARGO_HOME="${WORKDIR}/cargo_home"
27 -#ECARGO_REPO="github.com-88ac128001ac3a9a"
28 -ECARGO_REPO="github.com-1ecc6299db9ec823"
29 -ECARGO_INDEX="${ECARGO_HOME}/registry/index/${ECARGO_REPO}"
30 -ECARGO_SRC="${ECARGO_HOME}/registry/src/${ECARGO_REPO}"
31 -ECARGO_CACHE="${ECARGO_HOME}/registry/cache/${ECARGO_REPO}"
32 +ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
33
34 # @FUNCTION: cargo_crate_uris
35 # @DESCRIPTION:
36 @@ -47,18 +43,29 @@ cargo_crate_uris() {
37 cargo_src_unpack() {
38 debug-print-function ${FUNCNAME} "$@"
39
40 - mkdir -p "${ECARGO_INDEX}" || die
41 - mkdir -p "${ECARGO_CACHE}" || die
42 - mkdir -p "${ECARGO_SRC}" || die
43 + mkdir -p "${ECARGO_VENDOR}" || die
44 mkdir -p "${S}" || die
45
46 local archive
47 for archive in ${A}; do
48 case "${archive}" in
49 *.crate)
50 - ebegin "Unpacking ${archive}"
51 - cp "${DISTDIR}"/${archive} "${ECARGO_CACHE}/" || die
52 - tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_SRC}/" || die
53 + ebegin "Loading ${archive} into Cargo registry"
54 + tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_VENDOR}/" || die
55 + # generate sha256sum of the crate itself as cargo needs this
56 + shasum=$(sha256sum "${DISTDIR}"/${archive} | cut -d ' ' -f 1)
57 + pkg=$(basename ${archive} .crate)
58 + cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json
59 + {
60 + "package": "${shasum}",
61 + "files": {}
62 + }
63 + EOF
64 + # if this is our target package we need it in ${WORKDIR} too
65 + # to make ${S} (and handle any revisions too)
66 + if [[ ${P} == ${pkg}* ]]; then
67 + tar -xf "${DISTDIR}"/${archive} -C "${WORKDIR}" || die
68 + fi
69 eend $?
70 ;;
71 cargo-snapshot*)
72 @@ -70,18 +77,29 @@ cargo_src_unpack() {
73 touch "${S}"/target/snapshot/bin/cargo || die
74 eend $?
75 ;;
76 - cargo-registry*)
77 - ebegin "Unpacking ${archive}"
78 - tar -xzf "${DISTDIR}"/${archive} -C "${ECARGO_INDEX}" --strip-components 1 || die
79 - # prevent cargo from attempting to download this again
80 - touch "${ECARGO_INDEX}"/.cargo-index-lock || die
81 - eend $?
82 - ;;
83 *)
84 unpack ${archive}
85 ;;
86 esac
87 done
88 +
89 + cargo_gen_config
90 +}
91 +
92 +# @FUNCTION: cargo_gen_config
93 +# @DESCRIPTION:
94 +# Generate the $CARGO_HOME/config necessary to use our local registry
95 +cargo_gen_config() {
96 + debug-print-function ${FUNCNAME} "$@"
97 +
98 + cat <<- EOF > ${ECARGO_HOME}/config
99 + [source.gentoo]
100 + directory = "${ECARGO_VENDOR}"
101 +
102 + [source.crates-io]
103 + replace-with = "gentoo"
104 + local-registry = "/nonexistant"
105 + EOF
106 }
107
108 # @FUNCTION: cargo_src_compile
109 @@ -92,7 +110,8 @@ cargo_src_compile() {
110
111 export CARGO_HOME="${ECARGO_HOME}"
112
113 - cargo build -v $(usex debug "" --release)
114 + cargo build -v $(usex debug "" --release) \
115 + || die "cargo build failed"
116 }
117
118 # @FUNCTION: cargo_src_install