1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
5 # @ECLASS: subversion.eclass
7 # Akinori Hattori <hattya@gentoo.org>
9 # Original Author: Akinori Hattori <hattya@gentoo.org>
10 # @BLURB: The subversion eclass is written to fetch software sources from subversion repositories
12 # The subversion eclass provides functions to fetch, patch and bootstrap
13 # software sources from subversion repositories.
21 EXPORT_FUNCTIONS src_unpack pkg_preinst
22 DEPEND="dev-vcs/subversion"
25 EXPORT_FUNCTIONS src_unpack src_prepare pkg_preinst
26 DEPEND="|| ( dev-vcs/subversion[http] dev-vcs/subversion[webdav-neon] dev-vcs/subversion[webdav-serf] )"
29 EXPORT_FUNCTIONS src_unpack pkg_preinst
30 DEPEND="|| ( dev-vcs/subversion[http] dev-vcs/subversion[webdav-neon] dev-vcs/subversion[webdav-serf] )"
33 die "EAPI ${EAPI} is not supported in subversion.eclass"
37 DEPEND+=" net-misc/rsync"
39 # @ECLASS-VARIABLE: ESVN_STORE_DIR
41 # subversion sources store directory. Users may override this in /etc/portage/make.conf
42 [[ -z ${ESVN_STORE_DIR} ]] && ESVN_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/svn-src"
44 # @ECLASS-VARIABLE: ESVN_FETCH_CMD
46 # subversion checkout command
47 ESVN_FETCH_CMD="svn checkout"
49 # @ECLASS-VARIABLE: ESVN_UPDATE_CMD
51 # subversion update command
52 ESVN_UPDATE_CMD="svn update"
54 # @ECLASS-VARIABLE: ESVN_SWITCH_CMD
56 # subversion switch command
57 ESVN_SWITCH_CMD="svn switch"
59 # @ECLASS-VARIABLE: ESVN_OPTIONS
61 # the options passed to checkout or update. If you want a specific revision see
62 # ESVN_REPO_URI instead of using -rREV.
63 ESVN_OPTIONS="${ESVN_OPTIONS:-}"
65 # @ECLASS-VARIABLE: ESVN_REPO_URI
69 # e.g. http://foo/trunk, svn://bar/trunk, svn://bar/branch/foo@1234
71 # supported URI schemes:
78 # to peg to a specific revision, append @REV to the repo's uri
79 ESVN_REPO_URI="${ESVN_REPO_URI:-}"
81 # @ECLASS-VARIABLE: ESVN_REVISION
83 # User configurable revision checkout or update to from the repository
85 # Useful for live svn or trunk svn ebuilds allowing the user to peg
86 # to a specific revision
88 # Note: This should never be set in an ebuild!
89 ESVN_REVISION="${ESVN_REVISION:-}"
91 # @ECLASS-VARIABLE: ESVN_USER
94 ESVN_USER="${ESVN_USER:-}"
96 # @ECLASS-VARIABLE: ESVN_PASSWORD
99 ESVN_PASSWORD="${ESVN_PASSWORD:-}"
101 # @ECLASS-VARIABLE: ESVN_PROJECT
103 # project name of your ebuild (= name space)
105 # subversion eclass will check out the subversion repository like:
107 # ${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}
109 # so if you define ESVN_REPO_URI as http://svn.collab.net/repo/svn/trunk or
110 # http://svn.collab.net/repo/svn/trunk/. and PN is subversion-svn.
111 # it will check out like:
113 # ${ESVN_STORE_DIR}/subversion/trunk
115 # this is not used in order to declare the name of the upstream project.
116 # so that you can declare this like:
118 # # jakarta commons-loggin
119 # ESVN_PROJECT=commons/logging
121 # default: ${PN/-svn}.
122 ESVN_PROJECT="${ESVN_PROJECT:-${PN/-svn}}"
124 # @ECLASS-VARIABLE: ESVN_BOOTSTRAP
126 # Bootstrap script or command like autogen.sh or etc..
127 # Removed in EAPI 6 and later.
128 ESVN_BOOTSTRAP="${ESVN_BOOTSTRAP:-}"
130 # @ECLASS-VARIABLE: ESVN_PATCHES
132 # subversion eclass can apply patches in subversion_bootstrap().
133 # you can use regexp in this variable like *.diff or *.patch or etc.
134 # NOTE: patches will be applied before ESVN_BOOTSTRAP is processed.
136 # Patches are searched both in ${PWD} and ${FILESDIR}, if not found in either
137 # location, the installation dies.
139 # Removed in EAPI 6 and later, use PATCHES instead.
140 ESVN_PATCHES="${ESVN_PATCHES:-}"
142 # @ECLASS-VARIABLE: ESVN_RESTRICT
144 # this should be a space delimited list of subversion eclass features to
147 # don't export the working copy to S.
148 ESVN_RESTRICT="${ESVN_RESTRICT:-}"
150 # @ECLASS-VARIABLE: ESVN_OFFLINE
152 # Set this variable to a non-empty value to disable the automatic updating of
153 # an svn source tree. This is intended to be set outside the subversion source
155 ESVN_OFFLINE="${ESVN_OFFLINE:-${EVCS_OFFLINE}}"
157 # @ECLASS-VARIABLE: ESVN_UMASK
159 # Set this variable to a custom umask. This is intended to be set by users.
160 # By setting this to something like 002, it can make life easier for people
161 # who do development as non-root (but are in the portage group), and then
162 # switch over to building with FEATURES=userpriv. Or vice-versa. Shouldn't
163 # be a security issue here as anyone who has portage group write access
164 # already can screw the system over in more creative ways.
165 ESVN_UMASK="${ESVN_UMASK:-${EVCS_UMASK}}"
167 # @ECLASS-VARIABLE: ESVN_UP_FREQ
169 # Set the minimum number of hours between svn up'ing in any given svn module. This is particularly
170 # useful for split KDE ebuilds where we want to ensure that all submodules are compiled for the same
171 # revision. It should also be kept user overrideable.
172 ESVN_UP_FREQ="${ESVN_UP_FREQ:=}"
174 # @ECLASS-VARIABLE: ESCM_LOGDIR
176 # User configuration variable. If set to a path such as e.g. /var/log/scm any
177 # package inheriting from subversion.eclass will record svn revision to
178 # ${CATEGORY}/${PN}.log in that path in pkg_preinst. This is not supposed to be
179 # set by ebuilds/eclasses. It defaults to empty so users need to opt in.
180 ESCM_LOGDIR="${ESCM_LOGDIR:=}"
182 # @FUNCTION: subversion_fetch
183 # @USAGE: [repo_uri] [destination]
185 # Wrapper function to fetch sources from subversion via svn checkout or svn update,
186 # depending on whether there is an existing working copy in ${ESVN_STORE_DIR}.
188 # Can take two optional parameters:
189 # repo_uri - a repository URI. default is ESVN_REPO_URI.
190 # destination - a check out path in S.
192 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
193 local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")"
196 if [[ -z ${repo_uri} ]]; then
197 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
200 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}"
202 # check for the scheme
203 local scheme="${repo_uri%%:*}"
212 die "${ESVN}: fetch from '${scheme}' is not yet implemented."
216 addread "/etc/subversion"
217 addwrite "${ESVN_STORE_DIR}"
219 if [[ -n "${ESVN_UMASK}" ]]; then
220 eumask_push "${ESVN_UMASK}"
223 if [[ ! -d ${ESVN_STORE_DIR} ]]; then
224 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
225 mkdir -m 775 -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
228 pushd "${ESVN_STORE_DIR}" >/dev/null || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
230 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
231 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
233 [[ -n "${revision}" ]] && options="${options} -r ${revision}"
235 if [[ "${ESVN_OPTIONS}" = *-r* ]]; then
236 ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please"
237 ewarn "see \${ESVN_REPO_URI}"
240 if has_version ">=dev-vcs/subversion-1.6.0"; then
241 options="${options} --config-option=config:auth:password-stores="
244 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
245 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
246 debug-print "${FUNCNAME}: options = \"${options}\""
248 if [[ ! -d ${wc_path}/.svn ]]; then
249 if [[ -n ${ESVN_OFFLINE} ]]; then
250 ewarn "ESVN_OFFLINE cannot be used when there is no existing checkout."
253 einfo "subversion check out start -->"
254 einfo " repository: ${repo_uri}${revision:+@}${revision}"
256 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
258 mkdir -m 775 -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
259 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
260 if [[ -n "${ESVN_USER}" ]]; then
261 ${ESVN_FETCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
263 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
266 elif [[ -n ${ESVN_OFFLINE} ]]; then
267 svn upgrade "${wc_path}" &>/dev/null
268 svn cleanup "${wc_path}" &>/dev/null
269 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
271 if [[ -n ${ESVN_REVISION} && ${ESVN_REVISION} != ${ESVN_WC_REVISION} ]]; then
272 die "${ESVN}: You requested off-line updating and revision ${ESVN_REVISION} but only revision ${ESVN_WC_REVISION} is available locally."
274 einfo "Fetching disabled: Using existing repository copy at revision ${ESVN_WC_REVISION}."
276 svn upgrade "${wc_path}" &>/dev/null
277 svn cleanup "${wc_path}" &>/dev/null
278 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
281 if [[ -n ${ESVN_UP_FREQ} ]]; then
282 if [[ -n ${ESVN_UP_FREQ//[[:digit:]]} ]]; then
283 die "${ESVN}: ESVN_UP_FREQ must be an integer value corresponding to the minimum number of hours between svn up."
284 elif [[ -z $(find "${wc_path}/.svn/entries" -mmin "+$((ESVN_UP_FREQ*60))") ]]; then
285 einfo "Fetching disabled since ${ESVN_UP_FREQ} hours has not passed since last update."
286 einfo "Using existing repository copy at revision ${ESVN_WC_REVISION}."
287 esvn_up_freq=no_update
291 if [[ -z ${esvn_up_freq} ]]; then
292 if [[ ${ESVN_WC_UUID} != $(subversion__svn_info "${repo_uri}" "Repository UUID") ]]; then
293 # UUID mismatch. Delete working copy and check out it again.
294 einfo "subversion recheck out start -->"
295 einfo " old UUID: ${ESVN_WC_UUID}"
296 einfo " new UUID: $(subversion__svn_info "${repo_uri}" "Repository UUID")"
297 einfo " repository: ${repo_uri}${revision:+@}${revision}"
299 rm -fr "${ESVN_PROJECT}" || die
301 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
303 mkdir -m 775 -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
304 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
305 if [[ -n "${ESVN_USER}" ]]; then
306 ${ESVN_FETCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
308 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
310 elif [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then
311 einfo "subversion switch start -->"
312 einfo " old repository: ${ESVN_WC_URL}@${ESVN_WC_REVISION}"
313 einfo " new repository: ${repo_uri}${revision:+@}${revision}"
315 debug-print "${FUNCNAME}: ${ESVN_SWITCH_CMD} ${options} ${repo_uri}"
317 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
318 if [[ -n "${ESVN_USER}" ]]; then
319 ${ESVN_SWITCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
321 ${ESVN_SWITCH_CMD} ${options} ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
324 # update working copy
325 einfo "subversion update start -->"
326 einfo " repository: ${repo_uri}${revision:+@}${revision}"
328 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
330 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
331 if [[ -n "${ESVN_USER}" ]]; then
332 ${ESVN_UPDATE_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
334 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
338 # export updated information for the working copy
339 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
343 if [[ -n "${ESVN_UMASK}" ]]; then
347 einfo " working copy: ${wc_path}"
349 if ! has "export" ${ESVN_RESTRICT}; then
350 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
352 local S="${S}/${S_dest}"
355 # export to the ${WORKDIR}
356 #* "svn export" has a bug. see https://bugs.gentoo.org/119236
357 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
358 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
365 # @FUNCTION: subversion_bootstrap
367 # Apply patches in ${ESVN_PATCHES} and run ${ESVN_BOOTSTRAP} if specified.
368 # Removed in EAPI 6 and later.
369 subversion_bootstrap() {
370 [[ ${EAPI} == [012345] ]] || die "${FUNCNAME[1]} is removed from subversion.eclass in EAPI 6 and later"
372 if has "export" ${ESVN_RESTRICT}; then
378 if [[ -n ${ESVN_PATCHES} ]]; then
380 einfo "apply patches -->"
381 for patch in ${ESVN_PATCHES}; do
382 if [[ -f ${patch} ]]; then
385 for fpatch in ${FILESDIR}/${patch}; do
386 if [[ -f ${fpatch} ]]; then
389 die "${ESVN}: ${patch} not found"
397 if [[ -n ${ESVN_BOOTSTRAP} ]]; then
398 einfo "begin bootstrap -->"
399 if [[ -f ${ESVN_BOOTSTRAP} && -x ${ESVN_BOOTSTRAP} ]]; then
400 einfo " bootstrap with a file: ${ESVN_BOOTSTRAP}"
401 eval "./${ESVN_BOOTSTRAP}" || die "${ESVN}: can't execute ESVN_BOOTSTRAP."
403 einfo " bootstrap with command: ${ESVN_BOOTSTRAP}"
404 eval "${ESVN_BOOTSTRAP}" || die "${ESVN}: can't eval ESVN_BOOTSTRAP."
409 # @FUNCTION: subversion_wc_info
411 # @RETURN: ESVN_WC_URL, ESVN_WC_ROOT, ESVN_WC_UUID, ESVN_WC_REVISION and ESVN_WC_PATH
413 # Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI.
415 # The working copy information on the specified repository URI are set to
416 # ESVN_WC_* variables.
417 subversion_wc_info() {
418 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
419 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
421 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
422 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
424 if [[ ! -d ${wc_path} ]]; then
428 export ESVN_WC_URL="$(subversion__svn_info "${wc_path}" "URL")"
429 export ESVN_WC_ROOT="$(subversion__svn_info "${wc_path}" "Repository Root")"
430 export ESVN_WC_UUID="$(subversion__svn_info "${wc_path}" "Repository UUID")"
431 export ESVN_WC_REVISION="$(subversion__svn_info "${wc_path}" "Revision")"
432 export ESVN_WC_PATH="${wc_path}"
435 # @FUNCTION: subversion_src_unpack
437 # Default src_unpack. Fetch and, in older EAPIs, bootstrap.
438 subversion_src_unpack() {
439 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
440 if has "${EAPI:-0}" 0 1; then
441 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
445 # @FUNCTION: subversion_src_prepare
447 # Default src_prepare. Bootstrap.
448 # Removed in EAPI 6 and later.
449 subversion_src_prepare() {
450 [[ ${EAPI} == [012345] ]] || die "${FUNCNAME[1]} is removed from subversion.eclass in EAPI 6 and later"
451 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
454 # @FUNCTION: subversion_pkg_preinst
457 # Log the svn revision of source code. Doing this in pkg_preinst because we
458 # want the logs to stick around if packages are uninstalled without messing with
460 subversion_pkg_preinst() {
461 has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
462 local pkgdate=$(date "+%Y%m%d %H:%M:%S")
463 if [[ -n ${ESCM_LOGDIR} ]]; then
464 local dir="${EROOT}/${ESCM_LOGDIR}/${CATEGORY}"
465 if [[ ! -d ${dir} ]]; then
466 mkdir -p "${dir}" || eerror "Failed to create '${dir}' for logging svn revision"
468 local logmessage="svn: ${pkgdate} - ${PF}:${SLOT} was merged at revision ${ESVN_WC_REVISION}"
469 if [[ -d ${dir} ]]; then
470 echo "${logmessage}" >>"${dir}/${PN}.log"
472 eerror "Could not log the message '${logmessage}' to '${dir}/${PN}.log'"
477 ## -- Private Functions
479 ## -- subversion__svn_info() ------------------------------------------------- #
481 # param $1 - a target.
482 # param $2 - a key name.
484 subversion__svn_info() {
488 env LC_ALL=C svn info ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${target}" \
489 | grep -i "^${key}" \
493 ## -- subversion__get_repository_uri() --------------------------------------- #
495 # param $1 - a repository URI.
496 subversion__get_repository_uri() {
497 local repo_uri="${1}"
499 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
500 if [[ -z ${repo_uri} ]]; then
501 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
503 # delete trailing slash
504 if [[ -z ${repo_uri##*/} ]]; then
505 repo_uri="${repo_uri%/}"
507 repo_uri="${repo_uri%@*}"
512 ## -- subversion__get_wc_path() ---------------------------------------------- #
514 # param $1 - a repository URI.
515 subversion__get_wc_path() {
516 local repo_uri="$(subversion__get_repository_uri "${1}")"
518 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
520 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
523 ## -- subversion__get_peg_revision() ----------------------------------------- #
525 # param $1 - a repository URI.
526 subversion__get_peg_revision() {
527 local repo_uri="${1}"
530 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
531 # repo_uri has peg revision?
532 if [[ ${repo_uri} = *@* ]]; then
533 peg_rev="${repo_uri##*@}"
534 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
536 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."