media-plugins/gst-plugins-taglib-1.14.4: ppc stable, bug 674854
[gentoo.git] / eclass / bzr.eclass
1 # Copyright 1999-2018 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4 # @ECLASS: bzr.eclass
5 # @MAINTAINER:
6 # Ulrich Müller <ulm@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 # @SUPPORTED_EAPIS: 2 3 4 5 6 7
13 # @BLURB: generic fetching functions for the Bazaar VCS
14 # @DESCRIPTION:
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.
18 #
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}.
21
22 EBZR="bzr.eclass"
23
24 if [[ ${EBZR_REPO_URI%%:*} = sftp ]]; then
25         DEPEND=">=dev-vcs/bzr-2.6.0[sftp]"
26 else
27         DEPEND=">=dev-vcs/bzr-2.6.0"
28 fi
29
30 case ${EAPI:-0} in
31         2|3|4|5|6) ;;
32         7) BDEPEND="${DEPEND}"; DEPEND="" ;;
33         *) die "${EBZR}: EAPI ${EAPI:-0} is not supported" ;;
34 esac
35
36 EXPORT_FUNCTIONS src_unpack
37
38 # @ECLASS-VARIABLE: EBZR_STORE_DIR
39 # @DESCRIPTION:
40 # The directory to store all fetched Bazaar live sources.
41 : ${EBZR_STORE_DIR:=${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/bzr-src}
42
43 # @ECLASS-VARIABLE: EBZR_UNPACK_DIR
44 # @DESCRIPTION:
45 # The working directory where the sources are copied to.
46 : ${EBZR_UNPACK_DIR:=${WORKDIR}/${P}}
47
48 # @ECLASS-VARIABLE: EBZR_INIT_REPO_CMD
49 # @DESCRIPTION:
50 # The Bazaar command to initialise a shared repository.
51 : ${EBZR_INIT_REPO_CMD:="bzr init-repository --no-trees"}
52
53 # @ECLASS-VARIABLE: EBZR_FETCH_CMD
54 # @DESCRIPTION:
55 # The Bazaar command to fetch the sources.
56 : ${EBZR_FETCH_CMD:="bzr branch --no-tree"}
57
58 # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
59 # @DESCRIPTION:
60 # The Bazaar command to update the sources.
61 : ${EBZR_UPDATE_CMD:="bzr pull --overwrite-tags"}
62
63 # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
64 # @DESCRIPTION:
65 # The Bazaar command to export a branch.
66 : ${EBZR_EXPORT_CMD:="bzr export"}
67
68 # @ECLASS-VARIABLE: EBZR_CHECKOUT_CMD
69 # @DESCRIPTION:
70 # The Bazaar command to checkout a branch.
71 : ${EBZR_CHECKOUT_CMD:="bzr checkout --lightweight -q"}
72
73 # @ECLASS-VARIABLE: EBZR_REVNO_CMD
74 # @DESCRIPTION:
75 # The Bazaar command to list a revision number of the branch.
76 : ${EBZR_REVNO_CMD:="bzr revno"}
77
78 # @ECLASS-VARIABLE: EBZR_OPTIONS
79 # @DEFAULT_UNSET
80 # @DESCRIPTION:
81 # The options passed to the fetch and update commands.
82
83 # @ECLASS-VARIABLE: EBZR_REPO_URI
84 # @DEFAULT_UNSET
85 # @REQUIRED
86 # @DESCRIPTION:
87 # The repository URI for the source package.
88 #
89 # Note: If the ebuild uses an sftp:// URI, then the eclass will depend
90 # 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_PROJECT
104 # @DESCRIPTION:
105 # The project name of your ebuild.  Normally, the branch will be stored
106 # in the ${EBZR_STORE_DIR}/${EBZR_PROJECT} directory.
107 #
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}}
112
113 # @ECLASS-VARIABLE: EBZR_BRANCH
114 # @DEFAULT_UNSET
115 # @DESCRIPTION:
116 # The directory where to store the branch within a shared repository,
117 # relative to ${EBZR_STORE_DIR}/${EBZR_PROJECT}.
118 #
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.
123 #
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.
127
128 # @ECLASS-VARIABLE: EBZR_REVISION
129 # @DEFAULT_UNSET
130 # @DESCRIPTION:
131 # Revision to fetch, defaults to the latest
132 # (see http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec).
133
134 # @ECLASS-VARIABLE: EBZR_OFFLINE
135 # @DESCRIPTION:
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
138 # by users.
139 : ${EBZR_OFFLINE=${EVCS_OFFLINE}}
140
141 # @ECLASS-VARIABLE: EBZR_WORKDIR_CHECKOUT
142 # @DEFAULT_UNSET
143 # @DESCRIPTION:
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.
146
147 # @FUNCTION: bzr_initial_fetch
148 # @USAGE: <repository URI> <branch directory>
149 # @DESCRIPTION:
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
154
155         if [[ -n "${EBZR_OFFLINE}" ]]; then
156                 ewarn "EBZR_OFFLINE cannot be used when there is no local branch yet."
157         fi
158
159         # fetch branch
160         einfo "bzr branch start -->"
161         einfo "   repository: ${repo_uri} => ${branch_dir}"
162
163         ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repo_uri}" "${branch_dir}" \
164                 || die "${EBZR}: can't branch from ${repo_uri}"
165 }
166
167 # @FUNCTION: bzr_update
168 # @USAGE: <repository URI> <branch directory>
169 # @DESCRIPTION:
170 # Internal function, updates the source code from a repository, using
171 # ${EBZR_UPDATE_CMD}.
172 bzr_update() {
173         local repo_uri=$1 branch_dir=$2
174
175         if [[ -n "${EBZR_OFFLINE}" ]]; then
176                 einfo "skipping bzr pull -->"
177                 einfo "   repository: ${repo_uri}"
178         else
179                 # update branch
180                 einfo "bzr pull start -->"
181                 einfo "   repository: ${repo_uri}"
182
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}"
187                 popd > /dev/null
188         fi
189 }
190
191 # @FUNCTION: bzr_fetch
192 # @DESCRIPTION:
193 # Wrapper function to fetch sources from a Bazaar repository with
194 # bzr branch or bzr pull, depending on whether there is an existing
195 # working copy.
196 bzr_fetch() {
197         local repo_dir branch_dir
198         local save_sandbox_write=${SANDBOX_WRITE}
199
200         [[ -n ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty"
201
202         if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
203                 addwrite /
204                 mkdir -p "${EBZR_STORE_DIR}" \
205                         || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}"
206                 SANDBOX_WRITE=${save_sandbox_write}
207         fi
208
209         pushd "${EBZR_STORE_DIR}" > /dev/null \
210                 || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
211
212         repo_dir=${EBZR_STORE_DIR}/${EBZR_PROJECT}
213         branch_dir=${repo_dir}${EBZR_BRANCH:+/${EBZR_BRANCH}}
214
215         addwrite "${EBZR_STORE_DIR}"
216
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"
222                 fi
223
224                 if [[ -z ${EBZR_INITIAL_URI} ]]; then
225                         bzr_initial_fetch "${EBZR_REPO_URI}" "${branch_dir}"
226                 else
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" \
233                                         EBZR_OFFLINE="" \
234                                         bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
235                         fi
236                 fi
237         else
238                 bzr_update "${EBZR_REPO_URI}" "${branch_dir}"
239         fi
240
241         # Restore sandbox environment
242         SANDBOX_WRITE=${save_sandbox_write}
243
244         cd "${branch_dir}" || die "${EBZR}: can't chdir to ${branch_dir}"
245
246         # Save revision number in environment. #311101
247         export EBZR_REVNO=$(${EBZR_REVNO_CMD})
248
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"
253         else
254                 einfo "exporting ..."
255                 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} \
256                         "${EBZR_UNPACK_DIR}" . || die "${EBZR}: export failed"
257         fi
258         einfo \
259                 "revision ${EBZR_REVISION:-${EBZR_REVNO}} is now in ${EBZR_UNPACK_DIR}"
260
261         popd > /dev/null
262 }
263
264 # @FUNCTION: bzr_src_unpack
265 # @DESCRIPTION:
266 # Default src_unpack(), calls bzr_fetch.
267 bzr_src_unpack() {
268         bzr_fetch
269 }