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

Diff of /eclass/bzr.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20