1 |
Hello, |
2 |
|
3 |
Please review an updated version of bzr.eclass. |
4 |
|
5 |
This will fix the following main problems: |
6 |
|
7 |
- So far, bzr.eclass used "lightweight" checkouts. These are optimised |
8 |
for a use case very different from ours, where the data it accesses |
9 |
is considered local. This led to massive performance problems (for |
10 |
example, 700 MB of transferred data for a one week's update of the |
11 |
Emacs repository). Therefore, the eclass has been changed to use |
12 |
branches instead: |
13 |
|
14 |
1) initial branch with "bzr branch --no-tree", |
15 |
2) subsequent updates with "bzr pull", |
16 |
3) export to ${WORKDIR} with "bzr export". |
17 |
|
18 |
- There was no possibility to share several branches in one project, |
19 |
which effectively meant that the same commits had to be downloaded |
20 |
multiple times. The eclass now offers the possibility to use shared |
21 |
repositories. |
22 |
|
23 |
Furthermore, I've taken the opportunity to do some smaller cleanups of |
24 |
the code. |
25 |
|
26 |
I've tested the eclass with all ebuilds in the portage tree that are |
27 |
inheriting bzr, and haven't noticed any problems. Especially, the |
28 |
transition from checkout to branch was smooth in all cases. |
29 |
|
30 |
The updated eclass is included below. Or, if you prefer a diff, you |
31 |
can find it here: |
32 |
<https://overlays.gentoo.org/proj/emacs/changeset?reponame=&new=1606%40emacs-overlay%2Feclass%2Fbzr.eclass&old=1593%40emacs-overlay%2Feclass%2Fbzr.eclass> |
33 |
|
34 |
Ulrich |
35 |
|
36 |
|
37 |
# Copyright 1999-2011 Gentoo Foundation |
38 |
# Distributed under the terms of the GNU General Public License v2 |
39 |
# $Header: /var/cvsroot/gentoo-x86/eclass/bzr.eclass,v 1.10 2010/11/07 22:44:35 fauli Exp $ |
40 |
# |
41 |
# @ECLASS: bzr.eclass |
42 |
# @MAINTAINER: |
43 |
# Jorge Manuel B. S. Vicetto <jmbsvicetto@g.o>, |
44 |
# Ulrich Mueller <ulm@g.o>, |
45 |
# Christian Faulhammer <fauli@g.o>, |
46 |
# Mark Lee <bzr-gentoo-overlay@×××××××××××××××.com>, |
47 |
# and anyone who wants to help |
48 |
# @BLURB: generic fetching functions for the Bazaar VCS |
49 |
# @DESCRIPTION: |
50 |
# The bzr.eclass provides functions to fetch, unpack, patch, and |
51 |
# bootstrap sources from repositories of the Bazaar distributed version |
52 |
# control system. The eclass was originally derived from git.eclass. |
53 |
# |
54 |
# Note: Just set EBZR_REPO_URI to the URI of the branch and src_unpack() |
55 |
# of this eclass will export the branch to ${WORKDIR}/${P}. |
56 |
|
57 |
inherit eutils |
58 |
|
59 |
EBZR="bzr.eclass" |
60 |
|
61 |
case "${EAPI:-0}" in |
62 |
0|1) EXPORT_FUNCTIONS src_unpack ;; |
63 |
*) EXPORT_FUNCTIONS src_unpack src_prepare ;; |
64 |
esac |
65 |
|
66 |
HOMEPAGE="http://bazaar-vcs.org/" |
67 |
DESCRIPTION="Based on the ${EBZR} eclass" |
68 |
|
69 |
DEPEND=">=dev-vcs/bzr-2.0.1" |
70 |
case "${EAPI:-0}" in |
71 |
0|1) ;; |
72 |
*) [[ ${EBZR_REPO_URI%%:*} = sftp ]] \ |
73 |
&& DEPEND=">=dev-vcs/bzr-2.0.1[sftp]" ;; |
74 |
esac |
75 |
|
76 |
# @ECLASS-VARIABLE: EBZR_STORE_DIR |
77 |
# @DESCRIPTION: |
78 |
# The directory to store all fetched Bazaar live sources. |
79 |
: ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/bzr-src} |
80 |
|
81 |
# @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD |
82 |
# @DESCRIPTION: |
83 |
# The Bazaar command to initialise a shared repository. |
84 |
: ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"} |
85 |
|
86 |
# @ECLASS-VARIABLE: EBZR_FETCH_CMD |
87 |
# @DESCRIPTION: |
88 |
# The Bazaar command to fetch the sources. |
89 |
: ${EBZR_FETCH_CMD="bzr branch --no-tree"} |
90 |
|
91 |
# @ECLASS-VARIABLE: EBZR_UPDATE_CMD |
92 |
# @DESCRIPTION: |
93 |
# The Bazaar command to update the sources. |
94 |
: ${EBZR_UPDATE_CMD:="bzr pull"} |
95 |
|
96 |
# @ECLASS-VARIABLE: EBZR_EXPORT_CMD |
97 |
# @DESCRIPTION: |
98 |
# The Bazaar command to export a branch. |
99 |
: ${EBZR_EXPORT_CMD:="bzr export"} |
100 |
|
101 |
# @ECLASS-VARIABLE: EBZR_REVNO_CMD |
102 |
# @DESCRIPTION: |
103 |
# The Bazaar command to list a revision number of the branch. |
104 |
: ${EBZR_REVNO_CMD:="bzr revno"} |
105 |
|
106 |
# @ECLASS-VARIABLE: EBZR_OPTIONS |
107 |
# @DEFAULT_UNSET |
108 |
# @DESCRIPTION: |
109 |
# The options passed to the fetch and update commands. |
110 |
|
111 |
# @ECLASS-VARIABLE: EBZR_REPO_URI |
112 |
# @DEFAULT_UNSET |
113 |
# @DESCRIPTION: |
114 |
# The repository URI for the source package. |
115 |
# |
116 |
# Note: If the ebuild uses an sftp:// URI, then in EAPI 0 or 1 it must |
117 |
# make sure that dev-vcs/bzr was built with USE="sftp". In EAPI 2 or |
118 |
# later, the eclass will depend on dev-vcs/bzr[sftp]. |
119 |
|
120 |
# @ECLASS-VARIABLE: EBZR_BOOTSTRAP |
121 |
# @DEFAULT_UNSET |
122 |
# @DESCRIPTION: |
123 |
# Bootstrap script or command like autogen.sh or etc. |
124 |
|
125 |
# @ECLASS-VARIABLE: EBZR_PATCHES |
126 |
# @DEFAULT_UNSET |
127 |
# @DESCRIPTION: |
128 |
# bzr.eclass can apply patches in bzr_bootstrap(). You can use regular |
129 |
# expressions in this variable like *.diff or *.patch and the like. |
130 |
# Note: These patches will be applied before EBZR_BOOTSTRAP is processed. |
131 |
# |
132 |
# Patches are searched both in ${PWD} and ${FILESDIR}. If not found in |
133 |
# either location, the installation dies. |
134 |
|
135 |
# @ECLASS-VARIABLE: EBZR_PROJECT |
136 |
# @DESCRIPTION: |
137 |
# The project name of your ebuild. Normally, the branch will be stored |
138 |
# in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory. |
139 |
# |
140 |
# If EBZR_BRANCH is set (see below), then a shared repository will be |
141 |
# created in that directory, and the branch will be located in |
142 |
# ${EBZR_STORE_DIR}/${EBZR_PROJECT}/${EBZR_BRANCH}. |
143 |
: ${EBZR_PROJECT:=${PN}} |
144 |
|
145 |
# @ECLASS-VARIABLE: EBZR_BRANCH |
146 |
# @DEFAULT_UNSET |
147 |
# @DESCRIPTION: |
148 |
# The directory where to store the branch within a shared repository, |
149 |
# relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}. |
150 |
# |
151 |
# This variable should be set if there are several live ebuilds for |
152 |
# different branches of the same upstream project. The branches can |
153 |
# then share the same repository in EBZR_PROJECT, which will save both |
154 |
# data traffic volume and disk space. |
155 |
# |
156 |
# If there is only a live ebuild for one single branch, EBZR_BRANCH |
157 |
# needs not be set. In this case, the branch will be stored in a |
158 |
# stand-alone repository directly in EBZR_PROJECT. |
159 |
|
160 |
# @ECLASS-VARIABLE: EBZR_REVISION |
161 |
# @DEFAULT_UNSET |
162 |
# @DESCRIPTION: |
163 |
# Revision to fetch, defaults to the latest |
164 |
# (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec). |
165 |
|
166 |
# @ECLASS-VARIABLE: EBZR_OFFLINE |
167 |
# @DESCRIPTION: |
168 |
# Set this variable to a non-empty value to disable automatic updating |
169 |
# of a bzr source tree. This is intended to be set outside the ebuild |
170 |
# by users. |
171 |
: ${EBZR_OFFLINE:=${ESCM_OFFLINE}} |
172 |
|
173 |
# @FUNCTION: bzr_initial_fetch |
174 |
# @DESCRIPTION: |
175 |
# Internal function, retrieves the source code from a repository for the |
176 |
# first time, using ${EBZR_FETCH_CMD}. |
177 |
bzr_initial_fetch() { |
178 |
local repo_uri=$1 branch_dir=$2 |
179 |
|
180 |
if [[ -n "${EBZR_OFFLINE}" ]]; then |
181 |
ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet." |
182 |
fi |
183 |
|
184 |
# fetch branch |
185 |
einfo "bzr branch start -->" |
186 |
einfo " repository: ${repo_uri} => ${branch_dir}" |
187 |
|
188 |
${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \ |
189 |
|| die "${EBZR}: can't branch from ${repo_uri}" |
190 |
} |
191 |
|
192 |
# @FUNCTION: bzr_update |
193 |
# @DESCRIPTION: |
194 |
# Internal function, updates the source code from a repository, using |
195 |
# ${EBZR_UPDATE_CMD}. |
196 |
bzr_update() { |
197 |
local repo_uri=$1 branch_dir=$2 |
198 |
|
199 |
if [[ -n "${EBZR_OFFLINE}" ]]; then |
200 |
einfo "skipping bzr pull -->" |
201 |
einfo " repository: ${repo_uri}" |
202 |
else |
203 |
# update branch |
204 |
einfo "bzr pull start -->" |
205 |
einfo " repository: ${repo_uri}" |
206 |
|
207 |
pushd "${branch_dir}" > /dev/null \ |
208 |
|| die "${EBZR}: can't chdir to ${branch_dir}" |
209 |
${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repo_uri}" \ |
210 |
|| die "${EBZR}: can't pull from ${repo_uri}" |
211 |
popd > /dev/null |
212 |
fi |
213 |
} |
214 |
|
215 |
# @FUNCTION: bzr_fetch |
216 |
# @DESCRIPTION: |
217 |
# Wrapper function to fetch sources from a Bazaar repository with |
218 |
# bzr branch or bzr pull, depending on whether there is an existing |
219 |
# working copy. |
220 |
bzr_fetch() { |
221 |
local repo_dir branch_dir |
222 |
|
223 |
# EBZR_REPO_URI is empty. |
224 |
[[ ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty" |
225 |
|
226 |
if [[ ! -d ${EBZR_STORE_DIR} ]] ; then |
227 |
local save_sandbox_write=${SANDBOX_WRITE} |
228 |
addwrite / |
229 |
mkdir -p "${EBZR_STORE_DIR}" \ |
230 |
|| die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}" |
231 |
SANDBOX_WRITE=${save_sandbox_write} |
232 |
fi |
233 |
|
234 |
pushd "${EBZR_STORE_DIR}" > /dev/null \ |
235 |
|| die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}" |
236 |
|
237 |
repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT} |
238 |
branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}} |
239 |
|
240 |
addwrite "${EBZR_STORE_DIR}" |
241 |
|
242 |
# Clean up if the existing local copy is a checkout (as was the case |
243 |
# with an older version of bzr.eclass). |
244 |
if [[ ${EBZR_FETCH_CMD} != *checkout* && -d ${repo_dir}/.bzr/checkout ]] |
245 |
then |
246 |
ewarn "removing old bzr checkout" |
247 |
rm -rf "${repo_dir}" |
248 |
fi |
249 |
|
250 |
if [[ ! -d ${branch_dir}/.bzr ]]; then |
251 |
if [[ ${repo_dir} != "${branch_dir}" && ! -d ${repo_dir}/.bzr ]]; then |
252 |
einfo "creating shared bzr repository" |
253 |
${EBZR_INIT_REPO_CMD} "${repo_dir}" \ |
254 |
|| die "${EBZR}: can't create shared repository" |
255 |
fi |
256 |
|
257 |
if [[ -z ${EBZR_MIRROR_URI} ]]; then |
258 |
bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}" |
259 |
else |
260 |
# Workaround for faster initial download. This clones the |
261 |
# branch from a fast mirror (which may be out of date), and |
262 |
# subsequently pulls from the slow original repository. |
263 |
bzr_initial_fetch "${EBZR_MIRROR_URI}" "${branch_dir}" |
264 |
EBZR_UPDATE_CMD="${EBZR_UPDATE_CMD} --remember --overwrite" \ |
265 |
EBZR_OFFLINE="" bzr_update "${EBZR_REPO_URI}" "${branch_dir}" |
266 |
fi |
267 |
else |
268 |
bzr_update "${EBZR_REPO_URI}" "${branch_dir}" |
269 |
fi |
270 |
|
271 |
cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}" |
272 |
export EBZR_REVNO=$(${EBZR_REVNO_CMD}) |
273 |
|
274 |
einfo "exporting ..." |
275 |
${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \ |
276 |
"${WORKDIR}/${P}" . || die "${EBZR}: export failed" |
277 |
einfo "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${WORKDIR}/${P}" |
278 |
|
279 |
popd > /dev/null |
280 |
} |
281 |
|
282 |
# @FUNCTION: bzr_bootstrap |
283 |
# @DESCRIPTION: |
284 |
# Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified. |
285 |
bzr_bootstrap() { |
286 |
local patch lpatch |
287 |
|
288 |
pushd "${S}" > /dev/null || die "${EBZR}: can't chdir to ${S}" |
289 |
|
290 |
if [[ -n ${EBZR_PATCHES} ]] ; then |
291 |
einfo "apply patches -->" |
292 |
|
293 |
for patch in ${EBZR_PATCHES} ; do |
294 |
if [[ -f ${patch} ]] ; then |
295 |
epatch ${patch} |
296 |
else |
297 |
# This loop takes care of wildcarded patches given via |
298 |
# EBZR_PATCHES in an ebuild |
299 |
for lpatch in "${FILESDIR}"/${patch} ; do |
300 |
if [[ -f ${lpatch} ]] ; then |
301 |
epatch ${lpatch} |
302 |
else |
303 |
die "${EBZR}: ${patch} is not found" |
304 |
fi |
305 |
done |
306 |
fi |
307 |
done |
308 |
fi |
309 |
|
310 |
if [[ -n ${EBZR_BOOTSTRAP} ]] ; then |
311 |
einfo "begin bootstrap -->" |
312 |
|
313 |
if [[ -f ${EBZR_BOOTSTRAP} ]] && [[ -x ${EBZR_BOOTSTRAP} ]] ; then |
314 |
einfo " bootstrap with a file: ${EBZR_BOOTSTRAP}" |
315 |
"./${EBZR_BOOTSTRAP}" \ |
316 |
|| die "${EBZR}: can't execute EBZR_BOOTSTRAP" |
317 |
else |
318 |
einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}" |
319 |
"${EBZR_BOOTSTRAP}" \ |
320 |
|| die "${EBZR}: can't eval EBZR_BOOTSTRAP" |
321 |
fi |
322 |
fi |
323 |
|
324 |
popd > /dev/null |
325 |
} |
326 |
|
327 |
# @FUNCTION: bzr_src_unpack |
328 |
# @DESCRIPTION: |
329 |
# Default src_unpack(), calls bzr_fetch. For EAPIs 0 and 1, also calls |
330 |
# bzr_src_prepare. |
331 |
bzr_src_unpack() { |
332 |
bzr_fetch |
333 |
case "${EAPI:-0}" in |
334 |
0|1) bzr_src_prepare ;; |
335 |
esac |
336 |
} |
337 |
|
338 |
# @FUNCTION: bzr_src_prepare |
339 |
# @DESCRIPTION: |
340 |
# Default src_prepare(), calls bzr_bootstrap. |
341 |
bzr_src_prepare() { |
342 |
bzr_bootstrap |
343 |
} |