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