1 # Copyright 1999-2019 Gentoo Authors
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}.
26 if [[ ${EBZR_REPO_URI%%:*} = sftp ]]; then
27 DEPEND=">=dev-vcs/bzr-2.6.0[sftp]"
29 DEPEND=">=dev-vcs/bzr-2.6.0"
34 7) BDEPEND="${DEPEND}"; DEPEND="" ;;
35 *) die "${EBZR}: EAPI ${EAPI:-0} is not supported" ;;
38 EXPORT_FUNCTIONS src_unpack
40 # @ECLASS-VARIABLE: EBZR_STORE_DIR
42 # The directory to store all fetched Bazaar live sources.
43 : ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/bzr-src}
45 # @ECLASS-VARIABLE: EBZR_UNPACK_DIR
47 # The working directory where the sources are copied to.
48 : ${EBZR_UNPACK_DIR:=${WORKDIR}/${P}}
50 # @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD
52 # The Bazaar command to initialise a shared repository.
53 : ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"}
55 # @ECLASS-VARIABLE: EBZR_FETCH_CMD
57 # The Bazaar command to fetch the sources.
58 : ${EBZR_FETCH_CMD:="bzr branch --no-tree"}
60 # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
62 # The Bazaar command to update the sources.
63 : ${EBZR_UPDATE_CMD:="bzr pull --overwrite-tags"}
65 # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
67 # The Bazaar command to export a branch.
68 : ${EBZR_EXPORT_CMD:="bzr export"}
70 # @ECLASS-VARIABLE: EBZR_CHECKOUT_CMD
72 # The Bazaar command to checkout a branch.
73 : ${EBZR_CHECKOUT_CMD:="bzr checkout --lightweight -q"}
75 # @ECLASS-VARIABLE: EBZR_REVNO_CMD
77 # The Bazaar command to list a revision number of the branch.
78 : ${EBZR_REVNO_CMD:="bzr revno"}
80 # @ECLASS-VARIABLE: EBZR_OPTIONS
83 # The options passed to the fetch and update commands.
85 # @ECLASS-VARIABLE: EBZR_REPO_URI
89 # The repository URI for the source package.
91 # Note: If the ebuild uses an sftp:// URI, then the eclass will depend
92 # on dev-vcs/bzr[sftp].
94 # @ECLASS-VARIABLE: EBZR_INITIAL_URI
97 # 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.
103 # Normally, this variable needs not be set.
105 # @ECLASS-VARIABLE: EBZR_PROJECT
107 # The project name of your ebuild. Normally, the branch will be stored
108 # in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
110 # If EBZR_BRANCH is set (see below), then a shared repository will be
111 # created in that directory, and the branch will be located in
112 # ${EBZR_STORE_DIR}/${EBZR_PROJECT}/${EBZR_BRANCH}.
113 : ${EBZR_PROJECT:=${PN}}
115 # @ECLASS-VARIABLE: EBZR_BRANCH
118 # The directory where to store the branch within a shared repository,
119 # relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
121 # This variable should be set if there are several live ebuilds for
122 # different branches of the same upstream project. The branches can
123 # then share the same repository in EBZR_PROJECT, which will save both
124 # data traffic volume and disk space.
126 # If there is only a live ebuild for one single branch, EBZR_BRANCH
127 # needs not be set. In this case, the branch will be stored in a
128 # stand-alone repository directly in EBZR_PROJECT.
130 # @ECLASS-VARIABLE: EBZR_REVISION
133 # Revision to fetch, defaults to the latest
134 # (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
136 # @ECLASS-VARIABLE: EBZR_OFFLINE
138 # Set this variable to a non-empty value to disable automatic updating
139 # of a bzr source tree. This is intended to be set outside the ebuild
141 : ${EBZR_OFFLINE=${EVCS_OFFLINE}}
143 # @ECLASS-VARIABLE: EVCS_UMASK
146 # Set this variable to a custom umask. This is intended to be set by
147 # users. By setting this to something like 002, it can make life easier
148 # for people who do development as non-root (but are in the portage
149 # group), and then switch over to building with FEATURES=userpriv.
150 # Or vice-versa. Shouldn't be a security issue here as anyone who has
151 # portage group write access already can screw the system over in more
154 # @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
157 # If this variable is set to a non-empty value, EBZR_CHECKOUT_CMD will
158 # be used instead of EBZR_EXPORT_CMD to copy the sources to WORKDIR.
160 # @FUNCTION: bzr_initial_fetch
161 # @USAGE: <repository URI> <branch directory>
163 # Internal function, retrieves the source code from a repository for the
164 # first time, using ${EBZR_FETCH_CMD}.
165 bzr_initial_fetch() {
166 local repo_uri=$1 branch_dir=$2
168 if [[ -n "${EBZR_OFFLINE}" ]]; then
169 ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
173 einfo "bzr branch start -->"
174 einfo " repository: ${repo_uri} => ${branch_dir}"
176 ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
177 || die "${EBZR}: can't branch from ${repo_uri}"
180 # @FUNCTION: bzr_update
181 # @USAGE: <repository URI> <branch directory>
183 # Internal function, updates the source code from a repository, using
184 # ${EBZR_UPDATE_CMD}.
186 local repo_uri=$1 branch_dir=$2
188 if [[ -n "${EBZR_OFFLINE}" ]]; then
189 einfo "skipping bzr pull -->"
190 einfo " repository: ${repo_uri}"
193 einfo "bzr pull start -->"
194 einfo " repository: ${repo_uri}"
196 pushd "${branch_dir}" > /dev/null \
197 || die "${EBZR}: can't chdir to ${branch_dir}"
198 ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repo_uri}" \
199 || die "${EBZR}: can't pull from ${repo_uri}"
200 popd > /dev/null || die "${EBZR}: popd failed"
204 # @FUNCTION: bzr_fetch
206 # Wrapper function to fetch sources from a Bazaar repository with
207 # bzr branch or bzr pull, depending on whether there is an existing
210 local repo_dir branch_dir
211 local save_sandbox_write=${SANDBOX_WRITE} save_umask
213 [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
215 if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
217 mkdir -p "${EBZR_STORE_DIR}" \
218 || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
219 SANDBOX_WRITE=${save_sandbox_write}
222 pushd "${EBZR_STORE_DIR}" > /dev/null \
223 || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
225 repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
226 branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
228 if [[ -n ${EVCS_UMASK} ]]; then
230 umask "${EVCS_UMASK}" || die
232 addwrite "${EBZR_STORE_DIR}"
234 if [[ ! -d ${branch_dir}/.bzr ]]; then
235 if [[ ${repo_dir} != "${branch_dir}" && ! -d ${repo_dir}/.bzr ]]; then
236 einfo "creating shared bzr repository: ${repo_dir}"
237 ${EBZR_INIT_REPO_CMD} "${repo_dir}" \
238 || die "${EBZR}: can't create shared repository"
241 if [[ -z ${EBZR_INITIAL_URI} ]]; then
242 bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
244 # Workaround for faster initial download. This clones the
245 # branch from a fast server (which may be out of date), and
246 # subsequently pulls from the slow original repository.
247 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" \
251 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
255 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
258 # Restore sandbox environment and umask
259 SANDBOX_WRITE=${save_sandbox_write}
260 if [[ -n ${save_umask} ]]; then
261 umask "${save_umask}" || die
264 cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
266 # Save revision number in environment. #311101
267 export EBZR_REVNO=$(${EBZR_REVNO_CMD})
269 if [[ -n ${EBZR_WORKDIR_CHECKOUT} ]]; then
270 einfo "checking out ..."
271 ${EBZR_CHECKOUT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
272 . "${EBZR_UNPACK_DIR}" || die "${EBZR}: checkout failed"
274 einfo "exporting ..."
275 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
276 "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
279 "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
281 popd > /dev/null || die "${EBZR}: popd failed"
284 # @FUNCTION: bzr_src_unpack
286 # Default src_unpack(), calls bzr_fetch.