1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 # No maintainer <maintainer-needed@gentoo.org>
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
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.
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}.
26 0|1) EXPORT_FUNCTIONS src_unpack ;;
27 *) EXPORT_FUNCTIONS src_unpack src_prepare ;;
30 DEPEND=">=dev-vcs/bzr-2.0.1"
33 *) [[ ${EBZR_REPO_URI%%:*} = sftp ]] \
34 && DEPEND=">=dev-vcs/bzr-2.0.1[sftp]" ;;
37 # @ECLASS-VARIABLE: EBZR_STORE_DIR
39 # The directory to store all fetched Bazaar live sources.
40 : ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/bzr-src}
42 # @ECLASS-VARIABLE: EBZR_UNPACK_DIR
44 # The working directory where the sources are copied to.
45 : ${EBZR_UNPACK_DIR:=${WORKDIR}/${P}}
47 # @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD
49 # The Bazaar command to initialise a shared repository.
50 : ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"}
52 # @ECLASS-VARIABLE: EBZR_FETCH_CMD
54 # The Bazaar command to fetch the sources.
55 : ${EBZR_FETCH_CMD:="bzr branch --no-tree"}
57 # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
59 # The Bazaar command to update the sources.
60 : ${EBZR_UPDATE_CMD:="bzr pull"}
62 # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
64 # The Bazaar command to export a branch.
65 : ${EBZR_EXPORT_CMD:="bzr export"}
67 # @ECLASS-VARIABLE: EBZR_CHECKOUT_CMD
69 # The Bazaar command to checkout a branch.
70 : ${EBZR_CHECKOUT_CMD:="bzr checkout --lightweight -q"}
72 # @ECLASS-VARIABLE: EBZR_REVNO_CMD
74 # The Bazaar command to list a revision number of the branch.
75 : ${EBZR_REVNO_CMD:="bzr revno"}
77 # @ECLASS-VARIABLE: EBZR_OPTIONS
80 # The options passed to the fetch and update commands.
82 # @ECLASS-VARIABLE: EBZR_REPO_URI
86 # The repository URI for the source package.
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].
92 # @ECLASS-VARIABLE: EBZR_INITIAL_URI
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.
101 # Normally, this variable needs not be set.
103 # @ECLASS-VARIABLE: EBZR_BOOTSTRAP
106 # Bootstrap script or command like autogen.sh or etc.
108 # @ECLASS-VARIABLE: EBZR_PATCHES
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.
115 # Patches are searched both in ${PWD} and ${FILESDIR}. If not found in
116 # either location, the installation dies.
118 # @ECLASS-VARIABLE: EBZR_PROJECT
120 # The project name of your ebuild. Normally, the branch will be stored
121 # in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
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}}
128 # @ECLASS-VARIABLE: EBZR_BRANCH
131 # The directory where to store the branch within a shared repository,
132 # relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
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.
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.
143 # @ECLASS-VARIABLE: EBZR_REVISION
146 # Revision to fetch, defaults to the latest
147 # (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
149 # @ECLASS-VARIABLE: EBZR_OFFLINE
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
154 : ${EBZR_OFFLINE=${EVCS_OFFLINE}}
156 # @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
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.
162 # @FUNCTION: bzr_initial_fetch
163 # @USAGE: <repository URI> <branch directory>
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
170 if [[ -n "${EBZR_OFFLINE}" ]]; then
171 ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
175 einfo "bzr branch start -->"
176 einfo " repository: ${repo_uri} => ${branch_dir}"
178 ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
179 || die "${EBZR}: can't branch from ${repo_uri}"
182 # @FUNCTION: bzr_update
183 # @USAGE: <repository URI> <branch directory>
185 # Internal function, updates the source code from a repository, using
186 # ${EBZR_UPDATE_CMD}.
188 local repo_uri=$1 branch_dir=$2
190 if [[ -n "${EBZR_OFFLINE}" ]]; then
191 einfo "skipping bzr pull -->"
192 einfo " repository: ${repo_uri}"
195 einfo "bzr pull start -->"
196 einfo " repository: ${repo_uri}"
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}"
206 # @FUNCTION: bzr_fetch
208 # Wrapper function to fetch sources from a Bazaar repository with
209 # bzr branch or bzr pull, depending on whether there is an existing
212 local repo_dir branch_dir
213 local save_sandbox_write=${SANDBOX_WRITE}
215 [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
217 if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
219 mkdir -p "${EBZR_STORE_DIR}" \
220 || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
221 SANDBOX_WRITE=${save_sandbox_write}
224 pushd "${EBZR_STORE_DIR}" > /dev/null \
225 || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
227 repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
228 branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
230 addwrite "${EBZR_STORE_DIR}"
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"
239 if [[ -z ${EBZR_INITIAL_URI} ]]; then
240 bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
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" \
249 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
253 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
256 # Restore sandbox environment
257 SANDBOX_WRITE=${save_sandbox_write}
259 cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
261 # Save revision number in environment. #311101
262 export EBZR_REVNO=$(${EBZR_REVNO_CMD})
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"
269 einfo "exporting ..."
270 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
271 "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
274 "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
279 # @FUNCTION: bzr_bootstrap
281 # Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified.
285 pushd "${S}" > /dev/null || die "${EBZR}: can't chdir to ${S}"
287 if [[ -n ${EBZR_PATCHES} ]] ; then
288 einfo "apply patches -->"
290 for patch in ${EBZR_PATCHES} ; do
291 if [[ -f ${patch} ]] ; then
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
300 die "${EBZR}: ${patch} is not found"
307 if [[ -n ${EBZR_BOOTSTRAP} ]] ; then
308 einfo "begin bootstrap -->"
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"
315 einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}"
316 "${EBZR_BOOTSTRAP}" \
317 || die "${EBZR}: can't eval EBZR_BOOTSTRAP"
324 # @FUNCTION: bzr_src_unpack
326 # Default src_unpack(), calls bzr_fetch. For EAPIs 0 and 1, also calls
331 0|1) bzr_src_prepare ;;
335 # @FUNCTION: bzr_src_prepare
337 # Default src_prepare(), calls bzr_bootstrap.