Gentoo Archives: gentoo-dev

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

Attachments

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

Replies

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