Gentoo Archives: gentoo-dev

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

Attachments

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

Replies