/[gentoo-x86]/eclass/bzr.eclass
Gentoo

Contents of /eclass/bzr.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations) (download)
Wed Jul 8 09:47:38 2009 UTC (5 years ago) by fauli
Branch: MAIN
Changes since 1.1: +109 -61 lines
Import bzr.eclass from Bazaar overlay:

* Make it EAPI aware
* Use lightweight checkout to save disk space, including migration path for previously fetched sources
* Support sftp repositories
* Do some code clean up
* Rework documentation

1 # Copyright 1999-2009 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: $
4 #
5 # @ECLASS: bzr.eclass
6 # @MAINTAINER:
7 # Jorge Manuel B. S. Vicetto <jmbsvicetto@gentoo.org>,
8 # Ulrich Mueller <ulm@gentoo.org>,
9 # Christian Faulhammer <fauli@gentoo.org>
10 # Mark Lee <bzr-gentoo-overlay@lazymalevolence.com>,
11 # and anyone who wants to help
12 # @BLURB: This eclass provides support to use the Bazaar DSCM
13 # @DESCRIPTION:
14 # The bzr.eclass provides support for apps using the bazaar DSCM
15 # (distributed source control management system).
16 # The eclass was originally derived from the git eclass.
17 #
18 # Note: Just set EBZR_REPO_URI to the URI of the branch and the src_unpack()
19 # of this eclass will put an export of the branch in ${WORKDIR}/${PN}.
20
21 inherit eutils
22
23 EBZR="bzr.eclass"
24
25 case "${EAPI:-0}" in
26 0|1) EXPORT_FUNCTIONS src_unpack ;;
27 *) EXPORT_FUNCTIONS src_unpack src_prepare ;;
28 esac
29
30 HOMEPAGE="http://bazaar-vcs.org/"
31 DESCRIPTION="Based on the ${EBZR} eclass"
32
33 DEPEND=">=dev-util/bzr-1.5"
34
35 # @ECLASS-VARIABLE: EBZR_STORE_DIR
36 # @DESCRIPTION:
37 # The directory to store all fetched Bazaar live sources.
38 EBZR_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/bzr-src"
39
40 # @ECLASS-VARIABLE: EBZR_FETCH_CMD
41 # @DESCRIPTION:
42 # The Bazaar command to fetch the sources.
43 EBZR_FETCH_CMD="bzr checkout --lightweight"
44
45 # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
46 # @DESCRIPTION:
47 # The Bazaar command to update the sources.
48 EBZR_UPDATE_CMD="bzr update"
49
50 # @ECLASS-VARIABLE: EBZR_DIFF_CMD
51 # @DESCRIPTION:
52 # The Bazaar command to get the diff output.
53 EBZR_DIFF_CMD="bzr diff"
54
55 # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
56 # @DESCRIPTION:
57 # The Bazaar command to export a branch.
58 EBZR_EXPORT_CMD="bzr export"
59
60 # @ECLASS-VARIABLE: EBZR_REVNO_CMD
61 # @DESCRIPTION:
62 # The Bazaar command to list a revision number of the branch.
63 EBZR_REVNO_CMD="bzr revno"
64
65 # @ECLASS-VARIABLE: EBZR_OPTIONS
66 # @DESCRIPTION:
67 # The options passed to the fetch and update commands.
68 EBZR_OPTIONS="${EBZR_OPTIONS:-}"
69
70 # @ECLASS-VARIABLE: EBZR_REPO_URI
71 # @DESCRIPTION:
72 # The repository URI for the source package.
73 #
74 # @CODE
75 # Supported protocols:
76 # - http://
77 # - https://
78 # - sftp://
79 # - rsync://
80 # - lp:
81 # @CODE
82 #
83 # Note: lp: seems to be an alias for https://launchpad.net
84 EBZR_REPO_URI="${EBZR_REPO_URI:-}"
85
86 # @ECLASS-VARIABLE: EBZR_BOOTSTRAP
87 # @DESCRIPTION:
88 # Bootstrap script or command like autogen.sh or etc.
89 EBZR_BOOTSTRAP="${EBZR_BOOTSTRAP:-}"
90
91 # @ECLASS-VARIABLE: EBZR_PATCHES
92 # @DESCRIPTION:
93 # bzr eclass can apply patches in bzr_bootstrap().
94 # You can use regular expressions in this variable like *.diff or
95 # *.patch and the like.
96 # NOTE: These patches will bei applied before EBZR_BOOTSTRAP is processed.
97 #
98 # Patches are searched both in ${PWD} and ${FILESDIR}, if not found in either
99 # location, the installation dies.
100 EBZR_PATCHES="${EBZR_PATCHES:-}"
101
102 # @ECLASS-VARIABLE: EBZR_REVISION
103 # @DESCRIPTION:
104 # Revision to fetch, defaults to the latest (see
105 # http://bazaar-vcs.org/BzrRevisionSpec or bzr help revisionspec)
106 EBZR_REVISION="${EBZR_REVISION:-}"
107
108 # @ECLASS-VARIABLE: EBZR_CACHE_DIR
109 # @DESCRIPTION:
110 # The directory to store the source for the package, relative to
111 # EBZR_STORE_DIR.
112 #
113 # default: ${PN}
114 EBZR_CACHE_DIR="${EBZR_CACHE_DIR:-${PN}}"
115
116 # @FUNCTION: bzr_initial_fetch
117 # @DESCRIPTION:
118 # Retrieves the source code from a repository for the first time, via
119 # ${EBZR_FETCH_CMD}.
120 bzr_initial_fetch() {
121 local repository="${1}";
122 local branch_dir="${2}";
123
124 # fetch branch
125 einfo "bzr fetch start -->"
126 einfo " repository: ${repository} => ${branch_dir}"
127
128 ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repository}" "${branch_dir}" \
129 || die "${EBZR}: can't branch from ${repository}."
130 }
131
132 # @FUNCTION: bzr_update
133 # @DESCRIPTION:
134 # Updates the source code from a repository, via ${EBZR_UPDATE_CMD}.
135 bzr_update() {
136 local repository="${1}";
137
138 # update branch
139 einfo "bzr update start -->"
140 einfo " repository: ${repository}"
141
142 pushd "${EBZR_BRANCH_DIR}" > /dev/null
143 ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} \
144 || die "${EBZR}: can't update from ${repository}."
145 popd > /dev/null
146 }
147
148
149 # @FUNCTION: bzr_fetch
150 # @DESCRIPTION:
151 # Wrapper function to fetch sources from a Bazaar repository via bzr
152 # fetch or bzr update, depending on whether there is an existing
153 # working copy in ${EBZR_BRANCH_DIR}.
154 bzr_fetch() {
155 local EBZR_BRANCH_DIR
156
157 # EBZR_REPO_URI is empty.
158 [[ ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty."
159
160 # check for the protocol or pull from a local repo.
161 if [[ -z ${EBZR_REPO_URI%%:*} ]] ; then
162 case ${EBZR_REPO_URI%%:*} in
163 # lp: seems to be an alias to https://launchpad.net
164 http|https|rsync|lp)
165 ;;
166 sftp)
167 if ! built_with_use --missing true dev-util/bzr sftp; then
168 eerror "To fetch sources from ${EBZR_REPO_URI} you need SFTP"
169 eerror "support in dev-util/bzr."
170 die "Please, rebuild dev-util/bzr with the sftp USE flag enabled."
171 fi
172 ;;
173 *)
174 die "${EBZR}: fetch from ${EBZR_REPO_URI%:*} is not yet implemented."
175 ;;
176 esac
177 fi
178
179 if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
180 debug-print "${FUNCNAME}: initial branch. Creating bzr directory"
181 addwrite /
182 mkdir -p "${EBZR_STORE_DIR}" \
183 || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}."
184 export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}"
185 fi
186
187 pushd "${EBZR_STORE_DIR}" > /dev/null || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
188
189 EBZR_BRANCH_DIR="${EBZR_STORE_DIR}/${EBZR_CACHE_DIR}"
190
191 addwrite "${EBZR_STORE_DIR}"
192 addwrite "${EBZR_BRANCH_DIR}"
193
194 debug-print "${FUNCNAME}: EBZR_OPTIONS = ${EBZR_OPTIONS}"
195
196 # Run bzr_initial_fetch() only if the branch has not been pulled
197 # before or if the existing local copy is a full checkout (as did
198 # an older version of bzr.eclass)
199 if [[ ! -d ${EBZR_BRANCH_DIR} ]] ; then
200 bzr_initial_fetch "${EBZR_REPO_URI}" "${EBZR_BRANCH_DIR}"
201 elif [[ -d "${EBZR_BRANCH_DIR}"/.bzr/repository/ ]]; then
202 einfo "Re-fetching the branch to save space..."
203 rm -rf "${EBZR_BRANCH_DIR}"
204 bzr_initial_fetch "${EBZR_REPO_URI}" "${EBZR_BRANCH_DIR}"
205 else
206 bzr_update "${EBZR_REPO_URI}" "${EBZR_BRANCH_DIR}"
207 fi
208
209 cd "${EBZR_BRANCH_DIR}"
210
211 einfo "exporting ..."
212 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} "${WORKDIR}/${P}" \
213 || die "${EBZR}: export failed"
214
215 local revision
216 if [[ -n "${EBZR_REVISION}" ]]; then
217 revision="${EBZR_REVISION}"
218 else
219 revision=$(${EBZR_REVNO_CMD} "${EBZR_BRANCH_DIR}")
220 fi
221
222 einfo "Revision ${revision} is now in ${WORKDIR}/${P}"
223
224 popd > /dev/null
225 }
226
227 # @FUNCTION: bzr_bootstrap
228 # @DESCRIPTION:
229 # Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified.
230 bzr_bootstrap() {
231 local patch lpatch
232
233 pushd "${S}" > /dev/null
234
235 if [[ -n ${EBZR_PATCHES} ]] ; then
236 einfo "apply patches -->"
237
238 for patch in ${EBZR_PATCHES} ; do
239 if [[ -f ${patch} ]] ; then
240 epatch ${patch}
241 else
242 # This loop takes care of wildcarded patches given via
243 # EBZR_PATCHES in an ebuild
244 for lpatch in "${FILESDIR}"/${patch} ; do
245 if [[ -f ${lpatch} ]] ; then
246 epatch ${lpatch}
247 else
248 die "${EBZR}: ${patch} is not found"
249 fi
250 done
251 fi
252 done
253 fi
254
255 if [[ -n ${EBZR_BOOTSTRAP} ]] ; then
256 einfo "begin bootstrap -->"
257
258 if [[ -f ${EBZR_BOOTSTRAP} ]] && [[ -x ${EBZR_BOOTSTRAP} ]] ; then
259 einfo " bootstrap with a file: ${EBZR_BOOTSTRAP}"
260 "./${EBZR_BOOTSTRAP}" \
261 || die "${EBZR}: can't execute EBZR_BOOTSTRAP."
262 else
263 einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}"
264 "${EBZR_BOOTSTRAP}" \
265 || die "${EBZR}: can't eval EBZR_BOOTSTRAP."
266 fi
267 fi
268
269 popd > /dev/null
270 }
271
272 # @FUNCTION: bzr_src_unpack
273 # @DESCRIPTION:
274 # Default src_unpack(). Includes bzr_fetch() and bootstrap().
275 bzr_src_unpack() {
276 if ! [ -z ${EBZR_BRANCH} ]; then
277 # This test will go away on 01 Jul 2010
278 eerror "This ebuild uses EBZR_BRANCH which is not supported anymore"
279 eerror "by the bzr.eclass. Please report this to the ebuild's maintainer."
280 die "EBZR_BRANCH still defined"
281 fi
282 bzr_fetch || die "${EBZR}: unknown problem in bzr_fetch()."
283 case "${EAPI:-0}" in
284 0|1) bzr_src_prepare ;;
285 esac
286 }
287
288 # @FUNCTION: bzr_src_prepare
289 # @DESCRIPTION:
290 # Default src_prepare(). Executes bzr_bootstrap() for patch
291 # application and Make file generation (if needed).
292 bzr_src_prepare() {
293 bzr_bootstrap || die "${EBZR}: unknown problem in bzr_bootstrap()."
294 }

  ViewVC Help
Powered by ViewVC 1.1.20