Gentoo Archives: gentoo-dev

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

Replies