1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
7 # Bazaar team <bazaar@gentoo.org>
9 # Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>
10 # Mark Lee <bzr-gentoo-overlay@lazymalevolence.com>
11 # Ulrich Müller <ulm@gentoo.org>
12 # Christian Faulhammer <fauli@gentoo.org>
13 # @BLURB: generic fetching functions for the Bazaar VCS
15 # The bzr.eclass provides functions to fetch, unpack, patch, and
16 # bootstrap sources from repositories of the Bazaar distributed version
17 # control system. The eclass was originally derived from git.eclass.
19 # Note: Just set EBZR_REPO_URI to the URI of the branch and src_unpack()
20 # of this eclass will export the branch to ${WORKDIR}/${P}.
27 0|1) EXPORT_FUNCTIONS src_unpack ;;
28 *) EXPORT_FUNCTIONS src_unpack src_prepare ;;
31 DEPEND=">=dev-vcs/bzr-2.0.1"
34 *) [[ ${EBZR_REPO_URI%%:*} = sftp ]] \
35 && DEPEND=">=dev-vcs/bzr-2.0.1[sftp]" ;;
38 # @ECLASS-VARIABLE: EBZR_STORE_DIR
40 # The directory to store all fetched Bazaar live sources.
41 : ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/bzr-src}
43 # @ECLASS-VARIABLE: EBZR_UNPACK_DIR
45 # The working directory where the sources are copied to.
46 : ${EBZR_UNPACK_DIR:=${WORKDIR}/${P}}
48 # @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD
50 # The Bazaar command to initialise a shared repository.
51 : ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"}
53 # @ECLASS-VARIABLE: EBZR_FETCH_CMD
55 # The Bazaar command to fetch the sources.
56 : ${EBZR_FETCH_CMD:="bzr branch --no-tree"}
58 # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
60 # The Bazaar command to update the sources.
61 : ${EBZR_UPDATE_CMD:="bzr pull"}
63 # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
65 # The Bazaar command to export a branch.
66 : ${EBZR_EXPORT_CMD:="bzr export"}
68 # @ECLASS-VARIABLE: EBZR_CHECKOUT_CMD
70 # The Bazaar command to checkout a branch.
71 : ${EBZR_CHECKOUT_CMD:="bzr checkout --lightweight -q"}
73 # @ECLASS-VARIABLE: EBZR_REVNO_CMD
75 # The Bazaar command to list a revision number of the branch.
76 : ${EBZR_REVNO_CMD:="bzr revno"}
78 # @ECLASS-VARIABLE: EBZR_OPTIONS
81 # The options passed to the fetch and update commands.
83 # @ECLASS-VARIABLE: EBZR_REPO_URI
87 # The repository URI for the source package.
89 # Note: If the ebuild uses an sftp:// URI, then in EAPI 0 or 1 it must
90 # make sure that dev-vcs/bzr was built with USE="sftp". In EAPI 2 or
91 # later, the eclass will depend on dev-vcs/bzr[sftp].
93 # @ECLASS-VARIABLE: EBZR_INITIAL_URI
96 # The URI used for initial branching of the source repository. If this
97 # variable is set, the initial branch will be cloned from the location
98 # specified, followed by a pull from ${EBZR_REPO_URI}. This is intended
99 # for special cases, e.g. when download from the original repository is
100 # slow, but a fast mirror exists but may be out of date.
102 # Normally, this variable needs not be set.
104 # @ECLASS-VARIABLE: EBZR_BOOTSTRAP
107 # Bootstrap script or command like autogen.sh or etc.
109 # @ECLASS-VARIABLE: EBZR_PATCHES
112 # bzr.eclass can apply patches in bzr_bootstrap(). You can use regular
113 # expressions in this variable like *.diff or *.patch and the like.
114 # Note: These patches will be applied before EBZR_BOOTSTRAP is processed.
116 # Patches are searched both in ${PWD} and ${FILESDIR}. If not found in
117 # either location, the installation dies.
119 # @ECLASS-VARIABLE: EBZR_PROJECT
121 # The project name of your ebuild. Normally, the branch will be stored
122 # in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
124 # If EBZR_BRANCH is set (see below), then a shared repository will be
125 # created in that directory, and the branch will be located in
126 # ${EBZR_STORE_DIR}/${EBZR_PROJECT}/${EBZR_BRANCH}.
127 : ${EBZR_PROJECT:=${PN}}
129 # @ECLASS-VARIABLE: EBZR_BRANCH
132 # The directory where to store the branch within a shared repository,
133 # relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
135 # This variable should be set if there are several live ebuilds for
136 # different branches of the same upstream project. The branches can
137 # then share the same repository in EBZR_PROJECT, which will save both
138 # data traffic volume and disk space.
140 # If there is only a live ebuild for one single branch, EBZR_BRANCH
141 # needs not be set. In this case, the branch will be stored in a
142 # stand-alone repository directly in EBZR_PROJECT.
144 # @ECLASS-VARIABLE: EBZR_REVISION
147 # Revision to fetch, defaults to the latest
148 # (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
150 # @ECLASS-VARIABLE: EBZR_OFFLINE
152 # Set this variable to a non-empty value to disable automatic updating
153 # of a bzr source tree. This is intended to be set outside the ebuild
155 : ${EBZR_OFFLINE=${EVCS_OFFLINE}}
157 # @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
160 # If this variable is set to a non-empty value, EBZR_CHECKOUT_CMD will
161 # be used instead of EBZR_EXPORT_CMD to copy the sources to WORKDIR.
163 # @FUNCTION: bzr_initial_fetch
164 # @USAGE: <repository URI> <branch directory>
166 # Internal function, retrieves the source code from a repository for the
167 # first time, using ${EBZR_FETCH_CMD}.
168 bzr_initial_fetch() {
169 local repo_uri=$1 branch_dir=$2
171 if [[ -n "${EBZR_OFFLINE}" ]]; then
172 ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
176 einfo "bzr branch start -->"
177 einfo " repository: ${repo_uri} => ${branch_dir}"
179 ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
180 || die "${EBZR}: can't branch from ${repo_uri}"
183 # @FUNCTION: bzr_update
184 # @USAGE: <repository URI> <branch directory>
186 # Internal function, updates the source code from a repository, using
187 # ${EBZR_UPDATE_CMD}.
189 local repo_uri=$1 branch_dir=$2
191 if [[ -n "${EBZR_OFFLINE}" ]]; then
192 einfo "skipping bzr pull -->"
193 einfo " repository: ${repo_uri}"
196 einfo "bzr pull start -->"
197 einfo " repository: ${repo_uri}"
199 pushd "${branch_dir}" > /dev/null \
200 || die "${EBZR}: can't chdir to ${branch_dir}"
201 ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repo_uri}" \
202 || die "${EBZR}: can't pull from ${repo_uri}"
207 # @FUNCTION: bzr_fetch
209 # Wrapper function to fetch sources from a Bazaar repository with
210 # bzr branch or bzr pull, depending on whether there is an existing
213 local repo_dir branch_dir
214 local save_sandbox_write=${SANDBOX_WRITE}
216 [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
218 if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
220 mkdir -p "${EBZR_STORE_DIR}" \
221 || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
222 SANDBOX_WRITE=${save_sandbox_write}
225 pushd "${EBZR_STORE_DIR}" > /dev/null \
226 || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
228 repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
229 branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
231 addwrite "${EBZR_STORE_DIR}"
233 if [[ ! -d ${branch_dir}/.bzr ]]; then
234 if [[ ${repo_dir} != "${branch_dir}" && ! -d ${repo_dir}/.bzr ]]; then
235 einfo "creating shared bzr repository: ${repo_dir}"
236 ${EBZR_INIT_REPO_CMD} "${repo_dir}" \
237 || die "${EBZR}: can't create shared repository"
240 if [[ -z ${EBZR_INITIAL_URI} ]]; then
241 bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
243 # Workaround for faster initial download. This clones the
244 # branch from a fast server (which may be out of date), and
245 # subsequently pulls from the slow original repository.
246 bzr_initial_fetch "${EBZR_INITIAL_URI}" "${branch_dir}"
247 if [[ ${EBZR_REPO_URI} != "${EBZR_INITIAL_URI}" ]]; then
248 EBZR_UPDATE_CMD="${EBZR_UPDATE_CMD} --remember --overwrite" \
250 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
254 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
257 # Restore sandbox environment
258 SANDBOX_WRITE=${save_sandbox_write}
260 cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
262 # Save revision number in environment. #311101
263 export EBZR_REVNO=$(${EBZR_REVNO_CMD})
265 if [[ -n ${EBZR_WORKDIR_CHECKOUT} ]]; then
266 einfo "checking out ..."
267 ${EBZR_CHECKOUT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
268 . "${EBZR_UNPACK_DIR}" || die "${EBZR}: checkout failed"
270 einfo "exporting ..."
271 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
272 "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
275 "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
280 # @FUNCTION: bzr_bootstrap
282 # Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified.
286 pushd "${S}" > /dev/null || die "${EBZR}: can't chdir to ${S}"
288 if [[ -n ${EBZR_PATCHES} ]] ; then
289 einfo "apply patches -->"
291 for patch in ${EBZR_PATCHES} ; do
292 if [[ -f ${patch} ]] ; then
295 # This loop takes care of wildcarded patches given via
296 # EBZR_PATCHES in an ebuild
297 for lpatch in "${FILESDIR}"/${patch} ; do
298 if [[ -f ${lpatch} ]] ; then
301 die "${EBZR}: ${patch} is not found"
308 if [[ -n ${EBZR_BOOTSTRAP} ]] ; then
309 einfo "begin bootstrap -->"
311 if [[ -f ${EBZR_BOOTSTRAP} ]] && [[ -x ${EBZR_BOOTSTRAP} ]] ; then
312 einfo " bootstrap with a file: ${EBZR_BOOTSTRAP}"
313 "./${EBZR_BOOTSTRAP}" \
314 || die "${EBZR}: can't execute EBZR_BOOTSTRAP"
316 einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}"
317 "${EBZR_BOOTSTRAP}" \
318 || die "${EBZR}: can't eval EBZR_BOOTSTRAP"
325 # @FUNCTION: bzr_src_unpack
327 # Default src_unpack(), calls bzr_fetch. For EAPIs 0 and 1, also calls
332 0|1) bzr_src_prepare ;;
336 # @FUNCTION: bzr_src_prepare
338 # Default src_prepare(), calls bzr_bootstrap.