Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: arthurzam@g.o, "Ulrich Müller" <ulm@g.o>
Subject: Re: [gentoo-dev] [PATCH 1/2] bzr.eclass: Reinstate eclass
Date: Sat, 25 Sep 2021 09:56:53
Message-Id: a8bec4bf0902f097ec33a0559a76485a7e694b0c.camel@gentoo.org
In Reply to: [gentoo-dev] [PATCH 1/2] bzr.eclass: Reinstate eclass by "Ulrich Müller"
1 On Sat, 2021-09-25 at 11:36 +0200, Ulrich Müller wrote:
2 > Taken from commit 320fcf034f5e860454e0d2a28ed405c5b843c60c.
3
4 I suppose you'll want to apply my comments as followup changes.
5
6 >
7 > Signed-off-by: Ulrich Müller <ulm@g.o>
8 > ---
9 > eclass/bzr.eclass | 289 ++++++++++++++++++++++++++++++++++++++++++++++
10 > 1 file changed, 289 insertions(+)
11 > create mode 100644 eclass/bzr.eclass
12 >
13 > diff --git a/eclass/bzr.eclass b/eclass/bzr.eclass
14 > new file mode 100644
15 > index 000000000000..fc1de9dc9ccc
16 > --- /dev/null
17 > +++ b/eclass/bzr.eclass
18 > @@ -0,0 +1,289 @@
19 > +# Copyright 1999-2019 Gentoo Authors
20 > +# Distributed under the terms of the GNU General Public License v2
21 > +
22 > +# @ECLASS: bzr.eclass
23 > +# @MAINTAINER:
24 > +# Ulrich Müller <ulm@g.o>
25 > +# @AUTHOR:
26 > +# Jorge Manuel B. S. Vicetto <jmbsvicetto@g.o>
27 > +# Mark Lee <bzr-gentoo-overlay@×××××××××××××××.com>
28 > +# Ulrich Müller <ulm@g.o>
29 > +# Christian Faulhammer <fauli@g.o>
30 > +# @SUPPORTED_EAPIS: 2 3 4 5 6 7
31 > +# @BLURB: generic fetching functions for the Bazaar VCS
32 > +# @DESCRIPTION:
33 > +# The bzr.eclass provides functions to fetch and unpack sources from
34 > +# repositories of the Bazaar distributed version control system.
35 > +# The eclass was originally derived from git.eclass.
36 > +#
37 > +# Note: Just set EBZR_REPO_URI to the URI of the branch and src_unpack()
38 > +# of this eclass will export the branch to ${WORKDIR}/${P}.
39 > +
40 > +EBZR="bzr.eclass"
41
42 Why do we need this? It seems as if someone is reinventing ${ECLASS}.
43
44 > +
45 > +PROPERTIES+=" live"
46 > +
47 > +if [[ ${EBZR_REPO_URI%%:*} = sftp ]]; then
48 > + DEPEND=">=dev-vcs/bzr-2.6.0[sftp]"
49 > +else
50 > + DEPEND=">=dev-vcs/bzr-2.6.0"
51 > +fi
52 > +
53 > +case ${EAPI:-0} in
54 > + 2|3|4|5|6) ;;
55 > + 7) BDEPEND="${DEPEND}"; DEPEND="" ;;
56 > + *) die "${EBZR}: EAPI ${EAPI:-0} is not supported" ;;
57 > +esac
58 > +
59 > +EXPORT_FUNCTIONS src_unpack
60 > +
61 > +# @ECLASS-VARIABLE: EBZR_STORE_DIR
62
63 @USER_VARIABLE?
64
65 > +# @DESCRIPTION:
66 > +# The directory to store all fetched Bazaar live sources.
67 > +: ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/bzr-src}
68 > +
69 > +# @ECLASS-VARIABLE: EBZR_UNPACK_DIR
70 > +# @DESCRIPTION:
71 > +# The working directory where the sources are copied to.
72 > +: ${EBZR_UNPACK_DIR:=${WORKDIR}/${P}}
73 > +
74 > +# @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD
75 > +# @DESCRIPTION:
76 > +# The Bazaar command to initialise a shared repository.
77 > +: ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"}
78 > +
79 > +# @ECLASS-VARIABLE: EBZR_FETCH_CMD
80 > +# @DESCRIPTION:
81 > +# The Bazaar command to fetch the sources.
82 > +: ${EBZR_FETCH_CMD:="bzr branch --no-tree"}
83 > +
84 > +# @ECLASS-VARIABLE: EBZR_UPDATE_CMD
85 > +# @DESCRIPTION:
86 > +# The Bazaar command to update the sources.
87 > +: ${EBZR_UPDATE_CMD:="bzr pull --overwrite-tags"}
88 > +
89 > +# @ECLASS-VARIABLE: EBZR_EXPORT_CMD
90 > +# @DESCRIPTION:
91 > +# The Bazaar command to export a branch.
92 > +: ${EBZR_EXPORT_CMD:="bzr export"}
93 > +
94 > +# @ECLASS-VARIABLE: EBZR_CHECKOUT_CMD
95 > +# @DESCRIPTION:
96 > +# The Bazaar command to checkout a branch.
97 > +: ${EBZR_CHECKOUT_CMD:="bzr checkout --lightweight -q"}
98 > +
99 > +# @ECLASS-VARIABLE: EBZR_REVNO_CMD
100 > +# @DESCRIPTION:
101 > +# The Bazaar command to list a revision number of the branch.
102 > +: ${EBZR_REVNO_CMD:="bzr revno"}
103
104 Are you sure that having these overrides is a good idea? Your followup
105 patch pretty much proves that every ebuild redefining them would get
106 broken by switch to breezy.
107
108 > +
109 > +# @ECLASS-VARIABLE: EBZR_OPTIONS
110 > +# @DEFAULT_UNSET
111 > +# @DESCRIPTION:
112 > +# The options passed to the fetch and update commands.
113
114 Is this intended to be set by ebuild or by user?
115
116 > +
117 > +# @ECLASS-VARIABLE: EBZR_REPO_URI
118 > +# @DEFAULT_UNSET
119 > +# @REQUIRED
120 > +# @DESCRIPTION:
121 > +# The repository URI for the source package.
122 > +#
123 > +# Note: If the ebuild uses an sftp:// URI, then the eclass will depend
124 > +# on dev-vcs/bzr[sftp].
125 > +
126 > +# @ECLASS-VARIABLE: EBZR_INITIAL_URI
127 > +# @DEFAULT_UNSET
128 > +# @DESCRIPTION:
129 > +# The URI used for initial branching of the source repository. If this
130 > +# variable is set, the initial branch will be cloned from the location
131 > +# specified, followed by a pull from ${EBZR_REPO_URI}. This is intended
132 > +# for special cases, e.g. when download from the original repository is
133 > +# slow, but a fast mirror exists but may be out of date.
134 > +#
135 > +# Normally, this variable needs not be set.
136 > +
137 > +# @ECLASS-VARIABLE: EBZR_PROJECT
138 > +# @DESCRIPTION:
139 > +# The project name of your ebuild. Normally, the branch will be stored
140 > +# in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
141 > +#
142 > +# If EBZR_BRANCH is set (see below), then a shared repository will be
143 > +# created in that directory, and the branch will be located in
144 > +# ${EBZR_STORE_DIR}/${EBZR_PROJECT}/${EBZR_BRANCH}.
145 > +: ${EBZR_PROJECT:=${PN}}
146 > +
147 > +# @ECLASS-VARIABLE: EBZR_BRANCH
148 > +# @DEFAULT_UNSET
149 > +# @DESCRIPTION:
150 > +# The directory where to store the branch within a shared repository,
151 > +# relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
152 > +#
153 > +# This variable should be set if there are several live ebuilds for
154 > +# different branches of the same upstream project. The branches can
155 > +# then share the same repository in EBZR_PROJECT, which will save both
156 > +# data traffic volume and disk space.
157 > +#
158 > +# If there is only a live ebuild for one single branch, EBZR_BRANCH
159 > +# needs not be set. In this case, the branch will be stored in a
160 > +# stand-alone repository directly in EBZR_PROJECT.
161 > +
162 > +# @ECLASS-VARIABLE: EBZR_REVISION
163 > +# @DEFAULT_UNSET
164 > +# @DESCRIPTION:
165 > +# Revision to fetch, defaults to the latest
166 > +# (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
167 > +
168 > +# @ECLASS-VARIABLE: EBZR_OFFLINE
169
170 @USER_VARIABLE?
171
172 > +# @DESCRIPTION:
173 > +# Set this variable to a non-empty value to disable automatic updating
174 > +# of a bzr source tree. This is intended to be set outside the ebuild
175 > +# by users.
176 > +: ${EBZR_OFFLINE=${EVCS_OFFLINE}}
177 > +
178 > +# @ECLASS-VARIABLE: EVCS_UMASK
179
180 @USER_VARIABLE?
181
182 > +# @DEFAULT_UNSET
183 > +# @DESCRIPTION:
184 > +# Set this variable to a custom umask. This is intended to be set by
185 > +# users. By setting this to something like 002, it can make life easier
186 > +# for people who do development as non-root (but are in the portage
187 > +# group), and then switch over to building with FEATURES=userpriv.
188 > +# Or vice-versa. Shouldn't be a security issue here as anyone who has
189 > +# portage group write access already can screw the system over in more
190 > +# creative ways.
191 > +
192 > +# @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
193 > +# @DEFAULT_UNSET
194 > +# @DESCRIPTION:
195 > +# If this variable is set to a non-empty value, EBZR_CHECKOUT_CMD will
196 > +# be used instead of EBZR_EXPORT_CMD to copy the sources to WORKDIR.
197 > +
198 > +# @FUNCTION: bzr_initial_fetch
199
200 @INTERNAL?
201
202 > +# @USAGE: <repository URI> <branch directory>
203 > +# @DESCRIPTION:
204 > +# Internal function, retrieves the source code from a repository for the
205 > +# first time, using ${EBZR_FETCH_CMD}.
206 > +bzr_initial_fetch() {
207 > + local repo_uri=$1 branch_dir=$2
208 > +
209 > + if [[ -n "${EBZR_OFFLINE}" ]]; then
210 > + ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
211
212 I dare say this is incorrect. If user says "no online operations", then
213 the eclass should just fail, not ignore the user.
214
215 > + fi
216 > +
217 > + # fetch branch
218 > + einfo "bzr branch start -->"
219 > + einfo " repository: ${repo_uri} => ${branch_dir}"
220 > +
221 > + ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
222 > + || die "${EBZR}: can't branch from ${repo_uri}"
223
224 You can replace the backslash with '||'.
225
226 > +}
227 > +
228 > +# @FUNCTION: bzr_update
229
230 @INTERNAL?
231
232 > +# @USAGE: <repository URI> <branch directory>
233 > +# @DESCRIPTION:
234 > +# Internal function, updates the source code from a repository, using
235 > +# ${EBZR_UPDATE_CMD}.
236 > +bzr_update() {
237 > + local repo_uri=$1 branch_dir=$2
238 > +
239 > + if [[ -n "${EBZR_OFFLINE}" ]]; then
240 > + einfo "skipping bzr pull -->"
241 > + einfo " repository: ${repo_uri}"
242 > + else
243 > + # update branch
244 > + einfo "bzr pull start -->"
245 > + einfo " repository: ${repo_uri}"
246 > +
247 > + pushd "${branch_dir}" > /dev/null \
248 > + || die "${EBZR}: can't chdir to ${branch_dir}"
249 > + ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repo_uri}" \
250 > + || die "${EBZR}: can't pull from ${repo_uri}"
251 > + popd > /dev/null || die "${EBZR}: popd failed"
252 > + fi
253 > +}
254 > +
255 > +# @FUNCTION: bzr_fetch
256 > +# @DESCRIPTION:
257 > +# Wrapper function to fetch sources from a Bazaar repository with
258 > +# bzr branch or bzr pull, depending on whether there is an existing
259 > +# working copy.
260 > +bzr_fetch() {
261 > + local repo_dir branch_dir
262 > + local save_sandbox_write=${SANDBOX_WRITE} save_umask
263 > +
264 > + [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
265 > +
266 > + if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
267 > + addwrite /
268 > + mkdir -p "${EBZR_STORE_DIR}" \
269 > + || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
270 > + SANDBOX_WRITE=${save_sandbox_write}
271
272 Looks like abusing implementation details.
273
274 > + fi
275 > +
276 > + pushd "${EBZR_STORE_DIR}" > /dev/null \
277 > + || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
278 > +
279 > + repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
280 > + branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
281 > +
282 > + if [[ -n ${EVCS_UMASK} ]]; then
283 > + save_umask=$(umask)
284 > + umask "${EVCS_UMASK}" || die
285 > + fi
286 > + addwrite "${EBZR_STORE_DIR}"
287 > +
288 > + if [[ ! -d ${branch_dir}/.bzr ]]; then
289 > + if [[ ${repo_dir} != "${branch_dir}" && ! -d ${repo_dir}/.bzr ]]; then
290 > + einfo "creating shared bzr repository: ${repo_dir}"
291 > + ${EBZR_INIT_REPO_CMD} "${repo_dir}" \
292 > + || die "${EBZR}: can't create shared repository"
293 > + fi
294 > +
295 > + if [[ -z ${EBZR_INITIAL_URI} ]]; then
296 > + bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
297 > + else
298 > + # Workaround for faster initial download. This clones the
299 > + # branch from a fast server (which may be out of date), and
300 > + # subsequently pulls from the slow original repository.
301 > + bzr_initial_fetch "${EBZR_INITIAL_URI}" "${branch_dir}"
302 > + if [[ ${EBZR_REPO_URI} != "${EBZR_INITIAL_URI}" ]]; then
303 > + EBZR_UPDATE_CMD="${EBZR_UPDATE_CMD} --remember --overwrite" \
304 > + EBZR_OFFLINE="" \
305
306 Why do you override EBZR_OFFLINE here?
307
308 > + bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
309 > + fi
310 > + fi
311 > + else
312 > + bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
313 > + fi
314 > +
315 > + # Restore sandbox environment and umask
316 > + SANDBOX_WRITE=${save_sandbox_write}
317 > + if [[ -n ${save_umask} ]]; then
318 > + umask "${save_umask}" || die
319 > + fi
320 > +
321 > + cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
322 > +
323 > + # Save revision number in environment. #311101
324 > + export EBZR_REVNO=$(${EBZR_REVNO_CMD})
325 > +
326 > + if [[ -n ${EBZR_WORKDIR_CHECKOUT} ]]; then
327 > + einfo "checking out ..."
328 > + ${EBZR_CHECKOUT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
329 > + . "${EBZR_UNPACK_DIR}" || die "${EBZR}: checkout failed"
330 > + else
331 > + einfo "exporting ..."
332 > + ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
333 > + "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
334 > + fi
335 > + einfo \
336 > + "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
337 > +
338 > + popd > /dev/null || die "${EBZR}: popd failed"
339 > +}
340 > +
341 > +# @FUNCTION: bzr_src_unpack
342 > +# @DESCRIPTION:
343 > +# Default src_unpack(), calls bzr_fetch.
344 > +bzr_src_unpack() {
345 > + bzr_fetch
346 > +}
347
348 --
349 Best regards,
350 Michał Górny

Replies

Subject Author
Re: [gentoo-dev] [PATCH 1/2] bzr.eclass: Reinstate eclass Ulrich Mueller <ulm@g.o>