1 # Copyright 1999-2017 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: subversion.eclass
6 # Akinori Hattori <hattya@gentoo.org>
8 # Original Author: Akinori Hattori <hattya@gentoo.org>
9 # @BLURB: The subversion eclass is written to fetch software sources from subversion repositories
11 # The subversion eclass provides functions to fetch, patch and bootstrap
12 # software sources from subversion repositories.
20 EXPORT_FUNCTIONS src_unpack pkg_preinst
21 DEPEND="dev-vcs/subversion"
24 EXPORT_FUNCTIONS src_unpack src_prepare pkg_preinst
25 DEPEND="|| ( dev-vcs/subversion[http] dev-vcs/subversion[webdav-neon] dev-vcs/subversion[webdav-serf] )"
28 EXPORT_FUNCTIONS src_unpack pkg_preinst
29 DEPEND="|| ( dev-vcs/subversion[http] dev-vcs/subversion[webdav-neon] dev-vcs/subversion[webdav-serf] )"
32 die "EAPI ${EAPI} is not supported in subversion.eclass"
36 DEPEND+=" net-misc/rsync"
38 # @ECLASS-VARIABLE: ESVN_STORE_DIR
40 # subversion sources store directory. Users may override this in /etc/portage/make.conf
41 [[ -z ${ESVN_STORE_DIR} ]] && ESVN_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/svn-src"
43 # @ECLASS-VARIABLE: ESVN_FETCH_CMD
45 # subversion checkout command
46 ESVN_FETCH_CMD="svn checkout"
48 # @ECLASS-VARIABLE: ESVN_UPDATE_CMD
50 # subversion update command
51 ESVN_UPDATE_CMD="svn update"
53 # @ECLASS-VARIABLE: ESVN_SWITCH_CMD
55 # subversion switch command
56 ESVN_SWITCH_CMD="svn switch"
58 # @ECLASS-VARIABLE: ESVN_OPTIONS
60 # the options passed to checkout or update. If you want a specific revision see
61 # ESVN_REPO_URI instead of using -rREV.
62 ESVN_OPTIONS="${ESVN_OPTIONS:-}"
64 # @ECLASS-VARIABLE: ESVN_REPO_URI
68 # e.g. http://foo/trunk, svn://bar/trunk, svn://bar/branch/foo@1234
70 # supported URI schemes:
77 # to peg to a specific revision, append @REV to the repo's uri
78 ESVN_REPO_URI="${ESVN_REPO_URI:-}"
80 # @ECLASS-VARIABLE: ESVN_REVISION
82 # User configurable revision checkout or update to from the repository
84 # Useful for live svn or trunk svn ebuilds allowing the user to peg
85 # to a specific revision
87 # Note: This should never be set in an ebuild!
88 ESVN_REVISION="${ESVN_REVISION:-}"
90 # @ECLASS-VARIABLE: ESVN_USER
93 ESVN_USER="${ESVN_USER:-}"
95 # @ECLASS-VARIABLE: ESVN_PASSWORD
98 ESVN_PASSWORD="${ESVN_PASSWORD:-}"
100 # @ECLASS-VARIABLE: ESVN_PROJECT
102 # project name of your ebuild (= name space)
104 # subversion eclass will check out the subversion repository like:
106 # ${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}
108 # so if you define ESVN_REPO_URI as http://svn.collab.net/repo/svn/trunk or
109 # http://svn.collab.net/repo/svn/trunk/. and PN is subversion-svn.
110 # it will check out like:
112 # ${ESVN_STORE_DIR}/subversion/trunk
114 # this is not used in order to declare the name of the upstream project.
115 # so that you can declare this like:
117 # # jakarta commons-loggin
118 # ESVN_PROJECT=commons/logging
120 # default: ${PN/-svn}.
121 ESVN_PROJECT="${ESVN_PROJECT:-${PN/-svn}}"
123 # @ECLASS-VARIABLE: ESVN_BOOTSTRAP
125 # Bootstrap script or command like autogen.sh or etc..
126 # Removed in EAPI 6 and later.
127 ESVN_BOOTSTRAP="${ESVN_BOOTSTRAP:-}"
129 # @ECLASS-VARIABLE: ESVN_PATCHES
131 # subversion eclass can apply patches in subversion_bootstrap().
132 # you can use regexp in this variable like *.diff or *.patch or etc.
133 # NOTE: patches will be applied before ESVN_BOOTSTRAP is processed.
135 # Patches are searched both in ${PWD} and ${FILESDIR}, if not found in either
136 # location, the installation dies.
138 # Removed in EAPI 6 and later, use PATCHES instead.
139 ESVN_PATCHES="${ESVN_PATCHES:-}"
141 # @ECLASS-VARIABLE: ESVN_RESTRICT
143 # this should be a space delimited list of subversion eclass features to
146 # don't export the working copy to S.
147 ESVN_RESTRICT="${ESVN_RESTRICT:-}"
149 # @ECLASS-VARIABLE: ESVN_OFFLINE
151 # Set this variable to a non-empty value to disable the automatic updating of
152 # an svn source tree. This is intended to be set outside the subversion source
154 ESVN_OFFLINE="${ESVN_OFFLINE:-${EVCS_OFFLINE}}"
156 # @ECLASS-VARIABLE: ESVN_UMASK
158 # Set this variable to a custom umask. This is intended to be set by users.
159 # By setting this to something like 002, it can make life easier for people
160 # who do development as non-root (but are in the portage group), and then
161 # switch over to building with FEATURES=userpriv. Or vice-versa. Shouldn't
162 # be a security issue here as anyone who has portage group write access
163 # already can screw the system over in more creative ways.
164 ESVN_UMASK="${ESVN_UMASK:-${EVCS_UMASK}}"
166 # @ECLASS-VARIABLE: ESVN_UP_FREQ
168 # Set the minimum number of hours between svn up'ing in any given svn module. This is particularly
169 # useful for split KDE ebuilds where we want to ensure that all submodules are compiled for the same
170 # revision. It should also be kept user overrideable.
171 ESVN_UP_FREQ="${ESVN_UP_FREQ:=}"
173 # @ECLASS-VARIABLE: ESCM_LOGDIR
175 # User configuration variable. If set to a path such as e.g. /var/log/scm any
176 # package inheriting from subversion.eclass will record svn revision to
177 # ${CATEGORY}/${PN}.log in that path in pkg_preinst. This is not supposed to be
178 # set by ebuilds/eclasses. It defaults to empty so users need to opt in.
179 ESCM_LOGDIR="${ESCM_LOGDIR:=}"
181 # @FUNCTION: subversion_fetch
182 # @USAGE: [repo_uri] [destination]
184 # Wrapper function to fetch sources from subversion via svn checkout or svn update,
185 # depending on whether there is an existing working copy in ${ESVN_STORE_DIR}.
187 # Can take two optional parameters:
188 # repo_uri - a repository URI. default is ESVN_REPO_URI.
189 # destination - a check out path in S.
191 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
192 local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")"
195 if [[ -z ${repo_uri} ]]; then
196 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
199 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}"
201 # check for the scheme
202 local scheme="${repo_uri%%:*}"
211 die "${ESVN}: fetch from '${scheme}' is not yet implemented."
215 addread "/etc/subversion"
216 addwrite "${ESVN_STORE_DIR}"
218 if [[ -n "${ESVN_UMASK}" ]]; then
219 eumask_push "${ESVN_UMASK}"
222 if [[ ! -d ${ESVN_STORE_DIR} ]]; then
223 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
224 mkdir -m 775 -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
227 pushd "${ESVN_STORE_DIR}" >/dev/null || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
229 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
230 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
232 [[ -n "${revision}" ]] && options="${options} -r ${revision}"
234 if [[ "${ESVN_OPTIONS}" = *-r* ]]; then
235 ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please"
236 ewarn "see \${ESVN_REPO_URI}"
239 if has_version ">=dev-vcs/subversion-1.6.0"; then
240 options="${options} --config-option=config:auth:password-stores="
243 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
244 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
245 debug-print "${FUNCNAME}: options = \"${options}\""
247 if [[ ! -d ${wc_path}/.svn ]]; then
248 if [[ -n ${ESVN_OFFLINE} ]]; then
249 ewarn "ESVN_OFFLINE cannot be used when there is no existing checkout."
252 einfo "subversion check out start -->"
253 einfo " repository: ${repo_uri}${revision:+@}${revision}"
255 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
257 mkdir -m 775 -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
258 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
259 if [[ -n "${ESVN_USER}" ]]; then
260 ${ESVN_FETCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
262 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
265 elif [[ -n ${ESVN_OFFLINE} ]]; then
266 svn upgrade "${wc_path}" &>/dev/null
267 svn cleanup "${wc_path}" &>/dev/null
268 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
270 if [[ -n ${ESVN_REVISION} && ${ESVN_REVISION} != ${ESVN_WC_REVISION} ]]; then
271 die "${ESVN}: You requested off-line updating and revision ${ESVN_REVISION} but only revision ${ESVN_WC_REVISION} is available locally."
273 einfo "Fetching disabled: Using existing repository copy at revision ${ESVN_WC_REVISION}."
275 svn upgrade "${wc_path}" &>/dev/null
276 svn cleanup "${wc_path}" &>/dev/null
277 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
280 if [[ -n ${ESVN_UP_FREQ} ]]; then
281 if [[ -n ${ESVN_UP_FREQ//[[:digit:]]} ]]; then
282 die "${ESVN}: ESVN_UP_FREQ must be an integer value corresponding to the minimum number of hours between svn up."
283 elif [[ -z $(find "${wc_path}/.svn/entries" -mmin "+$((ESVN_UP_FREQ*60))") ]]; then
284 einfo "Fetching disabled since ${ESVN_UP_FREQ} hours has not passed since last update."
285 einfo "Using existing repository copy at revision ${ESVN_WC_REVISION}."
286 esvn_up_freq=no_update
290 if [[ -z ${esvn_up_freq} ]]; then
291 if [[ ${ESVN_WC_UUID} != $(subversion__svn_info "${repo_uri}" "Repository UUID") ]]; then
292 # UUID mismatch. Delete working copy and check out it again.
293 einfo "subversion recheck out start -->"
294 einfo " old UUID: ${ESVN_WC_UUID}"
295 einfo " new UUID: $(subversion__svn_info "${repo_uri}" "Repository UUID")"
296 einfo " repository: ${repo_uri}${revision:+@}${revision}"
298 rm -fr "${ESVN_PROJECT}" || die
300 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
302 mkdir -m 775 -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
303 cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
304 if [[ -n "${ESVN_USER}" ]]; then
305 ${ESVN_FETCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
307 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch to ${wc_path} from ${repo_uri}."
309 elif [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then
310 einfo "subversion switch start -->"
311 einfo " old repository: ${ESVN_WC_URL}@${ESVN_WC_REVISION}"
312 einfo " new repository: ${repo_uri}${revision:+@}${revision}"
314 debug-print "${FUNCNAME}: ${ESVN_SWITCH_CMD} ${options} ${repo_uri}"
316 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
317 if [[ -n "${ESVN_USER}" ]]; then
318 ${ESVN_SWITCH_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
320 ${ESVN_SWITCH_CMD} ${options} ${repo_uri} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
323 # update working copy
324 einfo "subversion update start -->"
325 einfo " repository: ${repo_uri}${revision:+@}${revision}"
327 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
329 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
330 if [[ -n "${ESVN_USER}" ]]; then
331 ${ESVN_UPDATE_CMD} ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
333 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update ${wc_path} from ${repo_uri}."
337 # export updated information for the working copy
338 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
342 if [[ -n "${ESVN_UMASK}" ]]; then
346 einfo " working copy: ${wc_path}"
348 if ! has "export" ${ESVN_RESTRICT}; then
349 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
351 local S="${S}/${S_dest}"
354 # export to the ${WORKDIR}
355 #* "svn export" has a bug. see https://bugs.gentoo.org/119236
356 #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
357 rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
364 # @FUNCTION: subversion_bootstrap
366 # Apply patches in ${ESVN_PATCHES} and run ${ESVN_BOOTSTRAP} if specified.
367 # Removed in EAPI 6 and later.
368 subversion_bootstrap() {
369 [[ ${EAPI} == [012345] ]] || die "${FUNCNAME} is removed from subversion.eclass in EAPI 6 and later"
371 if has "export" ${ESVN_RESTRICT}; then
377 if [[ -n ${ESVN_PATCHES} ]]; then
379 einfo "apply patches -->"
380 for patch in ${ESVN_PATCHES}; do
381 if [[ -f ${patch} ]]; then
384 for fpatch in ${FILESDIR}/${patch}; do
385 if [[ -f ${fpatch} ]]; then
388 die "${ESVN}: ${patch} not found"
396 if [[ -n ${ESVN_BOOTSTRAP} ]]; then
397 einfo "begin bootstrap -->"
398 if [[ -f ${ESVN_BOOTSTRAP} && -x ${ESVN_BOOTSTRAP} ]]; then
399 einfo " bootstrap with a file: ${ESVN_BOOTSTRAP}"
400 eval "./${ESVN_BOOTSTRAP}" || die "${ESVN}: can't execute ESVN_BOOTSTRAP."
402 einfo " bootstrap with command: ${ESVN_BOOTSTRAP}"
403 eval "${ESVN_BOOTSTRAP}" || die "${ESVN}: can't eval ESVN_BOOTSTRAP."
408 # @FUNCTION: subversion_wc_info
410 # @RETURN: ESVN_WC_URL, ESVN_WC_ROOT, ESVN_WC_UUID, ESVN_WC_REVISION and ESVN_WC_PATH
412 # Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI.
414 # The working copy information on the specified repository URI are set to
415 # ESVN_WC_* variables.
416 subversion_wc_info() {
417 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
418 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
420 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
421 debug-print "${FUNCNAME}: wc_path = ${wc_path}"
423 if [[ ! -d ${wc_path} ]]; then
427 export ESVN_WC_URL="$(subversion__svn_info "${wc_path}" "URL")"
428 export ESVN_WC_ROOT="$(subversion__svn_info "${wc_path}" "Repository Root")"
429 export ESVN_WC_UUID="$(subversion__svn_info "${wc_path}" "Repository UUID")"
430 export ESVN_WC_REVISION="$(subversion__svn_info "${wc_path}" "Revision")"
431 export ESVN_WC_PATH="${wc_path}"
434 # @FUNCTION: subversion_src_unpack
436 # Default src_unpack. Fetch and, in older EAPIs, bootstrap.
437 subversion_src_unpack() {
438 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
439 if has "${EAPI:-0}" 0 1; then
440 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
444 # @FUNCTION: subversion_src_prepare
446 # Default src_prepare. Bootstrap.
447 # Removed in EAPI 6 and later.
448 subversion_src_prepare() {
449 [[ ${EAPI} == [012345] ]] || die "${FUNCNAME} is removed from subversion.eclass in EAPI 6 and later"
450 subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
453 # @FUNCTION: subversion_pkg_preinst
456 # Log the svn revision of source code. Doing this in pkg_preinst because we
457 # want the logs to stick around if packages are uninstalled without messing with
459 subversion_pkg_preinst() {
460 has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}"
461 local pkgdate=$(date "+%Y%m%d %H:%M:%S")
462 if [[ -n ${ESCM_LOGDIR} ]]; then
463 local dir="${EROOT}/${ESCM_LOGDIR}/${CATEGORY}"
464 if [[ ! -d ${dir} ]]; then
465 mkdir -p "${dir}" || eerror "Failed to create '${dir}' for logging svn revision"
467 local logmessage="svn: ${pkgdate} - ${PF}:${SLOT} was merged at revision ${ESVN_WC_REVISION}"
468 if [[ -d ${dir} ]]; then
469 echo "${logmessage}" >>"${dir}/${PN}.log"
471 eerror "Could not log the message '${logmessage}' to '${dir}/${PN}.log'"
476 ## -- Private Functions
478 ## -- subversion__svn_info() ------------------------------------------------- #
480 # param $1 - a target.
481 # param $2 - a key name.
483 subversion__svn_info() {
487 env LC_ALL=C svn info ${options} --username "${ESVN_USER}" --password "${ESVN_PASSWORD}" "${target}" \
488 | grep -i "^${key}" \
492 ## -- subversion__get_repository_uri() --------------------------------------- #
494 # param $1 - a repository URI.
495 subversion__get_repository_uri() {
496 local repo_uri="${1}"
498 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
499 if [[ -z ${repo_uri} ]]; then
500 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
502 # delete trailing slash
503 if [[ -z ${repo_uri##*/} ]]; then
504 repo_uri="${repo_uri%/}"
506 repo_uri="${repo_uri%@*}"
511 ## -- subversion__get_wc_path() ---------------------------------------------- #
513 # param $1 - a repository URI.
514 subversion__get_wc_path() {
515 local repo_uri="$(subversion__get_repository_uri "${1}")"
517 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
519 echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
522 ## -- subversion__get_peg_revision() ----------------------------------------- #
524 # param $1 - a repository URI.
525 subversion__get_peg_revision() {
526 local repo_uri="${1}"
529 debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
530 # repo_uri has peg revision?
531 if [[ ${repo_uri} = *@* ]]; then
532 peg_rev="${repo_uri##*@}"
533 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
535 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."