summaryrefslogtreecommitdiff
blob: 8c5e00ccb8f6ac367b4ffc5b7e4371a004ae1786 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

# @ECLASS: cargo.eclass
# @MAINTAINER:
# rust@gentoo.org
# @AUTHOR:
# Doug Goldstein <cardoe@gentoo.org>
# @BLURB: common functions and variables for cargo builds

if [[ -z ${_CARGO_ECLASS} ]]; then
_CARGO_ECLASS=1

case ${EAPI} in
	6) : ;;
	*) die "EAPI=${EAPI:-0} is not supported" ;;
esac

EXPORT_FUNCTIONS src_unpack

ECARGO_HOME="${WORKDIR}/cargo_home"
ECARGO_REGISTRY="github.com-88ac128001ac3a9a"
ECARGO_INDEX="${ECARGO_HOME}/registry/index/${ECARGO_REGISTRY}"
ECARGO_SRC="${ECARGO_HOME}/registry/src/${ECARGO_REGISTRY}"
ECARGO_CACHE="${ECARGO_HOME}/registry/cache/${ECARGO_REGISTRY}"

# @FUNCTION: cargo_crate_uris
# @DESCRIPTION:
# Generates the URIs to put in SRC_URI to help fetch dependencies.
cargo_crate_uris() {
	for crate in $*; do
		local name version url
		name="${crate%-*}"
		version="${crate##*-}"
		url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate"
		echo $url
	done
}

# @FUNCTION: cargo_src_unpack
# @DESCRIPTION:
# Unpacks the package and the cargo registry
cargo_src_unpack() {
	debug-print-function ${FUNCNAME} "$@"

	mkdir -p "${ECARGO_INDEX}" || die
	mkdir -p "${ECARGO_CACHE}" || die
	mkdir -p "${ECARGO_SRC}" || die
	mkdir -p "${S}" || die

	local archive
	for archive in ${A}; do
		case "${archive}" in
			*.crate)
				ebegin "Unpacking ${archive}"
				cp "${DISTDIR}"/${archive} "${ECARGO_CACHE}/" || die
				tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_SRC}/" || die
				eend $?
				;;
			cargo-snapshot*)
				ebegin "Unpacking ${archive}"
				mkdir -p "${S}"/target/snapshot
				tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die
				# cargo's makefile needs this otherwise it will try to
				# download it
				touch "${S}"/target/snapshot/bin/cargo || die
				eend $?
				;;
			cargo-registry*)
				ebegin "Unpacking ${archive}"
				tar -xzf "${DISTDIR}"/${archive} -C "${ECARGO_INDEX}" --strip-components 1 || die
				# prevent cargo from attempting to download this again
				touch "${ECARGO_INDEX}"/.cargo-index-lock || die
				eend $?
				;;
			*)
				unpack ${archive}
				;;
		esac
	done
}


fi