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

Contents of /eclass/subversion.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.51 - (hide annotations) (download)
Wed Feb 20 22:28:49 2008 UTC (6 years, 4 months ago) by zlin
Branch: MAIN
Changes since 1.50: +6 -4 lines
As kindly pointed out by David Leverton there is no requirement to define ESVN_REPO_URI before inheriting this eclass. On the other hand subversion_src_fetch must die if repo_uri is unset.

1 hattya 1.45 # Copyright 1999-2008 Gentoo Foundation
2 hattya 1.1 # Distributed under the terms of the GNU General Public License v2
3 zlin 1.51 # $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.50 2008/02/20 20:36:30 zlin Exp $
4 hattya 1.1
5 zlin 1.46 # @ECLASS: subversion.eclass
6     # @MAINTAINER:
7     # Akinori Hattori <hattya@gentoo.org>
8     # Bo ├śrsted Andresen <zlin@gentoo.org>
9 swegener 1.23 #
10 zlin 1.46 # Original Author: Akinori Hattori <hattya@gentoo.org>
11 hattya 1.1 #
12 zlin 1.46 # @BLURB: The subversion eclass is written to fetch software sources from subversion repositories
13     # @DESCRIPTION:
14     # The subversion eclass provides functions to fetch, patch and bootstrap
15     # software sources from subversion repositories.
16 hattya 1.1
17 hattya 1.8 inherit eutils
18 hattya 1.1
19 zlin 1.46 ESVN="${ECLASS}"
20 hattya 1.1
21 zlin 1.50 EXPORT_FUNCTIONS src_unpack pkg_preinst
22 hattya 1.1
23 hattya 1.5 DESCRIPTION="Based on the ${ECLASS} eclass"
24 hattya 1.1
25 zlin 1.46 DEPEND="dev-util/subversion
26     net-misc/rsync"
27 hattya 1.1
28 zlin 1.46 # @ECLASS-VARIABLE: ESVN_STORE_DIR
29     # @DESCRIPTION:
30     # subversion sources store directory. Users may override this in /etc/make.conf
31     [[ -z ${ESVN_STORE_DIR} ]] && ESVN_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR:-${DISTDIR}}/svn-src"
32    
33     # @ECLASS-VARIABLE: ESVN_FETCH_CMD
34     # @DESCRIPTION:
35     # subversion checkout command
36 hattya 1.25 ESVN_FETCH_CMD="svn checkout"
37    
38 zlin 1.46 # @ECLASS-VARIABLE: ESVN_UPDATE_CMD
39     # @DESCRIPTION:
40     # subversion update command
41 hattya 1.25 ESVN_UPDATE_CMD="svn update"
42 hattya 1.1
43 cardoe 1.48 # @ECLASS-VARIABLE: ESVN_SWITCH_CMD
44     # @DESCRIPTION:
45     # subversion switch command
46     ESVN_SWITCH_CMD="svn switch"
47    
48 zlin 1.46 # @ECLASS-VARIABLE: ESVN_OPTIONS
49     # @DESCRIPTION:
50     # the options passed to checkout or update. If you want a specific revision see
51     # ESVN_REPO_URI instead of using -rREV.
52     ESVN_OPTIONS="${ESVN_OPTIONS:-}"
53    
54     # @ECLASS-VARIABLE: ESVN_REPO_URI
55     # @DESCRIPTION:
56     # repository uri
57 hattya 1.1 #
58 zlin 1.46 # e.g. http://foo/trunk, svn://bar/trunk, svn://bar/branch/foo@1234
59 hattya 1.12 #
60     # supported protocols:
61     # http://
62     # https://
63     # svn://
64 hattya 1.33 # svn+ssh://
65 hattya 1.1 #
66 zlin 1.46 # to peg to a specific revision, append @REV to the repo's uri
67     ESVN_REPO_URI="${ESVN_REPO_URI:-}"
68 hattya 1.1
69 cardoe 1.47 # @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!
77     ESVN_REVISION="${ESVN_REVISION:-}"
78    
79 zlin 1.46 # @ECLASS-VARIABLE: ESVN_PROJECT
80     # @DESCRIPTION:
81     # project name of your ebuild (= name space)
82 hattya 1.1 #
83     # subversion eclass will check out the subversion repository like:
84     #
85     # ${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}
86     #
87     # so if you define ESVN_REPO_URI as http://svn.collab.net/repo/svn/trunk or
88     # http://svn.collab.net/repo/svn/trunk/. and PN is subversion-svn.
89     # it will check out like:
90     #
91     # ${ESVN_STORE_DIR}/subversion/trunk
92     #
93 hattya 1.33 # this is not used in order to declare the name of the upstream project.
94     # so that you can declare this like:
95     #
96     # # jakarta commons-loggin
97     # ESVN_PROJECT=commons/logging
98     #
99 hattya 1.1 # default: ${PN/-svn}.
100 zlin 1.46 ESVN_PROJECT="${ESVN_PROJECT:-${PN/-svn}}"
101 hattya 1.1
102 zlin 1.46 # @ECLASS-VARIABLE: ESVN_BOOTSTRAP
103     # @DESCRIPTION:
104 hattya 1.8 # bootstrap script or command like autogen.sh or etc..
105 zlin 1.46 ESVN_BOOTSTRAP="${ESVN_BOOTSTRAP:-}"
106 hattya 1.1
107 zlin 1.46 # @ECLASS-VARIABLE: ESVN_PATCHES
108     # @DESCRIPTION:
109     # subversion eclass can apply patches in subversion_bootstrap().
110 peper 1.43 # you can use regexp in this variable like *.diff or *.patch or etc.
111     # NOTE: patches will be applied before ESVN_BOOTSTRAP is processed.
112 hattya 1.8 #
113 zlin 1.46 # Patches are searched both in ${PWD} and ${FILESDIR}, if not found in either
114     # location, the installation dies.
115     ESVN_PATCHES="${ESVN_PATCHES:-}"
116 hattya 1.33
117 zlin 1.46 # @ECLASS-VARIABLE: ESVN_RESTRICT
118     # @DESCRIPTION:
119 hattya 1.39 # this should be a space delimited list of subversion eclass features to
120     # restrict.
121 hattya 1.33 # export)
122     # don't export the working copy to S.
123 zlin 1.46 ESVN_RESTRICT="${ESVN_RESTRICT:-}"
124 hattya 1.45
125 zlin 1.49 # @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.
130     ESVN_OFFLINE="${ESVN_OFFLINE:-${ESCM_OFFLINE}}"
131    
132 zlin 1.50 # @ECLASS-VARIABLE: ESCM_LOGDIR
133     # @DESCRIPTION:
134     # User configuration variable. If set to a path such as e.g. /var/log/scm any
135     # package inheriting from subversion.eclass will record svn revision to
136     # ${CATEGORY}/${PN}.log in that path in pkg_preinst. This is not supposed to be
137     # set by ebuilds/eclasses. It defaults to empty so users need to opt in.
138     ESCM_LOGDIR="${ESCM_LOGDIR:=}"
139    
140 zlin 1.46 # @FUNCTION: subversion_fetch
141     # @USAGE: [repo_uri] [destination]
142     # @DESCRIPTION:
143     # Wrapper function to fetch sources from subversion via svn checkout or svn update,
144     # depending on whether there is an existing working copy in ${ESVN_STORE_DIR}.
145     #
146     # Can take two optional parameters:
147     # repo_uri - a repository URI. default is ESVN_REPO_URI.
148     # destination - a check out path in S.
149     subversion_fetch() {
150 cardoe 1.47 local repo_uri="$(subversion__get_repository_uri "${1:-${ESVN_REPO_URI}}")"
151     local revision="$(subversion__get_peg_revision "${1:-${ESVN_REPO_URI}}")"
152 hattya 1.39 local S_dest="${2}"
153 hattya 1.25
154 zlin 1.51 if [[ -z ${repo_uri} ]]; then
155     die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
156     fi
157    
158 cardoe 1.47 [[ -n "${ESVN_REVISION}" ]] && revision="${ESVN_REVISION}"
159    
160 hattya 1.33 # check for the protocol
161 hattya 1.39 local protocol="${repo_uri%%:*}"
162 hattya 1.1
163 hattya 1.33 case "${protocol}" in
164 vapier 1.24 http|https)
165 hattya 1.25 if built_with_use dev-util/subversion nowebdav; then
166 hattya 1.34 echo
167 vapier 1.24 eerror "In order to emerge this package, you need to"
168     eerror "re-emerge subversion with USE=-nowebdav"
169 hattya 1.34 echo
170     die "${ESVN}: please run 'USE=-nowebdav emerge subversion'"
171 vapier 1.24 fi
172     ;;
173 hattya 1.33 svn|svn+ssh)
174     ;;
175 hattya 1.5 *)
176 zlin 1.46 die "${ESVN}: fetch from '${protocol}' is not yet implemented."
177 hattya 1.5 ;;
178     esac
179 hattya 1.1
180 hattya 1.38 addread "/etc/subversion"
181     addwrite "${ESVN_STORE_DIR}"
182    
183 zlin 1.46 if [[ ! -d ${ESVN_STORE_DIR} ]]; then
184 hattya 1.17 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
185 hattya 1.33 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
186 hattya 1.1 fi
187    
188 hattya 1.33 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
189 hattya 1.1
190 hattya 1.39 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
191 hattya 1.38 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
192 hattya 1.1
193 cardoe 1.47 [[ -n "${revision}" ]] && options="${options} -r ${revision}"
194    
195     if [[ "${ESVN_OPTIONS}" = *-r* ]]; then
196     ewarn "\${ESVN_OPTIONS} contains -r, this usage is unsupported. Please"
197     ewarn "see \${ESVN_REPO_URI}"
198     fi
199    
200 hattya 1.39 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
201 hattya 1.25 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
202 hattya 1.38 debug-print "${FUNCNAME}: options = \"${options}\""
203 joker 1.37
204 zlin 1.46 if [[ ! -d ${wc_path}/.svn ]]; then
205 hattya 1.1 # first check out
206     einfo "subversion check out start -->"
207 cardoe 1.47 einfo " repository: ${repo_uri}${revision:+@}${revision}"
208 hattya 1.1
209 hattya 1.39 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
210    
211     mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
212     cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
213 hattya 1.38 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
214 hattya 1.12
215 zlin 1.49 elif [[ -n ${ESVN_OFFLINE} ]]; then
216     subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
217     if [[ -n ${ESVN_REVISION} && ${ESVN_REVISION} != ${ESVN_WC_REVISION} ]]; then
218     die "${ESVN}: You requested off-line updating and revision ${ESVN_REVISION} but only revision ${ESVN_WC_REVISION} is available locally."
219     fi
220     einfo "Fetching disabled: Using existing repository copy"
221 hattya 1.1 else
222 peper 1.44 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
223 hattya 1.45
224 cardoe 1.47 if [[ ${ESVN_WC_URL} != $(subversion__get_repository_uri "${repo_uri}") ]]; then
225 cardoe 1.48 einfo "suversion switch start -->"
226     einfo " old repository: ${ESVN_WC_URL}@${ESVN_WC_REVISION}"
227     einfo " new repository: ${repo_uri}${revision:+@}${revision}"
228    
229     debug-print "${FUNCNAME}: ${ESVN_SWITCH_CMD} ${options} ${repo_uri}"
230 hattya 1.34
231 cardoe 1.48 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
232     ${ESVN_SWITCH_CMD} ${options} ${repo_uri} || die "${ESVN}: can't update from ${repo_uri}"
233     else
234     # update working copy
235     einfo "subversion update start -->"
236     einfo " repository: ${repo_uri}${revision:+@}${revision}"
237 hattya 1.25
238 cardoe 1.48 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
239 hattya 1.39
240 cardoe 1.48 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
241     ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
242     fi
243 hattya 1.45
244 peper 1.43 fi
245 hattya 1.1
246 hattya 1.39 einfo " working copy: ${wc_path}"
247 hattya 1.33
248     if ! has "export" ${ESVN_RESTRICT}; then
249 hattya 1.39 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
250    
251     local S="${S}/${S_dest}"
252 hattya 1.33
253     # export to the ${WORKDIR}
254     #* "svn export" has a bug. see http://bugs.gentoo.org/119236
255     #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
256     rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
257     fi
258 hattya 1.1
259 hattya 1.8 echo
260 hattya 1.1 }
261    
262 zlin 1.46 # @FUNCTION: subversion_bootstrap
263     # @DESCRIPTION:
264     # Apply patches in ${ESVN_PATCHES} and run ${ESVN_BOOTSTRAP} if specified.
265     subversion_bootstrap() {
266 hattya 1.33 if has "export" ${ESVN_RESTRICT}; then
267     return
268     fi
269 hattya 1.1
270 hattya 1.8 cd "${S}"
271    
272 zlin 1.46 if [[ -n ${ESVN_PATCHES} ]]; then
273 hattya 1.15 einfo "apply patches -->"
274 hattya 1.12
275 peper 1.43 local patch fpatch
276 hattya 1.45
277 peper 1.43 for patch in ${ESVN_PATCHES}; do
278 zlin 1.46 if [[ -f ${patch} ]]; then
279 peper 1.43 epatch "${patch}"
280 hattya 1.45
281 hattya 1.8 else
282 peper 1.43 for fpatch in ${FILESDIR}/${patch}; do
283 zlin 1.46 if [[ -f ${fpatch} ]]; then
284 peper 1.43 epatch "${fpatch}"
285 hattya 1.45
286 hattya 1.8 else
287 peper 1.43 die "${ESVN}: ${patch} not found"
288 hattya 1.45
289 hattya 1.8 fi
290     done
291 hattya 1.45
292 hattya 1.8 fi
293     done
294 hattya 1.45
295 hattya 1.8 echo
296     fi
297    
298 zlin 1.46 if [[ -n ${ESVN_BOOTSTRAP} ]]; then
299 hattya 1.8 einfo "begin bootstrap -->"
300 hattya 1.12
301 zlin 1.46 if [[ -f ${ESVN_BOOTSTRAP} && -x ${ESVN_BOOTSTRAP} ]]; then
302 hattya 1.8 einfo " bootstrap with a file: ${ESVN_BOOTSTRAP}"
303     eval "./${ESVN_BOOTSTRAP}" || die "${ESVN}: can't execute ESVN_BOOTSTRAP."
304 hattya 1.45
305 hattya 1.8 else
306 peper 1.43 einfo " bootstrap with command: ${ESVN_BOOTSTRAP}"
307 hattya 1.8 eval "${ESVN_BOOTSTRAP}" || die "${ESVN}: can't eval ESVN_BOOTSTRAP."
308 hattya 1.45
309 hattya 1.1 fi
310     fi
311     }
312    
313 zlin 1.46 # @FUNCTION: subversion_src_unpack
314     # @DESCRIPTION:
315     # default src_unpack. fetch and bootstrap.
316     subversion_src_unpack() {
317 hattya 1.34 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
318     subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
319 hattya 1.1 }
320 hattya 1.33
321 zlin 1.46 # @FUNCTION: subversion_wc_info
322     # @USAGE: [repo_uri]
323 cardoe 1.47 # @RETURN: ESVN_WC_URL, ESVN_WC_ROOT, ESVN_WC_UUID, ESVN_WC_REVISION and ESVN_WC_PATH
324 zlin 1.46 # @DESCRIPTION:
325     # Get svn info for the specified repo_uri. The default repo_uri is ESVN_REPO_URI.
326 hattya 1.39 #
327 zlin 1.46 # The working copy information on the specified repository URI are set to
328 hattya 1.45 # ESVN_WC_* variables.
329 zlin 1.46 subversion_wc_info() {
330 hattya 1.39 local repo_uri="$(subversion__get_repository_uri "${1}")"
331     local wc_path="$(subversion__get_wc_path "${repo_uri}")"
332    
333     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
334     debug-print "${FUNCNAME}: wc_path = ${wc_path}"
335    
336 zlin 1.46 if [[ ! -d ${wc_path} ]]; then
337 hattya 1.39 return 1
338     fi
339    
340 cardoe 1.47 export ESVN_WC_URL="$(subversion__svn_info "${wc_path}" "URL")"
341     export ESVN_WC_ROOT="$(subversion__svn_info "${wc_path}" "Repository Root")"
342     export ESVN_WC_UUID="$(subversion__svn_info "${wc_path}" "Repository UUID")"
343     export ESVN_WC_REVISION="$(subversion__svn_info "${wc_path}" "Revision")"
344 hattya 1.45 export ESVN_WC_PATH="${wc_path}"
345 hattya 1.39 }
346    
347     ## -- Private Functions
348    
349     ## -- subversion__svn_info() ------------------------------------------------- #
350     #
351 zlin 1.46 # param $1 - a target.
352     # param $2 - a key name.
353 hattya 1.39 #
354 zlin 1.46 subversion__svn_info() {
355 hattya 1.39 local target="${1}"
356     local key="${2}"
357    
358     env LC_ALL=C svn info "${target}" | grep -i "^${key}" | cut -d" " -f2-
359     }
360    
361     ## -- subversion__get_repository_uri() --------------------------------------- #
362     #
363 zlin 1.46 # param $1 - a repository URI.
364     subversion__get_repository_uri() {
365 cardoe 1.47 local repo_uri="${1}"
366 hattya 1.39
367     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
368 hattya 1.33
369 zlin 1.46 if [[ -z ${repo_uri} ]]; then
370 hattya 1.39 die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
371     fi
372 hattya 1.33
373     # delete trailing slash
374 zlin 1.46 if [[ -z ${repo_uri##*/} ]]; then
375 hattya 1.33 repo_uri="${repo_uri%/}"
376     fi
377    
378 cardoe 1.47 repo_uri="${repo_uri%@*}"
379 hattya 1.39
380     echo "${repo_uri}"
381     }
382    
383     ## -- subversion__get_wc_path() ---------------------------------------------- #
384     #
385 zlin 1.46 # param $1 - a repository URI.
386     subversion__get_wc_path() {
387 cardoe 1.47 local repo_uri="$(subversion__get_repository_uri "${1}")"
388 hattya 1.39
389     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
390    
391     echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
392     }
393    
394 cardoe 1.47 ## -- subversion__get_peg_revision() ----------------------------------------- #
395 hattya 1.39 #
396 zlin 1.46 # param $1 - a repository URI.
397 cardoe 1.47 subversion__get_peg_revision() {
398 hattya 1.39 local repo_uri="${1}"
399    
400     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
401    
402     # repo_uri has peg revision ?
403 zlin 1.46 if [[ ${repo_uri} != *@* ]]; then
404 hattya 1.39 debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
405 hattya 1.33 fi
406 zlin 1.49
407 cardoe 1.47 local peg_rev=
408     [[ ${repo_uri} = *@* ]] && peg_rev="${repo_uri##*@}"
409 hattya 1.33
410 hattya 1.39 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
411    
412 cardoe 1.47 echo "${peg_rev}"
413 hattya 1.33 }
414 zlin 1.50
415     # @FUNCTION: subversion_pkg_preinst
416     # @DESCRIPTION:
417     # Log the svn revision of source code. Doing this in pkg_preinst because we
418     # want the logs to stick around if packages are uninstalled without messing with
419     # config protection.
420     subversion_pkg_preinst() {
421     local pkgdate=$(date "+%Y%m%d %H:%M:%S")
422     subversion_wc_info
423     if [[ -n ${ESCM_LOGDIR} ]]; then
424     local dir="${ROOT}/${ESCM_LOGDIR}/${CATEGORY}"
425     if [[ ! -d ${dir} ]]; then
426     mkdir -p "${dir}" || \
427     eerror "Failed to create '${dir}' for logging svn revision to '${PORTDIR_SCM}'"
428     fi
429     local logmessage="svn: ${pkgdate} - ${PF}:${SLOT} was merged at revision ${ESVN_WC_REVISION}"
430     if [[ -d ${dir} ]]; then
431     echo "${logmessage}" >> "${dir}/${PN}.log"
432     else
433     eerror "Could not log the message '${logmessage}' to '${dir}/${PN}.log'"
434     fi
435     fi
436 zlin 1.51 }

  ViewVC Help
Powered by ViewVC 1.1.20