Gentoo Archives: gentoo-dev

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-dev@l.g.o
Cc: Georgy Yakovlev <gyakovlev@g.o>
Subject: [gentoo-dev] [PATCH 2/2] cargo.eclass: add standard src_test
Date: Mon, 07 Jan 2019 04:02:03
Message-Id: 20190107040122.6874-2-gyakovlev@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/2] cargo.eclass: allow passing additional arguments to cargo by Georgy Yakovlev
1 But not set IUSE=test by default
2
3 Signed-off-by: Georgy Yakovlev <gyakovlev@g.o>
4 This is pretty straightforward change, just adds standard src_test for
5 cargo
6
7 ---
8 eclass/cargo.eclass | 12 +++++++++++-
9 1 file changed, 11 insertions(+), 1 deletion(-)
10
11 diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
12 index ee17f2af9d9..c576c8e8066 100644
13 --- a/eclass/cargo.eclass
14 +++ b/eclass/cargo.eclass
15 @@ -1,142 +1,152 @@
16 # Copyright 1999-2019 Gentoo Authors
17 # Distributed under the terms of the GNU General Public License v2
18
19 # @ECLASS: cargo.eclass
20 # @MAINTAINER:
21 # rust@g.o
22 # @AUTHOR:
23 # Doug Goldstein <cardoe@g.o>
24 # @SUPPORTED_EAPIS: 6 7
25 # @BLURB: common functions and variables for cargo builds
26
27 if [[ -z ${_CARGO_ECLASS} ]]; then
28 _CARGO_ECLASS=1
29
30 CARGO_DEPEND=""
31 [[ ${CATEGORY}/${PN} != dev-util/cargo ]] && CARGO_DEPEND="virtual/cargo"
32
33 case ${EAPI} in
34 6) DEPEND="${CARGO_DEPEND}";;
35 7) BDEPEND="${CARGO_DEPEND}";;
36 *) die "EAPI=${EAPI:-0} is not supported" ;;
37 esac
38
39 inherit multiprocessing
40
41 -EXPORT_FUNCTIONS src_unpack src_compile src_install
42 +EXPORT_FUNCTIONS src_unpack src_compile src_install src_test
43
44 IUSE="${IUSE} debug"
45
46 ECARGO_HOME="${WORKDIR}/cargo_home"
47 ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
48
49 # @FUNCTION: cargo_crate_uris
50 # @DESCRIPTION:
51 # Generates the URIs to put in SRC_URI to help fetch dependencies.
52 cargo_crate_uris() {
53 local crate
54 for crate in "$@"; do
55 local name version url pretag
56 name="${crate%-*}"
57 version="${crate##*-}"
58 pretag="^[a-zA-Z]+"
59 if [[ $version =~ $pretag ]]; then
60 version="${name##*-}-${version}"
61 name="${name%-*}"
62 fi
63 url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate"
64 echo "${url}"
65 done
66 }
67
68 # @FUNCTION: cargo_src_unpack
69 # @DESCRIPTION:
70 # Unpacks the package and the cargo registry
71 cargo_src_unpack() {
72 debug-print-function ${FUNCNAME} "$@"
73
74 mkdir -p "${ECARGO_VENDOR}" || die
75 mkdir -p "${S}" || die
76
77 local archive shasum pkg
78 for archive in ${A}; do
79 case "${archive}" in
80 *.crate)
81 ebegin "Loading ${archive} into Cargo registry"
82 tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_VENDOR}/" || die
83 # generate sha256sum of the crate itself as cargo needs this
84 shasum=$(sha256sum "${DISTDIR}"/${archive} | cut -d ' ' -f 1)
85 pkg=$(basename ${archive} .crate)
86 cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json
87 {
88 "package": "${shasum}",
89 "files": {}
90 }
91 EOF
92 # if this is our target package we need it in ${WORKDIR} too
93 # to make ${S} (and handle any revisions too)
94 if [[ ${P} == ${pkg}* ]]; then
95 tar -xf "${DISTDIR}"/${archive} -C "${WORKDIR}" || die
96 fi
97 eend $?
98 ;;
99 cargo-snapshot*)
100 ebegin "Unpacking ${archive}"
101 mkdir -p "${S}"/target/snapshot
102 tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die
103 # cargo's makefile needs this otherwise it will try to
104 # download it
105 touch "${S}"/target/snapshot/bin/cargo || die
106 eend $?
107 ;;
108 *)
109 unpack ${archive}
110 ;;
111 esac
112 done
113
114 cargo_gen_config
115 }
116
117 # @FUNCTION: cargo_gen_config
118 # @DESCRIPTION:
119 # Generate the $CARGO_HOME/config necessary to use our local registry
120 cargo_gen_config() {
121 debug-print-function ${FUNCNAME} "$@"
122
123 cat <<- EOF > "${ECARGO_HOME}/config"
124 [source.gentoo]
125 directory = "${ECARGO_VENDOR}"
126
127 [source.crates-io]
128 replace-with = "gentoo"
129 local-registry = "/nonexistant"
130 EOF
131 }
132
133 # @FUNCTION: cargo_src_compile
134 # @DESCRIPTION:
135 # Build the package using cargo build
136 cargo_src_compile() {
137 debug-print-function ${FUNCNAME} "$@"
138
139 export CARGO_HOME="${ECARGO_HOME}"
140
141 cargo build -j $(makeopts_jobs) $(usex debug "" --release) "${@}" \
142 || die "cargo build failed"
143 }
144
145 # @FUNCTION: cargo_src_install
146 # @DESCRIPTION:
147 # Installs the binaries generated by cargo
148 cargo_src_install() {
149 debug-print-function ${FUNCNAME} "$@"
150
151 cargo install -j $(makeopts_jobs) --root="${D}/usr" $(usex debug --debug "") "${@}" \
152 || die "cargo install failed"
153 rm -f "${D}/usr/.crates.toml"
154
155 [ -d "${S}/man" ] && doman "${S}/man" || return 0
156 }
157
158 +# @FUNCTION: cargo_src_test
159 +# @DESCRIPTION:
160 +# Test the package using cargo test
161 +cargo_src_test() {
162 + debug-print-function ${FUNCNAME} "$@"
163 +
164 + cargo test -j $(makeopts_jobs) $(usex debug "" --release) "${@}" \
165 + || die "cargo test failed"
166 +}
167 +
168 fi
169 --
170 2.20.1