/[gentoo-x86]/eclass/bzr.eclass
Gentoo

Contents of /eclass/bzr.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.19 - (hide annotations) (download)
Tue Sep 18 06:41:45 2012 UTC (23 months ago) by ulm
Branch: MAIN
Changes since 1.18: +25 -18 lines
Use lightweight checkout instead of export if EBZR_WORKDIR_CHECKOUT is set; bug 434746. Remove old cleanup code.

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

  ViewVC Help
Powered by ViewVC 1.1.20