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

Contents of /eclass/subversion.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.42 - (show annotations) (download)
Mon Apr 23 18:55:15 2007 UTC (7 years, 6 months ago) by cardoe
Branch: MAIN
Changes since 1.41: +1 -2 lines
should not contain HOMEPAGE as it's up to individual ebuilds to set this, and should not point to SubVersion.

1 # Copyright 1999-2007 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.41 2007/04/01 14:48:37 hattya Exp $
4
5 ## --------------------------------------------------------------------------- #
6 # Author: Akinori Hattori <hattya@gentoo.org>
7 #
8 # The subversion eclass is written to fetch the software sources from
9 # subversion repositories like the cvs eclass.
10 #
11 #
12 # Description:
13 # If you use this eclass, the ${S} is ${WORKDIR}/${P}.
14 # It is necessary to define the ESVN_REPO_URI variable at least.
15 #
16 ## --------------------------------------------------------------------------- #
17
18 inherit eutils
19
20 ESVN="subversion.eclass"
21
22 EXPORT_FUNCTIONS src_unpack
23
24 DESCRIPTION="Based on the ${ECLASS} eclass"
25
26
27 ## -- add subversion in DEPEND
28 #
29 DEPEND="dev-util/subversion"
30
31
32 ## -- ESVN_STORE_DIR: subversion sources store directory
33 #
34 ESVN_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/svn-src"
35
36
37 ## -- ESVN_FETCH_CMD: subversion fetch command
38 #
39 ESVN_FETCH_CMD="svn checkout"
40
41 ## -- ESVN_UPDATE_CMD: subversion update command
42 #
43 ESVN_UPDATE_CMD="svn update"
44
45
46 ## -- ESVN_OPTIONS:
47 #
48 # the options passed to checkout or update.
49 #
50 : ESVN_OPTIONS=${ESVN_OPTIONS:=}
51
52
53 ## -- ESVN_REPO_URI: repository uri
54 #
55 # e.g. http://foo/trunk, svn://bar/trunk
56 #
57 # supported protocols:
58 # http://
59 # https://
60 # svn://
61 # svn+ssh://
62 #
63 : ESVN_REPO_URI=${ESVN_REPO_URI:=}
64
65
66 ## -- ESVN_PROJECT: project name of your ebuild (= name space)
67 #
68 # subversion eclass will check out the subversion repository like:
69 #
70 # ${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}
71 #
72 # so if you define ESVN_REPO_URI as http://svn.collab.net/repo/svn/trunk or
73 # http://svn.collab.net/repo/svn/trunk/. and PN is subversion-svn.
74 # it will check out like:
75 #
76 # ${ESVN_STORE_DIR}/subversion/trunk
77 #
78 # this is not used in order to declare the name of the upstream project.
79 # so that you can declare this like:
80 #
81 # # jakarta commons-loggin
82 # ESVN_PROJECT=commons/logging
83 #
84 # default: ${PN/-svn}.
85 #
86 : ESVN_PROJECT=${ESVN_PROJECT:=${PN/-svn}}
87
88
89 ## -- ESVN_BOOTSTRAP:
90 #
91 # bootstrap script or command like autogen.sh or etc..
92 #
93 : ESVN_BOOTSTRAP=${ESVN_BOOTSTRAP:=}
94
95
96 ## -- ESVN_PATCHES:
97 #
98 # subversion eclass can apply pathces in subversion_bootstrap().
99 # you can use regexp in this valiable like *.diff or *.patch or etc.
100 # NOTE: this patches will apply before eval ESVN_BOOTSTRAP.
101 #
102 # the process of applying the patch is:
103 # 1. just epatch it, if the patch exists in the path.
104 # 2. scan it under FILESDIR and epatch it, if the patch exists in FILESDIR.
105 # 3. die.
106 #
107 : ESVN_PATCHES=${ESVN_PATCHES:=}
108
109
110 ## -- ESVN_RESTRICT:
111 #
112 # this should be a space delimited list of subversion eclass features to
113 # restrict.
114 # export)
115 # don't export the working copy to S.
116 #
117 : ESVN_RESTRICT=${ESVN_RESTRICT:=}
118
119
120 ## -- subversion_fetch() ----------------------------------------------------- #
121 #
122 # @param $1 - a repository URI. default is the ESVN_REPO_URI.
123 # @param $2 - a check out path in S.
124 #
125 function subversion_fetch() {
126
127 local repo_uri="$(subversion__get_repository_uri "${1}")"
128 local S_dest="${2}"
129
130 # check for the protocol
131 local protocol="${repo_uri%%:*}"
132
133 case "${protocol}" in
134 http|https)
135 if built_with_use dev-util/subversion nowebdav; then
136 echo
137 eerror "In order to emerge this package, you need to"
138 eerror "re-emerge subversion with USE=-nowebdav"
139 echo
140 die "${ESVN}: please run 'USE=-nowebdav emerge subversion'"
141 fi
142 ;;
143 svn|svn+ssh)
144 ;;
145 *)
146 die "${ESVN}: fetch from "${protocol}" is not yet implemented."
147 ;;
148 esac
149
150 # every time
151 addread "/etc/subversion"
152 addwrite "${ESVN_STORE_DIR}"
153
154 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then
155 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
156 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
157 fi
158
159 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
160
161 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
162 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
163
164 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
165 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
166 debug-print "${FUNCNAME}: options = \"${options}\""
167
168 if [[ ! -d "${wc_path}/.svn" ]]; then
169 # first check out
170 einfo "subversion check out start -->"
171 einfo " repository: ${repo_uri}"
172
173 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
174
175 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
176 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
177 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
178
179 else
180 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
181
182 if [ "${ESVN_WC_URL}" != "$(subversion__get_repository_uri "${repo_uri}" 1)" ]; then
183 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
184 fi
185
186 # update working copy
187 einfo "subversion update start -->"
188 einfo " repository: ${repo_uri}"
189
190 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
191
192 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
193 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
194
195 fi
196
197 einfo " working copy: ${wc_path}"
198
199 if ! has "export" ${ESVN_RESTRICT}; then
200 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
201
202 local S="${S}/${S_dest}"
203
204 # export to the ${WORKDIR}
205 #* "svn export" has a bug. see http://bugs.gentoo.org/119236
206 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
207 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
208 fi
209
210 echo
211
212 }
213
214
215 ## -- subversion_bootstrap() ------------------------------------------------ #
216 #
217 function subversion_bootstrap() {
218
219 if has "export" ${ESVN_RESTRICT}; then
220 return
221 fi
222
223 cd "${S}"
224
225 if [[ -n "${ESVN_PATCHES}" ]]; then
226 einfo "apply patches -->"
227
228 local p=
229
230 for p in ${ESVN_PATCHES}; do
231 if [[ -f "${p}" ]]; then
232 epatch "${p}"
233
234 else
235 local q=
236
237 for q in ${FILESDIR}/${p}; do
238 if [[ -f "${q}" ]]; then
239 epatch "${q}"
240
241 else
242 die "${ESVN}; ${p} is not found"
243
244 fi
245 done
246 fi
247 done
248
249 echo
250
251 fi
252
253 if [[ -n "${ESVN_BOOTSTRAP}" ]]; then
254 einfo "begin bootstrap -->"
255
256 if [[ -f "${ESVN_BOOTSTRAP}" && -x "${ESVN_BOOTSTRAP}" ]]; then
257 einfo " bootstrap with a file: ${ESVN_BOOTSTRAP}"
258 eval "./${ESVN_BOOTSTRAP}" || die "${ESVN}: can't execute ESVN_BOOTSTRAP."
259
260 else
261 einfo " bootstrap with commands: ${ESVN_BOOTSTRAP}"
262 eval "${ESVN_BOOTSTRAP}" || die "${ESVN}: can't eval ESVN_BOOTSTRAP."
263
264 fi
265 fi
266
267 }
268
269
270 ## -- subversion_src_unpack() ------------------------------------------------ #
271 #
272 function subversion_src_unpack() {
273
274 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
275 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
276
277 }
278
279
280 ## -- subversion_wc_info() --------------------------------------------------- #
281 #
282 # @param $1 - repository URI. default is ESVN_REPO_URI.
283 #
284 function subversion_wc_info() {
285
286 local repo_uri="$(subversion__get_repository_uri "${1}")"
287 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
288
289 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
290 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
291
292 if [[ ! -e "${wc_path}" ]]; then
293 return 1
294 fi
295
296 local k
297
298 for k in url revision; do
299 export ESVN_WC_$(subversion__to_upper_case "${k}")="$(subversion__svn_info "${wc_path}" "${k}")"
300 done
301
302 }
303
304
305 ## -- Private Functions
306
307
308 ## -- subversion__svn_info() ------------------------------------------------- #
309 #
310 # @param $1 - a target.
311 # @param $2 - a key name.
312 #
313 function subversion__svn_info() {
314
315 local target="${1}"
316 local key="${2}"
317
318 env LC_ALL=C svn info "${target}" | grep -i "^${key}" | cut -d" " -f2-
319
320 }
321
322
323 ## -- subversion__get_repository_uri() --------------------------------------- #
324 #
325 # @param $1 - a repository URI.
326 # @param $2 - a peg revision is deleted from a return value if this is
327 # specified.
328 #
329 function subversion__get_repository_uri() {
330
331 local repo_uri="${1:-${ESVN_REPO_URI}}"
332 local remove_peg_revision="${2}"
333
334 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
335 debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
336
337 if [[ -z "${repo_uri}" ]]; then
338 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
339 fi
340
341 # delete trailing slash
342 if [[ -z "${repo_uri##*/}" ]]; then
343 repo_uri="${repo_uri%/}"
344 fi
345
346 if [[ -n "${remove_peg_revision}" ]]; then
347 if subversion__has_peg_revision "${repo_uri}"; then
348 repo_uri="${repo_uri%@*}"
349
350 debug-print "${FUNCNAME}: repo_uri has a peg revision"
351 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
352 fi
353 fi
354
355 echo "${repo_uri}"
356
357 }
358
359
360 ## -- subversion__get_wc_path() ---------------------------------------------- #
361 #
362 # @param $1 - a repository URI.
363 #
364 function subversion__get_wc_path() {
365
366 local repo_uri="$(subversion__get_repository_uri "${1}" 1)"
367
368 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
369
370 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
371
372 }
373
374
375 ## -- subversion__has_peg_revision() ----------------------------------------- #
376 #
377 # @param $1 - a repository URI.
378 #
379 function subversion__has_peg_revision() {
380
381 local repo_uri="${1}"
382
383 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
384
385 # repo_uri has peg revision ?
386 if [[ "${repo_uri}" != *@* ]]; then
387 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
388 return 1
389 fi
390
391 local peg_rev="${repo_uri##*@}"
392
393 case "$(subversion__to_upper_case "${peg_rev}")" in
394 [[:digit:]]*)
395 # NUMBER
396 ;;
397 HEAD|BASE|COMMITED|PREV)
398 ;;
399 {[^}]*})
400 # DATE
401 ;;
402 *)
403 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
404 return 1
405 ;;
406 esac
407
408 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
409
410 return 0
411
412 }
413
414
415 ## -- subversion__to_upper_case() ----------------------------------------- #
416 #
417 # @param $@ - the strings to upper case.
418 #
419 function subversion__to_upper_case() {
420 echo "${@}" | tr "[a-z]" "[A-Z]"
421 }

  ViewVC Help
Powered by ViewVC 1.1.20