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

Diff of /eclass/subversion.eclass

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

Revision 1.47 Revision 1.65
1# Copyright 1999-2008 Gentoo Foundation 1# Copyright 1999-2009 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.47 2008/02/20 17:55:27 cardoe Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.65 2009/04/29 22:26:31 scarabeus 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>
9# Arfrever Frehtes Taifersar Arahesis <arfrever@gentoo.org>
9# 10#
10# Original Author: Akinori Hattori <hattya@gentoo.org> 11# Original Author: Akinori Hattori <hattya@gentoo.org>
11# 12#
12# @BLURB: The subversion eclass is written to fetch software sources from subversion repositories 13# @BLURB: The subversion eclass is written to fetch software sources from subversion repositories
13# @DESCRIPTION: 14# @DESCRIPTION:
14# The subversion eclass provides functions to fetch, patch and bootstrap 15# The subversion eclass provides functions to fetch, patch and bootstrap
15# software sources from subversion repositories. 16# software sources from subversion repositories.
16#
17# You must define the ESVN_REPO_URI variable before inheriting this eclass.
18 17
19inherit eutils 18inherit eutils
20 19
21ESVN="${ECLASS}" 20ESVN="${ECLASS}"
22 21
23EXPORT_FUNCTIONS src_unpack 22EXPORTED_FUNCTIONS="src_unpack pkg_preinst"
23case "${EAPI:-0}" in
24 2) EXPORTED_FUNCTIONS="${EXPORTED_FUNCTIONS} src_prepare" ;;
25 1|0) ;;
26 *) die "Unknown EAPI, Bug eclass maintainers." ;;
27esac
28EXPORT_FUNCTIONS ${EXPORTED_FUNCTIONS}
24 29
25DESCRIPTION="Based on the ${ECLASS} eclass" 30DESCRIPTION="Based on the ${ECLASS} eclass"
26 31
27DEPEND="dev-util/subversion 32DEPEND="dev-util/subversion
28 net-misc/rsync" 33 net-misc/rsync"
39 44
40# @ECLASS-VARIABLE: ESVN_UPDATE_CMD 45# @ECLASS-VARIABLE: ESVN_UPDATE_CMD
41# @DESCRIPTION: 46# @DESCRIPTION:
42# subversion update command 47# subversion update command
43ESVN_UPDATE_CMD="svn update" 48ESVN_UPDATE_CMD="svn update"
49
50# @ECLASS-VARIABLE: ESVN_SWITCH_CMD
51# @DESCRIPTION:
52# subversion switch command
53ESVN_SWITCH_CMD="svn switch"
44 54
45# @ECLASS-VARIABLE: ESVN_OPTIONS 55# @ECLASS-VARIABLE: ESVN_OPTIONS
46# @DESCRIPTION: 56# @DESCRIPTION:
47# the options passed to checkout or update. If you want a specific revision see 57# the options passed to checkout or update. If you want a specific revision see
48# ESVN_REPO_URI instead of using -rREV. 58# ESVN_REPO_URI instead of using -rREV.
71# to a specific revision 81# to a specific revision
72# 82#
73# Note: This should never be set in an ebuild! 83# Note: This should never be set in an ebuild!
74ESVN_REVISION="${ESVN_REVISION:-}" 84ESVN_REVISION="${ESVN_REVISION:-}"
75 85
86# @ECLASS-VARIABLE: ESVN_USER
87# @DESCRIPTION:
88# User name
89ESVN_USER="${ESVN_USER:-}"
90
91# @ECLASS-VARIABLE: ESVN_PASSWORD
92# @DESCRIPTION:
93# Password
94ESVN_PASSWORD="${ESVN_PASSWORD:-}"
95
76# @ECLASS-VARIABLE: ESVN_PROJECT 96# @ECLASS-VARIABLE: ESVN_PROJECT
77# @DESCRIPTION: 97# @DESCRIPTION:
78# project name of your ebuild (= name space) 98# project name of your ebuild (= name space)
79# 99#
80# subversion eclass will check out the subversion repository like: 100# subversion eclass will check out the subversion repository like:
116# this should be a space delimited list of subversion eclass features to 136# this should be a space delimited list of subversion eclass features to
117# restrict. 137# restrict.
118# export) 138# export)
119# don't export the working copy to S. 139# don't export the working copy to S.
120ESVN_RESTRICT="${ESVN_RESTRICT:-}" 140ESVN_RESTRICT="${ESVN_RESTRICT:-}"
141
142# @ECLASS-VARIABLE: ESVN_OFFLINE
143# @DESCRIPTION:
144# Set this variable to a non-empty value to disable the automatic updating of
145# an svn source tree. This is intended to be set outside the subversion source
146# tree by users.
147ESVN_OFFLINE="${ESVN_OFFLINE:-${ESCM_OFFLINE}}"
148
149# @ECLASS-VARIABLE: ESVN_UP_FREQ
150# @DESCRIPTION:
151# Set the minimum number of hours between svn up'ing in any given svn module. This is particularly
152# useful for split KDE ebuilds where we want to ensure that all submodules are compiled for the same
153# revision. It should also be kept user overrideable.
154ESVN_UP_FREQ="${ESVN_UP_FREQ:=}"
155
156# @ECLASS-VARIABLE: ESCM_LOGDIR
157# @DESCRIPTION:
158# User configuration variable. If set to a path such as e.g. /var/log/scm any
159# package inheriting from subversion.eclass will record svn revision to
160# ${CATEGORY}/${PN}.log in that path in pkg_preinst. This is not supposed to be
161# set by ebuilds/eclasses. It defaults to empty so users need to opt in.
162ESCM_LOGDIR="${ESCM_LOGDIR:=}"
121 163
122# @FUNCTION: subversion_fetch 164# @FUNCTION: subversion_fetch
123# @USAGE: [repo_uri] [destination] 165# @USAGE: [repo_uri] [destination]
124# @DESCRIPTION: 166# @DESCRIPTION:
125# Wrapper function to fetch sources from subversion via svn checkout or svn update, 167# Wrapper function to fetch sources from subversion via svn checkout or svn update,
131subversion_fetch() { 173subversion_fetch() {
132 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")" 174 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
133 local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")" 175 local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")"
134 local S_dest="${2}" 176 local S_dest="${2}"
135 177
178 if [[ -z ${repo_uri} ]]; then
179 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
180 fi
181
136 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}" 182 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}"
137 183
138 # check for the protocol 184 # check for the protocol
139 local protocol="${repo_uri%%:*}" 185 local protocol="${repo_uri%%:*}"
140 186
141 case "${protocol}" in 187 case "${protocol}" in
142 http|https) 188 http|https)
189 if ! built_with_use --missing true -o dev-util/subversion webdav-neon webdav-serf || \
143 if built_with_use dev-util/subversion nowebdav; then 190 built_with_use --missing false dev-util/subversion nowebdav; then
144 echo 191 echo
145 eerror "In order to emerge this package, you need to" 192 eerror "In order to emerge this package, you need to"
146 eerror "re-emerge subversion with USE=-nowebdav" 193 eerror "reinstall Subversion with support for WebDAV."
194 eerror "Subversion requires either Neon or Serf to support WebDAV."
147 echo 195 echo
148 die "${ESVN}: please run 'USE=-nowebdav emerge subversion'" 196 die "${ESVN}: reinstall Subversion with support for WebDAV."
149 fi 197 fi
150 ;; 198 ;;
151 svn|svn+ssh) 199 svn|svn+ssh)
152 ;; 200 ;;
153 *) 201 *)
173 if [[ "${ESVN_OPTIONS}" = *-r* ]]; then 221 if [[ "${ESVN_OPTIONS}" = *-r* ]]; then
174 ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please" 222 ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please"
175 ewarn "see \${ESVN_REPO_URI}" 223 ewarn "see \${ESVN_REPO_URI}"
176 fi 224 fi
177 225
226 if has_version ">=dev-util/subversion-1.6.0"; then
227 options="${options} --config-option=config:auth:password-stores="
228 fi
229
178 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\"" 230 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
179 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\"" 231 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
180 debug-print "${FUNCNAME}: options = \"${options}\"" 232 debug-print "${FUNCNAME}: options = \"${options}\""
181 233
182 if [[ ! -d ${wc_path}/.svn ]]; then 234 if [[ ! -d ${wc_path}/.svn ]]; then
235 if [[ -n ${ESVN_OFFLINE} ]]; then
236 ewarn "ESVN_OFFLINE cannot be used when there is no existing checkout."
237 fi
183 # first check out 238 # first check out
184 einfo "subversion check out start -->" 239 einfo "subversion check out start -->"
185 einfo " repository: ${repo_uri}${revision:+@}${revision}" 240 einfo " repository: ${repo_uri}${revision:+@}${revision}"
186 241
187 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}" 242 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
188 243
189 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}." 244 mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
190 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}" 245 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
246 if [[ -n "${ESVN_USER}" ]]; then
247 ${ESVN_FETCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
248 else
191 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}." 249 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
250 fi
192 251
252 elif [[ -n ${ESVN_OFFLINE} ]]; then
253 svn cleanup "${wc_path}"
254 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
255 if [[ -n ${ESVN_REVISION} && ${ESVN_REVISION} != ${ESVN_WC_REVISION} ]]; then
256 die "${ESVN}: You requested off-line updating and revision ${ESVN_REVISION} but only revision ${ESVN_WC_REVISION} is available locally."
257 fi
258 einfo "Fetching disabled: Using existing repository copy at revision ${ESVN_WC_REVISION}."
193 else 259 else
260 svn cleanup "${wc_path}"
194 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy." 261 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
195 262
263 local esvn_up_freq=
264 if [[ -n ${ESVN_UP_FREQ} ]]; then
265 if [[ -n ${ESVN_UP_FREQ//[[:digit:]]} ]]; then
266 die "${ESVN}: ESVN_UP_FREQ must be an integer value corresponding to the minimum number of hours between svn up."
267 elif [[ -z $(find "${wc_path}/.svn/entries" -mmin "+$((ESVN_UP_FREQ*60))") ]]; then
268 einfo "Fetching disabled since ${ESVN_UP_FREQ} hours has not passed since last update."
269 einfo "Using existing repository copy at revision ${ESVN_WC_REVISION}."
270 esvn_up_freq=no_update
271 fi
272 fi
273
274 if [[ -z ${esvn_up_freq} ]]; then
196 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then 275 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then
197 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched." 276 einfo "subversion switch start -->"
277 einfo " old repository: ${ESVN_WC_URL}@${ESVN_WC_REVISION}"
278 einfo " new repository: ${repo_uri}${revision:+@}${revision}"
279
280 debug-print "${FUNCNAME}: ${ESVN_SWITCH_CMD} ${options} ${repo_uri}"
281
282 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
283 if [[ -n "${ESVN_USER}" ]]; then
284 ${ESVN_SWITCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
285 else
286 ${ESVN_SWITCH_CMD} ${options} ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
198 fi 287 fi
199 288 else
200 # update working copy 289 # update working copy
201 einfo "subversion update start -->" 290 einfo "subversion update start -->"
202 einfo " repository: ${repo_uri}${revision:+@}${revision}" 291 einfo " repository: ${repo_uri}${revision:+@}${revision}"
203 292
204 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}" 293 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
205 294
206 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}" 295 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
296 if [[ -n "${ESVN_USER}" ]]; then
297 ${ESVN_UPDATE_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
298 else
207 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}." 299 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
208 300 fi
301 fi
302 fi
209 fi 303 fi
210 304
211 einfo " working copy: ${wc_path}" 305 einfo " working copy: ${wc_path}"
212 306
213 if ! has "export" ${ESVN_RESTRICT}; then 307 if ! has "export" ${ESVN_RESTRICT}; then
214 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}" 308 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
215 309
216 local S="${S}/${S_dest}" 310 local S="${S}/${S_dest}"
311 mkdir -p "${S}"
217 312
218 # export to the ${WORKDIR} 313 # export to the ${WORKDIR}
219 #* "svn export" has a bug. see http://bugs.gentoo.org/119236 314 #* "svn export" has a bug. see http://bugs.gentoo.org/119236
220 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}." 315 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
221 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}." 316 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
275 fi 370 fi
276} 371}
277 372
278# @FUNCTION: subversion_src_unpack 373# @FUNCTION: subversion_src_unpack
279# @DESCRIPTION: 374# @DESCRIPTION:
280# default src_unpack. fetch and bootstrap. 375# Default src_unpack. Fetch and, in older EAPIs, bootstrap.
281subversion_src_unpack() { 376subversion_src_unpack() {
282 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch." 377 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
378 has src_prepare ${EXPORTED_FUNCTIONS} || git_src_prepare
379}
380
381# @FUNCTION: subversion_src_prepare
382# @DESCRIPTION:
383# Default src_prepare. Bootstrap.
384subversion_src_prepare() {
283 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap." 385 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
284} 386}
285 387
286# @FUNCTION: subversion_wc_info 388# @FUNCTION: subversion_wc_info
287# @USAGE: [repo_uri] 389# @USAGE: [repo_uri]
290# Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI. 392# Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI.
291# 393#
292# The working copy information on the specified repository URI are set to 394# The working copy information on the specified repository URI are set to
293# ESVN_WC_* variables. 395# ESVN_WC_* variables.
294subversion_wc_info() { 396subversion_wc_info() {
295 local repo_uri="$(subversion__get_repository_uri "${1}")" 397 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
296 local wc_path="$(subversion__get_wc_path "${repo_uri}")" 398 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
297 399
298 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 400 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
299 debug-print "${FUNCNAME}: wc_path = ${wc_path}" 401 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
300 402
325 427
326## -- subversion__get_repository_uri() --------------------------------------- # 428## -- subversion__get_repository_uri() --------------------------------------- #
327# 429#
328# param $1 - a repository URI. 430# param $1 - a repository URI.
329subversion__get_repository_uri() { 431subversion__get_repository_uri() {
330 local repo_uri="${1}" 432 local repo_uri="${1}"
331 433
332 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}" 434 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
333 435
334 if [[ -z ${repo_uri} ]]; then 436 if [[ -z ${repo_uri} ]]; then
335 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty." 437 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
366 468
367 # repo_uri has peg revision ? 469 # repo_uri has peg revision ?
368 if [[ ${repo_uri} != *@* ]]; then 470 if [[ ${repo_uri} != *@* ]]; then
369 debug-print "${FUNCNAME}: repo_uri does not have a peg revision." 471 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
370 fi 472 fi
371 473
372 local peg_rev= 474 local peg_rev=
373 [[ ${repo_uri} = *@* ]] && peg_rev="${repo_uri##*@}" 475 [[ ${repo_uri} = *@* ]] && peg_rev="${repo_uri##*@}"
374 476
375 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}" 477 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
376 478
377 echo "${peg_rev}" 479 echo "${peg_rev}"
378} 480}
481
482# @FUNCTION: subversion_pkg_preinst
483# @USAGE: [repo_uri]
484# @DESCRIPTION:
485# Log the svn revision of source code. Doing this in pkg_preinst because we
486# want the logs to stick around if packages are uninstalled without messing with
487# config protection.
488subversion_pkg_preinst() {
489 local pkgdate=$(date "+%Y%m%d %H:%M:%S")
490 subversion_wc_info "${1:-${ESVN_REPO_URI}}"
491 if [[ -n ${ESCM_LOGDIR} ]]; then
492 local dir="${ROOT}/${ESCM_LOGDIR}/${CATEGORY}"
493 if [[ ! -d ${dir} ]]; then
494 mkdir -p "${dir}" || \
495 eerror "Failed to create '${dir}' for logging svn revision to '${PORTDIR_SCM}'"
496 fi
497 local logmessage="svn: ${pkgdate} - ${PF}:${SLOT} was merged at revision ${ESVN_WC_REVISION}"
498 if [[ -d ${dir} ]]; then
499 echo "${logmessage}" >> "${dir}/${PN}.log"
500 else
501 eerror "Could not log the message '${logmessage}' to '${dir}/${PN}.log'"
502 fi
503 fi
504}

Legend:
Removed from v.1.47  
changed lines
  Added in v.1.65

  ViewVC Help
Powered by ViewVC 1.1.20