sys-block/btrace: Merge GitHub PR #1716
[gentoo.git] / eclass / cargo.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: cargo.eclass
6 # @MAINTAINER:
7 # rust@gentoo.org
8 # @AUTHOR:
9 # Doug Goldstein <cardoe@gentoo.org>
10 # @BLURB: common functions and variables for cargo builds
11
12 if [[ -z ${_CARGO_ECLASS} ]]; then
13 _CARGO_ECLASS=1
14
15 case ${EAPI} in
16         6) : ;;
17         *) die "EAPI=${EAPI:-0} is not supported" ;;
18 esac
19
20 EXPORT_FUNCTIONS src_unpack
21
22 ECARGO_HOME="${WORKDIR}/cargo_home"
23 ECARGO_REPO="github.com-88ac128001ac3a9a"
24 ECARGO_INDEX="${ECARGO_HOME}/registry/index/${ECARGO_REPO}"
25 ECARGO_SRC="${ECARGO_HOME}/registry/src/${ECARGO_REPO}"
26 ECARGO_CACHE="${ECARGO_HOME}/registry/cache/${ECARGO_REPO}"
27
28 # @FUNCTION: cargo_crate_uris
29 # @DESCRIPTION:
30 # Generates the URIs to put in SRC_URI to help fetch dependencies.
31 cargo_crate_uris() {
32         for crate in $*; do
33                 local name version url
34                 name="${crate%-*}"
35                 version="${crate##*-}"
36                 url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate"
37                 echo $url
38         done
39 }
40
41 # @FUNCTION: cargo_src_unpack
42 # @DESCRIPTION:
43 # Unpacks the package and the cargo registry
44 cargo_src_unpack() {
45         debug-print-function ${FUNCNAME} "$@"
46
47         mkdir -p "${ECARGO_INDEX}" || die
48         mkdir -p "${ECARGO_CACHE}" || die
49         mkdir -p "${ECARGO_SRC}" || die
50         mkdir -p "${S}" || die
51
52         local archive
53         for archive in ${A}; do
54                 case "${archive}" in
55                         *.crate)
56                                 ebegin "Unpacking ${archive}"
57                                 cp "${DISTDIR}"/${archive} "${ECARGO_CACHE}/" || die
58                                 tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_SRC}/" || die
59                                 eend $?
60                                 ;;
61                         cargo-snapshot*)
62                                 ebegin "Unpacking ${archive}"
63                                 mkdir -p "${S}"/target/snapshot
64                                 tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die
65                                 # cargo's makefile needs this otherwise it will try to
66                                 # download it
67                                 touch "${S}"/target/snapshot/bin/cargo || die
68                                 eend $?
69                                 ;;
70                         cargo-registry*)
71                                 ebegin "Unpacking ${archive}"
72                                 tar -xzf "${DISTDIR}"/${archive} -C "${ECARGO_INDEX}" --strip-components 1 || die
73                                 # prevent cargo from attempting to download this again
74                                 touch "${ECARGO_INDEX}"/.cargo-index-lock || die
75                                 eend $?
76                                 ;;
77                         *)
78                                 unpack ${archive}
79                                 ;;
80                 esac
81         done
82 }
83
84
85 fi