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