1 |
commit: d3597bc14c65849fde63ca9d96be1e579e297146 |
2 |
Author: Doug Goldstein <cardoe <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Jun 29 14:30:02 2016 +0000 |
4 |
Commit: Doug Goldstein <cardoe <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Jun 29 21:59:11 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d3597bc1 |
7 |
|
8 |
eclass: initial cargo support eclass |
9 |
|
10 |
Base eclass for cargo that handles setting up the cargo registry and |
11 |
provides a way to fetch crates. |
12 |
|
13 |
Signed-off-by: Doug Goldstein <cardoe <AT> gentoo.org> |
14 |
|
15 |
eclass/cargo.eclass | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 |
1 file changed, 85 insertions(+) |
17 |
|
18 |
diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass |
19 |
new file mode 100644 |
20 |
index 0000000..8c5e00c |
21 |
--- /dev/null |
22 |
+++ b/eclass/cargo.eclass |
23 |
@@ -0,0 +1,85 @@ |
24 |
+# Copyright 1999-2016 Gentoo Foundation |
25 |
+# Distributed under the terms of the GNU General Public License v2 |
26 |
+# $Id$ |
27 |
+ |
28 |
+# @ECLASS: cargo.eclass |
29 |
+# @MAINTAINER: |
30 |
+# rust@g.o |
31 |
+# @AUTHOR: |
32 |
+# Doug Goldstein <cardoe@g.o> |
33 |
+# @BLURB: common functions and variables for cargo builds |
34 |
+ |
35 |
+if [[ -z ${_CARGO_ECLASS} ]]; then |
36 |
+_CARGO_ECLASS=1 |
37 |
+ |
38 |
+case ${EAPI} in |
39 |
+ 6) : ;; |
40 |
+ *) die "EAPI=${EAPI:-0} is not supported" ;; |
41 |
+esac |
42 |
+ |
43 |
+EXPORT_FUNCTIONS src_unpack |
44 |
+ |
45 |
+ECARGO_HOME="${WORKDIR}/cargo_home" |
46 |
+ECARGO_REGISTRY="github.com-88ac128001ac3a9a" |
47 |
+ECARGO_INDEX="${ECARGO_HOME}/registry/index/${ECARGO_REGISTRY}" |
48 |
+ECARGO_SRC="${ECARGO_HOME}/registry/src/${ECARGO_REGISTRY}" |
49 |
+ECARGO_CACHE="${ECARGO_HOME}/registry/cache/${ECARGO_REGISTRY}" |
50 |
+ |
51 |
+# @FUNCTION: cargo_crate_uris |
52 |
+# @DESCRIPTION: |
53 |
+# Generates the URIs to put in SRC_URI to help fetch dependencies. |
54 |
+cargo_crate_uris() { |
55 |
+ for crate in $*; do |
56 |
+ local name version url |
57 |
+ name="${crate%-*}" |
58 |
+ version="${crate##*-}" |
59 |
+ url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate" |
60 |
+ echo $url |
61 |
+ done |
62 |
+} |
63 |
+ |
64 |
+# @FUNCTION: cargo_src_unpack |
65 |
+# @DESCRIPTION: |
66 |
+# Unpacks the package and the cargo registry |
67 |
+cargo_src_unpack() { |
68 |
+ debug-print-function ${FUNCNAME} "$@" |
69 |
+ |
70 |
+ mkdir -p "${ECARGO_INDEX}" || die |
71 |
+ mkdir -p "${ECARGO_CACHE}" || die |
72 |
+ mkdir -p "${ECARGO_SRC}" || die |
73 |
+ mkdir -p "${S}" || die |
74 |
+ |
75 |
+ local archive |
76 |
+ for archive in ${A}; do |
77 |
+ case "${archive}" in |
78 |
+ *.crate) |
79 |
+ ebegin "Unpacking ${archive}" |
80 |
+ cp "${DISTDIR}"/${archive} "${ECARGO_CACHE}/" || die |
81 |
+ tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_SRC}/" || die |
82 |
+ eend $? |
83 |
+ ;; |
84 |
+ cargo-snapshot*) |
85 |
+ ebegin "Unpacking ${archive}" |
86 |
+ mkdir -p "${S}"/target/snapshot |
87 |
+ tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die |
88 |
+ # cargo's makefile needs this otherwise it will try to |
89 |
+ # download it |
90 |
+ touch "${S}"/target/snapshot/bin/cargo || die |
91 |
+ eend $? |
92 |
+ ;; |
93 |
+ cargo-registry*) |
94 |
+ ebegin "Unpacking ${archive}" |
95 |
+ tar -xzf "${DISTDIR}"/${archive} -C "${ECARGO_INDEX}" --strip-components 1 || die |
96 |
+ # prevent cargo from attempting to download this again |
97 |
+ touch "${ECARGO_INDEX}"/.cargo-index-lock || die |
98 |
+ eend $? |
99 |
+ ;; |
100 |
+ *) |
101 |
+ unpack ${archive} |
102 |
+ ;; |
103 |
+ esac |
104 |
+ done |
105 |
+} |
106 |
+ |
107 |
+ |
108 |
+fi |