Gentoo Archives: gentoo-dev

From: Georgy Yakovlev <gyakovlev@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] [PATCH] cargo.eclass: allow passing additional arguments to cargo
Date: Thu, 03 Jan 2019 05:46:49
Message-Id: 7129439.jzGIACW4vF@reaper
In Reply to: Re: [gentoo-dev] [PATCH] cargo.eclass: allow passing additional arguments to cargo by "Michał Górny"
1 On Wednesday, January 2, 2019 8:52:45 PM PST Michał Górny wrote:
2 > On Wed, 2019-01-02 at 13:58 -0800, Georgy Yakovlev wrote:
3 > > This adds 2 eclass variables
4 > >
5 > > ECARGO_BUILD_FLAGS
6 > > ECARGO_INSTALL_FLAGS
7 > >
8 > > contents will be passed to "cargo build" and "cargo install" calls in
9 > > cargo_src_compile() and cargo_src_install() respectively.
10 > >
11 > > Closes: https://github.com/gentoo/gentoo/pull/10725
12 > > Signed-off-by: Georgy Yakovlev <gyakovlev@g.o>
13 > > ---
14 > > eclass/cargo.eclass | 25 +++++++++++++++++++++++--
15 > > 1 file changed, 23 insertions(+), 2 deletions(-)
16 > >
17 > > diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
18 > > index 50f7830c51b..ea58c63b456 100644
19 > > --- a/eclass/cargo.eclass
20 > > +++ b/eclass/cargo.eclass
21 > > @@ -1,142 +1,163 @@
22 > > # Copyright 1999-2018 Gentoo Authors
23 > > # Distributed under the terms of the GNU General Public License v2
24 > >
25 > > # @ECLASS: cargo.eclass
26 > > # @MAINTAINER:
27 > > # rust@g.o
28 > > # @AUTHOR:
29 > > # Doug Goldstein <cardoe@g.o>
30 > > # @SUPPORTED_EAPIS: 6 7
31 > > # @BLURB: common functions and variables for cargo builds
32 > >
33 > > if [[ -z ${_CARGO_ECLASS} ]]; then
34 > > _CARGO_ECLASS=1
35 > >
36 > > CARGO_DEPEND=""
37 > > [[ ${CATEGORY}/${PN} != dev-util/cargo ]] && CARGO_DEPEND="virtual/cargo"
38 > >
39 > > case ${EAPI} in
40 > > 6) DEPEND="${CARGO_DEPEND}";;
41 > > 7) BDEPEND="${CARGO_DEPEND}";;
42 > > *) die "EAPI=${EAPI:-0} is not supported" ;;
43 > > esac
44 > >
45 > > inherit multiprocessing
46 > >
47 > > EXPORT_FUNCTIONS src_unpack src_compile src_install
48 > >
49 > > IUSE="${IUSE} debug"
50 > >
51 > > ECARGO_HOME="${WORKDIR}/cargo_home"
52 > > ECARGO_VENDOR="${ECARGO_HOME}/gentoo"
53 > >
54 > > +# @ECLASS-VARIABLE: ECARGO_BUILD_FLAGS
55 > > +# @DEFAULT_UNSET
56 > > +# @DESCRIPTION:
57 > > +# This allows to pass additional build flags to cargo in cargo_src_compile()
58 > > +#
59 > > +# Example:
60 > > +# @CODE
61 > > +# ECARGO_BUILD_FLAGS="$(usex pcre "--features pcre2" "")"
62 > > +# @CODE
63 > > +
64 > > +# @ECLASS-VARIABLE: ECARGO_INSTALL_FLAGS
65 > > +# @DEFAULT_UNSET
66 > > +# @DESCRIPTION:
67 > > +# This allows to pass additional install flags to cargo in cargo_src_install()
68 > > +#
69 > > +# Example:
70 > > +# @CODE
71 > > +# ECARGO_INSTALL_FLAGS="--path=."
72 > > +# @CODE
73 > > +
74 > > +
75 > > # @FUNCTION: cargo_crate_uris
76 > > # @DESCRIPTION:
77 > > # Generates the URIs to put in SRC_URI to help fetch dependencies.
78 > > cargo_crate_uris() {
79 > > local crate
80 > > for crate in "$@"; do
81 > > local name version url pretag
82 > > name="${crate%-*}"
83 > > version="${crate##*-}"
84 > > pretag="^[a-zA-Z]+"
85 > > if [[ $version =~ $pretag ]]; then
86 > > version="${name##*-}-${version}"
87 > > name="${name%-*}"
88 > > fi
89 > > url="https://crates.io/api/v1/crates/${name}/${version}/download -> ${crate}.crate"
90 > > echo "${url}"
91 > > done
92 > > }
93 > >
94 > > # @FUNCTION: cargo_src_unpack
95 > > # @DESCRIPTION:
96 > > # Unpacks the package and the cargo registry
97 > > cargo_src_unpack() {
98 > > debug-print-function ${FUNCNAME} "$@"
99 > >
100 > > mkdir -p "${ECARGO_VENDOR}" || die
101 > > mkdir -p "${S}" || die
102 > >
103 > > local archive shasum pkg
104 > > for archive in ${A}; do
105 > > case "${archive}" in
106 > > *.crate)
107 > > ebegin "Loading ${archive} into Cargo registry"
108 > > tar -xf "${DISTDIR}"/${archive} -C "${ECARGO_VENDOR}/" || die
109 > > # generate sha256sum of the crate itself as cargo needs this
110 > > shasum=$(sha256sum "${DISTDIR}"/${archive} | cut -d ' ' -f 1)
111 > > pkg=$(basename ${archive} .crate)
112 > > cat <<- EOF > ${ECARGO_VENDOR}/${pkg}/.cargo-checksum.json
113 > > {
114 > > "package": "${shasum}",
115 > > "files": {}
116 > > }
117 > > EOF
118 > > # if this is our target package we need it in ${WORKDIR} too
119 > > # to make ${S} (and handle any revisions too)
120 > > if [[ ${P} == ${pkg}* ]]; then
121 > > tar -xf "${DISTDIR}"/${archive} -C "${WORKDIR}" || die
122 > > fi
123 > > eend $?
124 > > ;;
125 > > cargo-snapshot*)
126 > > ebegin "Unpacking ${archive}"
127 > > mkdir -p "${S}"/target/snapshot
128 > > tar -xzf "${DISTDIR}"/${archive} -C "${S}"/target/snapshot --strip-components 2 || die
129 > > # cargo's makefile needs this otherwise it will try to
130 > > # download it
131 > > touch "${S}"/target/snapshot/bin/cargo || die
132 > > eend $?
133 > > ;;
134 > > *)
135 > > unpack ${archive}
136 > > ;;
137 > > esac
138 > > done
139 > >
140 > > cargo_gen_config
141 > > }
142 > >
143 > > # @FUNCTION: cargo_gen_config
144 > > # @DESCRIPTION:
145 > > # Generate the $CARGO_HOME/config necessary to use our local registry
146 > > cargo_gen_config() {
147 > > debug-print-function ${FUNCNAME} "$@"
148 > >
149 > > cat <<- EOF > "${ECARGO_HOME}/config"
150 > > [source.gentoo]
151 > > directory = "${ECARGO_VENDOR}"
152 > >
153 > > [source.crates-io]
154 > > replace-with = "gentoo"
155 > > local-registry = "/nonexistant"
156 > > EOF
157 > > }
158 > >
159 > > # @FUNCTION: cargo_src_compile
160 > > # @DESCRIPTION:
161 > > # Build the package using cargo build
162 > > cargo_src_compile() {
163 > > debug-print-function ${FUNCNAME} "$@"
164 > >
165 > > export CARGO_HOME="${ECARGO_HOME}"
166 > >
167 > > cargo build -j $(makeopts_jobs) $(usex debug "" --release) \
168 > > - || die "cargo build failed"
169 > > + ${ECARGO_BUILD_FLAGS} || die "cargo build failed"
170 > > }
171 > >
172 > > # @FUNCTION: cargo_src_install
173 > > # @DESCRIPTION:
174 > > # Installs the binaries generated by cargo
175 > > cargo_src_install() {
176 > > debug-print-function ${FUNCNAME} "$@"
177 > >
178 > > cargo install -j $(makeopts_jobs) --root="${D}/usr" $(usex debug --debug "") \
179 > > - || die "cargo install failed"
180 > > + ${ECARGO_INSTALL_FLAGS} || die "cargo install failed"
181 > > rm -f "${D}/usr/.crates.toml"
182 > >
183 > > [ -d "${S}/man" ] && doman "${S}/man" || return 0
184 > > }
185 > >
186 > > fi
187 >
188 > Can't you just pass "${@}" to both?
189 >
190 >
191 something like this?
192
193 diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
194 index 50f7830c51b..aa889751fef 100644
195 --- a/eclass/cargo.eclass
196 +++ b/eclass/cargo.eclass
197 @@ -122,7 +122,7 @@ cargo_src_compile() {
198
199 export CARGO_HOME="${ECARGO_HOME}"
200
201 - cargo build -j $(makeopts_jobs) $(usex debug "" --release) \
202 + cargo build -j $(makeopts_jobs) $(usex debug "" --release) "${@}" \
203 || die "cargo build failed"
204 }
205
206 @@ -132,7 +132,7 @@ cargo_src_compile() {
207 cargo_src_install() {
208 debug-print-function ${FUNCNAME} "$@"
209
210 - cargo install -j $(makeopts_jobs) --root="${D}/usr" $(usex debug --debug "") \
211 + cargo install -j $(makeopts_jobs) --root="${D}/usr" $(usex debug --debug "") "${@}" \
212 || die "cargo install failed"
213 rm -f "${D}/usr/.crates.toml"
214
215 yeah, it works.
216 it's a bit different to what I wanted but it's very simple and clean. I like it.
217
218
219 --
220 Georgy Yakovlev
221 Gentoo Linux Developer

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies