Gentoo Archives: gentoo-commits

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