Gentoo Archives: gentoo-commits

From: "Ulrich Mueller (ulm)" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in eclass: bzr.eclass
Date: Sat, 25 Oct 2008 12:17:28
Message-Id: E1Kti55-000480-Jw@stork.gentoo.org
1 ulm 08/10/25 12:17:23
2
3 Added: bzr.eclass
4 Log:
5 Initial import.
6
7 Revision Changes Path
8 1.1 eclass/bzr.eclass
9
10 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/bzr.eclass?rev=1.1&view=markup
11 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/eclass/bzr.eclass?rev=1.1&content-type=text/plain
12
13 Index: bzr.eclass
14 ===================================================================
15 # Copyright 1999-2008 Gentoo Foundation
16 # Distributed under the terms of the GNU General Public License v2
17 # $Header: /var/cvsroot/gentoo-x86/eclass/bzr.eclass,v 1.1 2008/10/25 12:17:23 ulm Exp $
18 #
19 # @ECLASS: bzr.eclass
20 # @MAINTAINER:
21 # Jorge Manuel B. S. Vicetto <jmbsvicetto@g.o>,
22 # Ulrich Mueller <ulm@g.o>,
23 # and anyone who wants to help
24 # @BLURB: This eclass provides support to use the Bazaar DSCM
25 # @DESCRIPTION:
26 # The bzr.eclass provides support for apps using the bazaar DSCM
27 # (distributed source control management system).
28 # The eclass was originally derived from the git eclass.
29 #
30 # Note: Just set EBZR_REPO_URI to the url of the branch and the src_unpack
31 # this eclass provides will put an export of the branch in ${WORKDIR}/${PN}.
32
33 inherit eutils
34
35 EBZR="bzr.eclass"
36
37 EXPORT_FUNCTIONS src_unpack
38
39 HOMEPAGE="http://bazaar-vcs.org/"
40 DESCRIPTION="Based on the ${EBZR} eclass"
41
42 DEPEND=">=dev-util/bzr-1.5"
43
44 # @ECLASS-VARIABLE: EBZR_STORE_DIR
45 # @DESCRIPTION:
46 # The dir to store the bzr sources.
47 EBZR_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/bzr-src"
48
49 # @ECLASS-VARIABLE: EBZR_FETCH_CMD
50 # @DESCRIPTION:
51 # The bzr command to fetch the sources.
52 EBZR_FETCH_CMD="bzr branch"
53
54 # @ECLASS-VARIABLE: EBZR_UPDATE_CMD
55 # @DESCRIPTION:
56 # The bzr command to update the sources.
57 EBZR_UPDATE_CMD="bzr pull"
58
59 # @ECLASS-VARIABLE: EBZR_DIFFSTAT_CMD
60 # @DESCRIPTION:
61 # The bzr command to get the diffstat output.
62 EBZR_DIFFSTAT_CMD="bzr diff"
63
64 # @ECLASS-VARIABLE: EBZR_EXPORT_CMD
65 # @DESCRIPTION:
66 # The bzr command to export a branch.
67 EBZR_EXPORT_CMD="bzr export"
68
69 # @ECLASS-VARIABLE: EBZR_REVNO_CMD
70 # @DESCRIPTION:
71 # The bzr command to list revision number of the branch.
72 EBZR_REVNO_CMD="bzr revno"
73
74 # @ECLASS-VARIABLE: EBZR_OPTIONS
75 # @DESCRIPTION:
76 # The options passed to the fetch and update commands.
77 EBZR_OPTIONS="${EBZR_OPTIONS:-}"
78
79 # @ECLASS-VARIABLE: EBZR_REPO_URI
80 # @DESCRIPTION:
81 # The repository uri for the source package.
82 #
83 # @CODE
84 # Supported protocols:
85 # - http://
86 # - https://
87 # - sftp://
88 # - rsync://
89 # - lp://
90 # @CODE
91 #
92 # Note: lp = https://launchpad.net
93 EBZR_REPO_URI="${EBZR_REPO_URI:-}"
94
95 # @ECLASS-VARIABLE: EBZR_BOOTSTRAP
96 # @DESCRIPTION:
97 # Bootstrap script or command like autogen.sh or etc.
98 EBZR_BOOTSTRAP="${EBZR_BOOTSTRAP:-}"
99
100 # @ECLASS-VARIABLE: EBZR_PATCHES
101 # @DESCRIPTION:
102 # bzr eclass can apply patches in bzr_bootstrap().
103 # you can use regexp in this valiable like *.diff or *.patch or etc.
104 # NOTE: this patches will applied before EBZR_BOOTSTRAP is processed.
105 #
106 # Patches are searched both in ${PWD} and ${FILESDIR}, if not found in either
107 # location, the installation dies.
108 EBZR_PATCHES="${EBZR_PATCHES:-}"
109
110 # @ECLASS-VARIABLE: EBZR_BRANCH
111 # @DESCRIPTION:
112 # The branch to fetch in bzr_fetch().
113 #
114 # default: trunk
115 EBZR_BRANCH="${EBZR_BRANCH:-trunk}"
116
117 # @ECLASS-VARIABLE: EBZR_REVISION
118 # @DESCRIPTION:
119 # Revision to get, if not latest (see http://bazaar-vcs.org/BzrRevisionSpec)
120 EBZR_REVISION="${EBZR_REVISION:-}"
121
122 # @ECLASS-VARIABLE: EBZR_CACHE_DIR
123 # @DESCRIPTION:
124 # The dir to store the source for the package, relative to EBZR_STORE_DIR.
125 #
126 # default: ${PN}
127 EBZR_CACHE_DIR="${EBZR_CACHE_DIR:-${PN}}"
128
129 # @FUNCTION: bzr_fetch
130 # @DESCRIPTION:
131 # Wrapper function to fetch sources from bazaar via bzr fetch or bzr update,
132 # depending on whether there is an existing working copy in ${EBZR_BRANCH_DIR}.
133 bzr_fetch() {
134 local EBZR_BRANCH_DIR
135
136 # EBZR_REPO_URI is empty.
137 [[ ${EBZR_REPO_URI} ]] || die "${EBZR}: EBZR_REPO_URI is empty."
138
139 # check for the protocol or pull from a local repo.
140 if [[ -z ${EBZR_REPO_URI%%:*} ]] ; then
141 case ${EBZR_REPO_URI%%:*} in
142 # lp:// is https://launchpad.net
143 http|https|rsync|sftp|lp)
144 ;;
145 *)
146 die "${EBZR}: fetch from ${EBZR_REPO_URI%:*} is not yet implemented."
147 ;;
148 esac
149 fi
150
151 if [[ ! -d ${EBZR_STORE_DIR} ]] ; then
152 debug-print "${FUNCNAME}: initial branch. creating bzr directory"
153 addwrite /
154 mkdir -p "${EBZR_STORE_DIR}" \
155 || die "${EBZR}: can't mkdir ${EBZR_STORE_DIR}."
156 export SANDBOX_WRITE="${SANDBOX_WRITE%%:/}"
157 fi
158
159 cd -P "${EBZR_STORE_DIR}" || die "${EBZR}: can't chdir to ${EBZR_STORE_DIR}"
160
161 EBZR_BRANCH_DIR="${EBZR_STORE_DIR}/${EBZR_CACHE_DIR}"
162
163 addwrite "${EBZR_STORE_DIR}"
164 addwrite "${EBZR_BRANCH_DIR}"
165
166 debug-print "${FUNCNAME}: EBZR_OPTIONS = ${EBZR_OPTIONS}"
167
168 local repository
169
170 if [[ ${EBZR_REPO_URI} == */* ]]; then
171 repository="${EBZR_REPO_URI}${EBZR_BRANCH}"
172 else
173 repository="${EBZR_REPO_URI}"
174 fi
175
176 if [[ ! -d ${EBZR_BRANCH_DIR} ]] ; then
177 # fetch branch
178 einfo "bzr branch start -->"
179 einfo " repository: ${repository} => ${EBZR_BRANCH_DIR}"
180
181 ${EBZR_FETCH_CMD} ${EBZR_OPTIONS} "${repository}" "${EBZR_BRANCH_DIR}" \
182 || die "${EBZR}: can't branch from ${repository}."
183
184 else
185 # update branch
186 einfo "bzr pull start -->"
187 einfo " repository: ${repository}"
188
189 cd "${EBZR_BRANCH_DIR}"
190 ${EBZR_UPDATE_CMD} ${EBZR_OPTIONS} "${repository}" \
191 || die "${EBZR}: can't merge from ${repository}."
192 ${EBZR_DIFFSTAT_CMD}
193 fi
194
195 cd "${EBZR_BRANCH_DIR}"
196
197 einfo "exporting ..."
198 ${EBZR_EXPORT_CMD} ${EBZR_REVISION:+-r ${EBZR_REVISION}} "${WORKDIR}/${P}" \
199 || die "${EBZR}: export failed"
200
201 local revision
202 if [[ -n "${EBZR_REVISION}" ]]; then
203 revision="${EBZR_REVISION}"
204 else
205 revision=$(${EBZR_REVNO_CMD} "${EBZR_BRANCH_DIR}")
206 fi
207
208 einfo "Revision ${revision} is now in ${WORKDIR}/${P}"
209
210 cd "${WORKDIR}"
211 }
212
213 # @FUNCTION: bzr_bootstrap
214 # @DESCRIPTION:
215 # Apply patches in ${EBZR_PATCHES} and run ${EBZR_BOOTSTRAP} if specified
216 bzr_bootstrap() {
217 local patch lpatch
218
219 cd "${S}"
220
221 if [[ -n ${EBZR_PATCHES} ]] ; then
222 einfo "apply patches -->"
223
224 for patch in ${EBZR_PATCHES} ; do
225 if [[ -f ${patch} ]] ; then
226 epatch ${patch}
227 else
228 for lpatch in "${FILESDIR}"/${patch} ; do
229 if [[ -f ${lpatch} ]] ; then
230 epatch ${lpatch}
231 else
232 die "${EBZR}: ${patch} is not found"
233 fi
234 done
235 fi
236 done
237 fi
238
239 if [[ -n ${EBZR_BOOTSTRAP} ]] ; then
240 einfo "begin bootstrap -->"
241
242 if [[ -f ${EBZR_BOOTSTRAP} ]] && [[ -x ${EBZR_BOOTSTRAP} ]] ; then
243 einfo " bootstrap with a file: ${EBZR_BOOTSTRAP}"
244 "./${EBZR_BOOTSTRAP}" \
245 || die "${EBZR}: can't execute EBZR_BOOTSTRAP."
246 else
247 einfo " bootstrap with commands: ${EBZR_BOOTSTRAP}"
248 "${EBZR_BOOTSTRAP}" \
249 || die "${EBZR}: can't eval EBZR_BOOTSTRAP."
250 fi
251 fi
252 }
253
254 # @FUNCTION: bzr_src_unpack
255 # @DESCRIPTION:
256 # default src_unpack. fetch and bootstrap.
257 bzr_src_unpack() {
258 bzr_fetch || die "${EBZR}: unknown problem in bzr_fetch()."
259 bzr_bootstrap || die "${EBZR}: unknown problem in bzr_bootstrap()."
260 }