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

Contents of /eclass/bzr.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.16 - (hide annotations) (download)
Fri Sep 2 21:26:58 2011 UTC (2 years, 11 months ago) by ulm
Branch: MAIN
Changes since 1.15: +8 -6 lines
Eclass documentation now supports @AUTHOR block.

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

  ViewVC Help
Powered by ViewVC 1.1.20