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