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

Diff of /eclass/subversion.eclass

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

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

Legend:
Removed from v.1.31  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.20