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

Contents of /eclass/bzr.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Thu Jul 11 18:38:59 2013 UTC (13 months, 3 weeks ago) by ulm
Branch: MAIN
CVS Tags: HEAD
Changes since 1.19: +11 -5 lines
New variable EBZR_UNPACK_DIR.

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

  ViewVC Help
Powered by ViewVC 1.1.20