1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
6 # Ulrich Müller <ulm@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 # @SUPPORTED_EAPIS: 2 3 4 5 6 7
13 # @BLURB: generic fetching functions for the Bazaar VCS
15 # The bzr.eclass provides functions to fetch and unpack sources from
16 # repositories of the Bazaar distributed version control system.
17 # 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}.
24 if [[ ${EBZR_REPO_URI%%:*} = sftp ]]; then
25 DEPEND=">=dev-vcs/bzr-2.6.0[sftp]"
27 DEPEND=">=dev-vcs/bzr-2.6.0"
32 7) BDEPEND="${DEPEND}"; DEPEND="" ;;
33 *) die "${EBZR}: EAPI ${EAPI:-0} is not supported" ;;
36 EXPORT_FUNCTIONS src_unpack
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 --overwrite-tags"}
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 the eclass will depend
90 # 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_PROJECT
105 # The project name of your ebuild. Normally, the branch will be stored
106 # in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
108 # If EBZR_BRANCH is set (see below), then a shared repository will be
109 # created in that directory, and the branch will be located in
110 # ${EBZR_STORE_DIR}/${EBZR_PROJECT}/${EBZR_BRANCH}.
111 : ${EBZR_PROJECT:=${PN}}
113 # @ECLASS-VARIABLE: EBZR_BRANCH
116 # The directory where to store the branch within a shared repository,
117 # relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
119 # This variable should be set if there are several live ebuilds for
120 # different branches of the same upstream project. The branches can
121 # then share the same repository in EBZR_PROJECT, which will save both
122 # data traffic volume and disk space.
124 # If there is only a live ebuild for one single branch, EBZR_BRANCH
125 # needs not be set. In this case, the branch will be stored in a
126 # stand-alone repository directly in EBZR_PROJECT.
128 # @ECLASS-VARIABLE: EBZR_REVISION
131 # Revision to fetch, defaults to the latest
132 # (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
134 # @ECLASS-VARIABLE: EBZR_OFFLINE
136 # Set this variable to a non-empty value to disable automatic updating
137 # of a bzr source tree. This is intended to be set outside the ebuild
139 : ${EBZR_OFFLINE=${EVCS_OFFLINE}}
141 # @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
144 # If this variable is set to a non-empty value, EBZR_CHECKOUT_CMD will
145 # be used instead of EBZR_EXPORT_CMD to copy the sources to WORKDIR.
147 # @FUNCTION: bzr_initial_fetch
148 # @USAGE: <repository URI> <branch directory>
150 # Internal function, retrieves the source code from a repository for the
151 # first time, using ${EBZR_FETCH_CMD}.
152 bzr_initial_fetch() {
153 local repo_uri=$1 branch_dir=$2
155 if [[ -n "${EBZR_OFFLINE}" ]]; then
156 ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
160 einfo "bzr branch start -->"
161 einfo " repository: ${repo_uri} => ${branch_dir}"
163 ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
164 || die "${EBZR}: can't branch from ${repo_uri}"
167 # @FUNCTION: bzr_update
168 # @USAGE: <repository URI> <branch directory>
170 # Internal function, updates the source code from a repository, using
171 # ${EBZR_UPDATE_CMD}.
173 local repo_uri=$1 branch_dir=$2
175 if [[ -n "${EBZR_OFFLINE}" ]]; then
176 einfo "skipping bzr pull -->"
177 einfo " repository: ${repo_uri}"
180 einfo "bzr pull start -->"
181 einfo " repository: ${repo_uri}"
183 pushd "${branch_dir}" > /dev/null \
184 || die "${EBZR}: can't chdir to ${branch_dir}"
185 ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repo_uri}" \
186 || die "${EBZR}: can't pull from ${repo_uri}"
191 # @FUNCTION: bzr_fetch
193 # Wrapper function to fetch sources from a Bazaar repository with
194 # bzr branch or bzr pull, depending on whether there is an existing
197 local repo_dir branch_dir
198 local save_sandbox_write=${SANDBOX_WRITE}
200 [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
202 if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
204 mkdir -p "${EBZR_STORE_DIR}" \
205 || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
206 SANDBOX_WRITE=${save_sandbox_write}
209 pushd "${EBZR_STORE_DIR}" > /dev/null \
210 || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
212 repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
213 branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
215 addwrite "${EBZR_STORE_DIR}"
217 if [[ ! -d ${branch_dir}/.bzr ]]; then
218 if [[ ${repo_dir} != "${branch_dir}" && ! -d ${repo_dir}/.bzr ]]; then
219 einfo "creating shared bzr repository: ${repo_dir}"
220 ${EBZR_INIT_REPO_CMD} "${repo_dir}" \
221 || die "${EBZR}: can't create shared repository"
224 if [[ -z ${EBZR_INITIAL_URI} ]]; then
225 bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
227 # Workaround for faster initial download. This clones the
228 # branch from a fast server (which may be out of date), and
229 # subsequently pulls from the slow original repository.
230 bzr_initial_fetch "${EBZR_INITIAL_URI}" "${branch_dir}"
231 if [[ ${EBZR_REPO_URI} != "${EBZR_INITIAL_URI}" ]]; then
232 EBZR_UPDATE_CMD="${EBZR_UPDATE_CMD} --remember --overwrite" \
234 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
238 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
241 # Restore sandbox environment
242 SANDBOX_WRITE=${save_sandbox_write}
244 cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
246 # Save revision number in environment. #311101
247 export EBZR_REVNO=$(${EBZR_REVNO_CMD})
249 if [[ -n ${EBZR_WORKDIR_CHECKOUT} ]]; then
250 einfo "checking out ..."
251 ${EBZR_CHECKOUT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
252 . "${EBZR_UNPACK_DIR}" || die "${EBZR}: checkout failed"
254 einfo "exporting ..."
255 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
256 "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
259 "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
264 # @FUNCTION: bzr_src_unpack
266 # Default src_unpack(), calls bzr_fetch.