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

Diff of /eclass/subversion.eclass

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

Revision 1.46 Revision 1.59
1# Copyright 1999-2008 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.46 2008/02/20 17:11:34 zlin Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.59 2008/05/15 13:27:40 zlin Exp $
4 4
5# @ECLASS: subversion.eclass 5# @ECLASS: subversion.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# Akinori Hattori <hattya@gentoo.org> 7# Akinori Hattori <hattya@gentoo.org>
8# Bo ├śrsted Andresen <zlin@gentoo.org> 8# Bo ├śrsted Andresen <zlin@gentoo.org>
11# 11#
12# @BLURB: The subversion eclass is written to fetch software sources from subversion repositories 12# @BLURB: The subversion eclass is written to fetch software sources from subversion repositories
13# @DESCRIPTION: 13# @DESCRIPTION:
14# The subversion eclass provides functions to fetch, patch and bootstrap 14# The subversion eclass provides functions to fetch, patch and bootstrap
15# software sources from subversion repositories. 15# software sources from subversion repositories.
16#
17# You must define the ESVN_REPO_URI variable before inheriting this eclass.
18 16
19inherit eutils 17inherit eutils
20 18
21ESVN="${ECLASS}" 19ESVN="${ECLASS}"
22 20
23EXPORT_FUNCTIONS src_unpack 21EXPORT_FUNCTIONS src_unpack pkg_preinst
24 22
25DESCRIPTION="Based on the ${ECLASS} eclass" 23DESCRIPTION="Based on the ${ECLASS} eclass"
26 24
27DEPEND="dev-util/subversion 25DEPEND="dev-util/subversion
28 net-misc/rsync" 26 net-misc/rsync"
39 37
40# @ECLASS-VARIABLE: ESVN_UPDATE_CMD 38# @ECLASS-VARIABLE: ESVN_UPDATE_CMD
41# @DESCRIPTION: 39# @DESCRIPTION:
42# subversion update command 40# subversion update command
43ESVN_UPDATE_CMD="svn update" 41ESVN_UPDATE_CMD="svn update"
42
43# @ECLASS-VARIABLE: ESVN_SWITCH_CMD
44# @DESCRIPTION:
45# subversion switch command
46ESVN_SWITCH_CMD="svn switch"
44 47
45# @ECLASS-VARIABLE: ESVN_OPTIONS 48# @ECLASS-VARIABLE: ESVN_OPTIONS
46# @DESCRIPTION: 49# @DESCRIPTION:
47# the options passed to checkout or update. If you want a specific revision see 50# the options passed to checkout or update. If you want a specific revision see
48# ESVN_REPO_URI instead of using -rREV. 51# ESVN_REPO_URI instead of using -rREV.
61# svn+ssh:// 64# svn+ssh://
62# 65#
63# to peg to a specific revision, append @REV to the repo's uri 66# to peg to a specific revision, append @REV to the repo's uri
64ESVN_REPO_URI="${ESVN_REPO_URI:-}" 67ESVN_REPO_URI="${ESVN_REPO_URI:-}"
65 68
69# @ECLASS-VARIABLE: ESVN_REVISION
70# @DESCRIPTION:
71# User configurable revision checkout or update to from the repository
72#
73# Useful for live svn or trunk svn ebuilds allowing the user to peg
74# to a specific revision
75#
76# Note: This should never be set in an ebuild!
77ESVN_REVISION="${ESVN_REVISION:-}"
78
66# @ECLASS-VARIABLE: ESVN_PROJECT 79# @ECLASS-VARIABLE: ESVN_PROJECT
67# @DESCRIPTION: 80# @DESCRIPTION:
68# project name of your ebuild (= name space) 81# project name of your ebuild (= name space)
69# 82#
70# subversion eclass will check out the subversion repository like: 83# subversion eclass will check out the subversion repository like:
107# restrict. 120# restrict.
108# export) 121# export)
109# don't export the working copy to S. 122# don't export the working copy to S.
110ESVN_RESTRICT="${ESVN_RESTRICT:-}" 123ESVN_RESTRICT="${ESVN_RESTRICT:-}"
111 124
125# @ECLASS-VARIABLE: ESVN_OFFLINE
126# @DESCRIPTION:
127# Set this variable to a non-empty value to disable the automatic updating of
128# an svn source tree. This is intended to be set outside the subversion source
129# tree by users.
130ESVN_OFFLINE="${ESVN_OFFLINE:-${ESCM_OFFLINE}}"
131
132# @ECLASS-VARIABLE: ESVN_UP_FREQ
133# @DESCRIPTION:
134# Set the minimum number of hours between svn up'ing in any given svn module. This is particularly
135# useful for split KDE ebuilds where we want to ensure that all submodules are compiled for the same
136# revision. It should also be kept user overrideable.
137ESVN_UP_FREQ="${ESVN_UP_FREQ:=}"
138
139# @ECLASS-VARIABLE: ESCM_LOGDIR
140# @DESCRIPTION:
141# User configuration variable. If set to a path such as e.g. /var/log/scm any
142# package inheriting from subversion.eclass will record svn revision to
143# ${CATEGORY}/${PN}.log in that path in pkg_preinst. This is not supposed to be
144# set by ebuilds/eclasses. It defaults to empty so users need to opt in.
145ESCM_LOGDIR="${ESCM_LOGDIR:=}"
146
112# @FUNCTION: subversion_fetch 147# @FUNCTION: subversion_fetch
113# @USAGE: [repo_uri] [destination] 148# @USAGE: [repo_uri] [destination]
114# @DESCRIPTION: 149# @DESCRIPTION:
115# Wrapper function to fetch sources from subversion via svn checkout or svn update, 150# Wrapper function to fetch sources from subversion via svn checkout or svn update,
116# depending on whether there is an existing working copy in ${ESVN_STORE_DIR}. 151# depending on whether there is an existing working copy in ${ESVN_STORE_DIR}.
117# 152#
118# Can take two optional parameters: 153# Can take two optional parameters:
119# repo_uri - a repository URI. default is ESVN_REPO_URI. 154# repo_uri - a repository URI. default is ESVN_REPO_URI.
120# destination - a check out path in S. 155# destination - a check out path in S.
121subversion_fetch() { 156subversion_fetch() {
122 local repo_uri="$(subversion__get_repository_uri "${1}")" 157 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
158 local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")"
123 local S_dest="${2}" 159 local S_dest="${2}"
160
161 if [[ -z ${repo_uri} ]]; then
162 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
163 fi
164
165 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}"
124 166
125 # check for the protocol 167 # check for the protocol
126 local protocol="${repo_uri%%:*}" 168 local protocol="${repo_uri%%:*}"
127 169
128 case "${protocol}" in 170 case "${protocol}" in
129 http|https) 171 http|https)
172 if ! built_with_use --missing true -o dev-util/subversion webdav-neon webdav-serf || \
130 if built_with_use dev-util/subversion nowebdav; then 173 built_with_use --missing false dev-util/subversion nowebdav ; then
131 echo 174 echo
132 eerror "In order to emerge this package, you need to" 175 eerror "In order to emerge this package, you need to"
133 eerror "re-emerge subversion with USE=-nowebdav" 176 eerror "reinstall Subversion with support for WebDAV."
177 eerror "Subversion requires either Neon or Serf to support WebDAV."
134 echo 178 echo
135 die "${ESVN}: please run 'USE=-nowebdav emerge subversion'" 179 die "${ESVN}: reinstall Subversion with support for WebDAV."
136 fi 180 fi
137 ;; 181 ;;
138 svn|svn+ssh) 182 svn|svn+ssh)
139 ;; 183 ;;
140 *) 184 *)
153 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}" 197 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
154 198
155 local wc_path="$(subversion__get_wc_path "${repo_uri}")" 199 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
156 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion" 200 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
157 201
202 [[ -n "${revision}" ]] && options="${options} -r ${revision}"
203
204 if [[ "${ESVN_OPTIONS}" = *-r* ]]; then
205 ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please"
206 ewarn "see \${ESVN_REPO_URI}"
207 fi
208
158 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\"" 209 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
159 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\"" 210 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
160 debug-print "${FUNCNAME}: options = \"${options}\"" 211 debug-print "${FUNCNAME}: options = \"${options}\""
161 212
162 if [[ ! -d ${wc_path}/.svn ]]; then 213 if [[ ! -d ${wc_path}/.svn ]]; then
214 if [[ -n ${ESVN_OFFLINE} ]]; then
215 ewarn "ESVN_OFFLINE cannot be used when the there is no existing checkout."
216 fi
163 # first check out 217 # first check out
164 einfo "subversion check out start -->" 218 einfo "subversion check out start -->"
165 einfo " repository: ${repo_uri}" 219 einfo " repository: ${repo_uri}${revision:+@}${revision}"
166 220
167 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}" 221 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
168 222
169 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}." 223 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
170 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}" 224 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
171 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}." 225 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
172 226
227 elif [[ -n ${ESVN_OFFLINE} ]]; then
228 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
229 if [[ -n ${ESVN_REVISION} && ${ESVN_REVISION} != ${ESVN_WC_REVISION} ]]; then
230 die "${ESVN}: You requested off-line updating and revision ${ESVN_REVISION} but only revision ${ESVN_WC_REVISION} is available locally."
231 fi
232 einfo "Fetching disabled: Using existing repository copy at revision ${ESVN_WC_REVISION}."
173 else 233 else
174 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy." 234 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
175 235
236 local esvn_up_freq=
237 if [[ -n ${ESVN_UP_FREQ} ]]; then
238 if [[ -n ${ESVN_UP_FREQ//[[:digit:]]} ]]; then
239 die "${ESVN}: ESVN_UP_FREQ must be an integer value corresponding to the minimum number of hours between svn up."
240 elif [[ -z $(find "${wc_path}/.svn/entries" -mmin "+$((ESVN_UP_FREQ*60))") ]]; then
241 einfo "Fetching disabled since ${ESVN_UP_FREQ} hours has not passed since last update."
242 einfo "Using existing repository copy at revision ${ESVN_WC_REVISION}."
243 esvn_up_freq=no_update
244 fi
245 fi
246
247 if [[ -z ${esvn_up_freq} ]]; then
176 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}" 1) ]]; then 248 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then
177 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
178 fi
179
180 # update working copy
181 einfo "subversion update start -->" 249 einfo "subversion switch start -->"
182 einfo " repository: ${repo_uri}" 250 einfo " old repository: ${ESVN_WC_URL}@${ESVN_WC_REVISION}"
251 einfo " new repository: ${repo_uri}${revision:+@}${revision}"
183 252
184 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}" 253 debug-print "${FUNCNAME}: ${ESVN_SWITCH_CMD} ${options} ${repo_uri}"
185 254
186 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}" 255 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
256 ${ESVN_SWITCH_CMD} ${options} ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}"
257 else
258 # update working copy
259 einfo "subversion update start -->"
260 einfo " repository: ${repo_uri}${revision:+@}${revision}"
261
262 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
263
264 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
187 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}." 265 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
188 266 fi
267 fi
189 fi 268 fi
190 269
191 einfo " working copy: ${wc_path}" 270 einfo " working copy: ${wc_path}"
192 271
193 if ! has "export" ${ESVN_RESTRICT}; then 272 if ! has "export" ${ESVN_RESTRICT}; then
263 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap." 342 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
264} 343}
265 344
266# @FUNCTION: subversion_wc_info 345# @FUNCTION: subversion_wc_info
267# @USAGE: [repo_uri] 346# @USAGE: [repo_uri]
268# @RETURN: ESVN_WC_URL, ESVN_WC_REVISION and ESVN_WC_PATH 347# @RETURN: ESVN_WC_URL, ESVN_WC_ROOT, ESVN_WC_UUID, ESVN_WC_REVISION and ESVN_WC_PATH
269# @DESCRIPTION: 348# @DESCRIPTION:
270# Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI. 349# Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI.
271# 350#
272# The working copy information on the specified repository URI are set to 351# The working copy information on the specified repository URI are set to
273# ESVN_WC_* variables. 352# ESVN_WC_* variables.
274subversion_wc_info() { 353subversion_wc_info() {
275 local repo_uri="$(subversion__get_repository_uri "${1}")" 354 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
276 local wc_path="$(subversion__get_wc_path "${repo_uri}")" 355 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
277 356
278 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 357 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
279 debug-print "${FUNCNAME}: wc_path = ${wc_path}" 358 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
280 359
281 if [[ ! -d ${wc_path} ]]; then 360 if [[ ! -d ${wc_path} ]]; then
282 return 1 361 return 1
283 fi 362 fi
284 363
285 local k 364 export ESVN_WC_URL="$(subversion__svn_info "${wc_path}" "URL")"
286 365 export ESVN_WC_ROOT="$(subversion__svn_info "${wc_path}" "Repository Root")"
287 for k in url revision; do 366 export ESVN_WC_UUID="$(subversion__svn_info "${wc_path}" "Repository UUID")"
288 export ESVN_WC_$(subversion__to_upper_case "${k}")="$(subversion__svn_info "${wc_path}" "${k}")" 367 export ESVN_WC_REVISION="$(subversion__svn_info "${wc_path}" "Revision")"
289 done
290
291 export ESVN_WC_PATH="${wc_path}" 368 export ESVN_WC_PATH="${wc_path}"
292} 369}
293 370
294## -- Private Functions 371## -- Private Functions
295 372
306} 383}
307 384
308## -- subversion__get_repository_uri() --------------------------------------- # 385## -- subversion__get_repository_uri() --------------------------------------- #
309# 386#
310# param $1 - a repository URI. 387# param $1 - a repository URI.
311# param $2 - a peg revision is deleted from a return value if this is
312# specified.
313subversion__get_repository_uri() { 388subversion__get_repository_uri() {
314 local repo_uri="${1:-${ESVN_REPO_URI}}" 389 local repo_uri="${1}"
315 local remove_peg_revision="${2}"
316 390
317 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 391 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
318 debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
319 392
320 if [[ -z ${repo_uri} ]]; then 393 if [[ -z ${repo_uri} ]]; then
321 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty." 394 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
322 fi 395 fi
323 396
324 # delete trailing slash 397 # delete trailing slash
325 if [[ -z ${repo_uri##*/} ]]; then 398 if [[ -z ${repo_uri##*/} ]]; then
326 repo_uri="${repo_uri%/}" 399 repo_uri="${repo_uri%/}"
327 fi 400 fi
328 401
329 if [[ -n ${remove_peg_revision} ]]; then
330 if subversion__has_peg_revision "${repo_uri}"; then
331 repo_uri="${repo_uri%@*}" 402 repo_uri="${repo_uri%@*}"
332
333 debug-print "${FUNCNAME}: repo_uri has a peg revision"
334 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
335 fi
336 fi
337 403
338 echo "${repo_uri}" 404 echo "${repo_uri}"
339} 405}
340 406
341## -- subversion__get_wc_path() ---------------------------------------------- # 407## -- subversion__get_wc_path() ---------------------------------------------- #
342# 408#
343# param $1 - a repository URI. 409# param $1 - a repository URI.
344subversion__get_wc_path() { 410subversion__get_wc_path() {
345 local repo_uri="$(subversion__get_repository_uri "${1}" 1)" 411 local repo_uri="$(subversion__get_repository_uri "${1}")"
346 412
347 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 413 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
348 414
349 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}" 415 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
350} 416}
351 417
352## -- subversion__has_peg_revision() ----------------------------------------- # 418## -- subversion__get_peg_revision() ----------------------------------------- #
353# 419#
354# param $1 - a repository URI. 420# param $1 - a repository URI.
355subversion__has_peg_revision() { 421subversion__get_peg_revision() {
356 local repo_uri="${1}" 422 local repo_uri="${1}"
357 423
358 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 424 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
359 425
360 # repo_uri has peg revision ? 426 # repo_uri has peg revision ?
361 if [[ ${repo_uri} != *@* ]]; then 427 if [[ ${repo_uri} != *@* ]]; then
362 debug-print "${FUNCNAME}: repo_uri does not have a peg revision." 428 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
363 return 1
364 fi 429 fi
365 430
366 local peg_rev="${repo_uri##*@}" 431 local peg_rev=
367 432 [[ ${repo_uri} = *@* ]] && peg_rev="${repo_uri##*@}"
368 case "$(subversion__to_upper_case "${peg_rev}")" in
369 [[:digit:]]*)
370 # NUMBER
371 ;;
372 HEAD|BASE|COMMITED|PREV)
373 ;;
374 {[^}]*})
375 # DATE
376 ;;
377 *)
378 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
379 return 1
380 ;;
381 esac
382 433
383 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}" 434 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
384 435
385 return 0 436 echo "${peg_rev}"
386} 437}
387 438
388## -- subversion__to_upper_case() ----------------------------------------- # 439# @FUNCTION: subversion_pkg_preinst
389# 440# @USAGE: [repo_uri]
390# param $@ - the strings to upper case. 441# @DESCRIPTION:
391subversion__to_upper_case() { 442# Log the svn revision of source code. Doing this in pkg_preinst because we
392 echo "${@}" | tr "[:lower:]" "[:upper:]" 443# want the logs to stick around if packages are uninstalled without messing with
444# config protection.
445subversion_pkg_preinst() {
446 local pkgdate=$(date "+%Y%m%d %H:%M:%S")
447 subversion_wc_info "${1:-${ESVN_REPO_URI}}"
448 if [[ -n ${ESCM_LOGDIR} ]]; then
449 local dir="${ROOT}/${ESCM_LOGDIR}/${CATEGORY}"
450 if [[ ! -d ${dir} ]]; then
451 mkdir -p "${dir}" || \
452 eerror "Failed to create '${dir}' for logging svn revision to '${PORTDIR_SCM}'"
453 fi
454 local logmessage="svn: ${pkgdate} - ${PF}:${SLOT} was merged at revision ${ESVN_WC_REVISION}"
455 if [[ -d ${dir} ]]; then
456 echo "${logmessage}" >> "${dir}/${PN}.log"
457 else
458 eerror "Could not log the message '${logmessage}' to '${dir}/${PN}.log'"
459 fi
460 fi
393} 461}

Legend:
Removed from v.1.46  
changed lines
  Added in v.1.59

  ViewVC Help
Powered by ViewVC 1.1.20