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

Diff of /eclass/subversion.eclass

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

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

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.44

  ViewVC Help
Powered by ViewVC 1.1.20