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

Diff of /eclass/subversion.eclass

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

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

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.41

  ViewVC Help
Powered by ViewVC 1.1.20