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

Contents of /eclass/subversion.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.41 - (hide annotations) (download)
Sun Apr 1 14:48:37 2007 UTC (7 years, 3 months ago) by hattya
Branch: MAIN
Changes since 1.40: +26 -8 lines
fixes bug #153227

1 hattya 1.39 # Copyright 1999-2007 Gentoo Foundation
2 hattya 1.1 # Distributed under the terms of the GNU General Public License v2
3 hattya 1.41 # $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.40 2007/04/01 12:21:09 hattya Exp $
4 hattya 1.1
5     ## --------------------------------------------------------------------------- #
6     # Author: Akinori Hattori <hattya@gentoo.org>
7 swegener 1.23 #
8 hattya 1.1 # The subversion eclass is written to fetch the software sources from
9     # subversion repositories like the cvs eclass.
10     #
11     #
12     # Description:
13     # If you use this eclass, the ${S} is ${WORKDIR}/${P}.
14 hattya 1.10 # It is necessary to define the ESVN_REPO_URI variable at least.
15 hattya 1.1 #
16     ## --------------------------------------------------------------------------- #
17    
18 hattya 1.8 inherit eutils
19 hattya 1.1
20 hattya 1.8 ESVN="subversion.eclass"
21 hattya 1.1
22     EXPORT_FUNCTIONS src_unpack
23    
24     HOMEPAGE="http://subversion.tigris.org/"
25 hattya 1.5 DESCRIPTION="Based on the ${ECLASS} eclass"
26 hattya 1.1
27    
28     ## -- add subversion in DEPEND
29     #
30 mr_bones_ 1.9 DEPEND="dev-util/subversion"
31 hattya 1.1
32    
33     ## -- ESVN_STORE_DIR: subversion sources store directory
34     #
35 ferringb 1.26 ESVN_STORE_DIR="${PORTAGE_ACTUAL_DISTDIR-${DISTDIR}}/svn-src"
36 hattya 1.1
37    
38     ## -- ESVN_FETCH_CMD: subversion fetch command
39     #
40 hattya 1.25 ESVN_FETCH_CMD="svn checkout"
41    
42     ## -- ESVN_UPDATE_CMD: subversion update command
43 hattya 1.1 #
44 hattya 1.25 ESVN_UPDATE_CMD="svn update"
45 hattya 1.1
46 hattya 1.25
47     ## -- ESVN_OPTIONS:
48 hattya 1.1 #
49 hattya 1.25 # the options passed to checkout or update.
50 hattya 1.1 #
51 hattya 1.33 : ESVN_OPTIONS=${ESVN_OPTIONS:=}
52 hattya 1.1
53    
54     ## -- ESVN_REPO_URI: repository uri
55     #
56     # e.g. http://foo/trunk, svn://bar/trunk
57 hattya 1.12 #
58     # supported protocols:
59     # http://
60     # https://
61     # svn://
62 hattya 1.33 # svn+ssh://
63 hattya 1.1 #
64 hattya 1.33 : ESVN_REPO_URI=${ESVN_REPO_URI:=}
65 hattya 1.1
66    
67 hattya 1.33 ## -- ESVN_PROJECT: project name of your ebuild (= name space)
68 hattya 1.1 #
69     # subversion eclass will check out the subversion repository like:
70     #
71     # ${ESVN_STORE_DIR}/${ESVN_PROJECT}/${ESVN_REPO_URI##*/}
72     #
73     # so if you define ESVN_REPO_URI as http://svn.collab.net/repo/svn/trunk or
74     # http://svn.collab.net/repo/svn/trunk/. and PN is subversion-svn.
75     # it will check out like:
76     #
77     # ${ESVN_STORE_DIR}/subversion/trunk
78     #
79 hattya 1.33 # this is not used in order to declare the name of the upstream project.
80     # so that you can declare this like:
81     #
82     # # jakarta commons-loggin
83     # ESVN_PROJECT=commons/logging
84     #
85 hattya 1.1 # default: ${PN/-svn}.
86     #
87 hattya 1.33 : ESVN_PROJECT=${ESVN_PROJECT:=${PN/-svn}}
88 hattya 1.1
89    
90     ## -- ESVN_BOOTSTRAP:
91     #
92 hattya 1.8 # bootstrap script or command like autogen.sh or etc..
93 hattya 1.1 #
94 hattya 1.33 : ESVN_BOOTSTRAP=${ESVN_BOOTSTRAP:=}
95 hattya 1.1
96    
97 hattya 1.8 ## -- ESVN_PATCHES:
98     #
99     # subversion eclass can apply pathces in subversion_bootstrap().
100     # you can use regexp in this valiable like *.diff or *.patch or etc.
101     # NOTE: this patches will apply before eval ESVN_BOOTSTRAP.
102     #
103     # the process of applying the patch is:
104     # 1. just epatch it, if the patch exists in the path.
105     # 2. scan it under FILESDIR and epatch it, if the patch exists in FILESDIR.
106     # 3. die.
107     #
108 hattya 1.33 : ESVN_PATCHES=${ESVN_PATCHES:=}
109    
110    
111     ## -- ESVN_RESTRICT:
112     #
113 hattya 1.39 # this should be a space delimited list of subversion eclass features to
114     # restrict.
115 hattya 1.33 # export)
116     # don't export the working copy to S.
117     #
118     : ESVN_RESTRICT=${ESVN_RESTRICT:=}
119    
120    
121     ## -- subversion_fetch() ----------------------------------------------------- #
122 hattya 1.39 #
123     # @param $1 - a repository URI. default is the ESVN_REPO_URI.
124 hattya 1.40 # @param $2 - a check out path in S.
125 hattya 1.39 #
126 hattya 1.33 function subversion_fetch() {
127 hattya 1.8
128 hattya 1.39 local repo_uri="$(subversion__get_repository_uri "${1}")"
129     local S_dest="${2}"
130 hattya 1.25
131 hattya 1.33 # check for the protocol
132 hattya 1.39 local protocol="${repo_uri%%:*}"
133 hattya 1.1
134 hattya 1.33 case "${protocol}" in
135 vapier 1.24 http|https)
136 hattya 1.25 if built_with_use dev-util/subversion nowebdav; then
137 hattya 1.34 echo
138 vapier 1.24 eerror "In order to emerge this package, you need to"
139     eerror "re-emerge subversion with USE=-nowebdav"
140 hattya 1.34 echo
141     die "${ESVN}: please run 'USE=-nowebdav emerge subversion'"
142 vapier 1.24 fi
143     ;;
144 hattya 1.33 svn|svn+ssh)
145     ;;
146 hattya 1.5 *)
147 hattya 1.33 die "${ESVN}: fetch from "${protocol}" is not yet implemented."
148 hattya 1.5 ;;
149     esac
150 hattya 1.1
151 hattya 1.38 # every time
152     addread "/etc/subversion"
153     addwrite "${ESVN_STORE_DIR}"
154    
155 hattya 1.33 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then
156 hattya 1.17 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
157 hattya 1.33 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
158 hattya 1.1 fi
159    
160 hattya 1.33 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
161 hattya 1.1
162 hattya 1.39 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
163 hattya 1.38 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
164 hattya 1.1
165 hattya 1.39 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
166 hattya 1.25 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
167 hattya 1.38 debug-print "${FUNCNAME}: options = \"${options}\""
168 joker 1.37
169 hattya 1.33 if [[ ! -d "${wc_path}/.svn" ]]; then
170 hattya 1.1 # first check out
171     einfo "subversion check out start -->"
172 hattya 1.33 einfo " repository: ${repo_uri}"
173 hattya 1.1
174 hattya 1.39 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
175    
176     mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
177     cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
178 hattya 1.38 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
179 hattya 1.12
180 hattya 1.1 else
181 hattya 1.39 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
182 hattya 1.34
183 hattya 1.39 if [ "${ESVN_WC_URL}" != "$(subversion__get_repository_uri "${repo_uri}" 1)" ]; then
184 hattya 1.38 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
185 hattya 1.34 fi
186    
187 hattya 1.1 # update working copy
188     einfo "subversion update start -->"
189 hattya 1.33 einfo " repository: ${repo_uri}"
190 hattya 1.25
191 hattya 1.39 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
192    
193     cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
194 hattya 1.38 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
195 hattya 1.1
196 hattya 1.29 fi
197 hattya 1.8
198 hattya 1.39 einfo " working copy: ${wc_path}"
199 hattya 1.33
200     if ! has "export" ${ESVN_RESTRICT}; then
201 hattya 1.39 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
202    
203     local S="${S}/${S_dest}"
204 hattya 1.33
205     # export to the ${WORKDIR}
206     #* "svn export" has a bug. see http://bugs.gentoo.org/119236
207     #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
208     rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
209     fi
210 hattya 1.1
211 hattya 1.8 echo
212 hattya 1.1
213     }
214    
215    
216     ## -- subversion_bootstrap() ------------------------------------------------ #
217 hattya 1.39 #
218 hattya 1.17 function subversion_bootstrap() {
219    
220 hattya 1.33 if has "export" ${ESVN_RESTRICT}; then
221     return
222     fi
223 hattya 1.1
224 hattya 1.8 cd "${S}"
225    
226 hattya 1.33 if [[ -n "${ESVN_PATCHES}" ]]; then
227 hattya 1.15 einfo "apply patches -->"
228 hattya 1.12
229 hattya 1.33 local p=
230    
231     for p in ${ESVN_PATCHES}; do
232     if [[ -f "${p}" ]]; then
233     epatch "${p}"
234 hattya 1.8
235     else
236 hattya 1.33 local q=
237    
238     for q in ${FILESDIR}/${p}; do
239     if [[ -f "${q}" ]]; then
240     epatch "${q}"
241 hattya 1.8
242     else
243 hattya 1.33 die "${ESVN}; ${p} is not found"
244 hattya 1.8
245     fi
246     done
247     fi
248     done
249 hattya 1.33
250 hattya 1.8 echo
251 hattya 1.33
252 hattya 1.8 fi
253    
254 hattya 1.33 if [[ -n "${ESVN_BOOTSTRAP}" ]]; then
255 hattya 1.8 einfo "begin bootstrap -->"
256 hattya 1.12
257 hattya 1.33 if [[ -f "${ESVN_BOOTSTRAP}" && -x "${ESVN_BOOTSTRAP}" ]]; then
258 hattya 1.8 einfo " bootstrap with a file: ${ESVN_BOOTSTRAP}"
259     eval "./${ESVN_BOOTSTRAP}" || die "${ESVN}: can't execute ESVN_BOOTSTRAP."
260    
261     else
262 hattya 1.16 einfo " bootstrap with commands: ${ESVN_BOOTSTRAP}"
263 hattya 1.8 eval "${ESVN_BOOTSTRAP}" || die "${ESVN}: can't eval ESVN_BOOTSTRAP."
264 hattya 1.1
265     fi
266     fi
267    
268     }
269    
270    
271     ## -- subversion_src_unpack() ------------------------------------------------ #
272 hattya 1.39 #
273 hattya 1.17 function subversion_src_unpack() {
274 hattya 1.1
275 hattya 1.34 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
276     subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
277 hattya 1.1
278     }
279 hattya 1.33
280    
281     ## -- subversion_wc_info() --------------------------------------------------- #
282 hattya 1.39 #
283     # @param $1 - repository URI. default is ESVN_REPO_URI.
284     #
285     function subversion_wc_info() {
286    
287     local repo_uri="$(subversion__get_repository_uri "${1}")"
288     local wc_path="$(subversion__get_wc_path "${repo_uri}")"
289    
290     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
291     debug-print "${FUNCNAME}: wc_path = ${wc_path}"
292    
293     if [[ ! -e "${wc_path}" ]]; then
294     return 1
295     fi
296    
297     local k
298    
299     for k in url revision; do
300 hattya 1.41 export ESVN_WC_$(subversion__to_upper_case "${k}")="$(subversion__svn_info "${wc_path}" "${k}")"
301 hattya 1.39 done
302    
303     }
304    
305    
306     ## -- Private Functions
307    
308    
309     ## -- subversion__svn_info() ------------------------------------------------- #
310     #
311     # @param $1 - a target.
312     # @param $2 - a key name.
313     #
314     function subversion__svn_info() {
315 hattya 1.33
316 hattya 1.39 local target="${1}"
317     local key="${2}"
318    
319     env LC_ALL=C svn info "${target}" | grep -i "^${key}" | cut -d" " -f2-
320    
321     }
322    
323    
324     ## -- subversion__get_repository_uri() --------------------------------------- #
325     #
326     # @param $1 - a repository URI.
327     # @param $2 - a peg revision is deleted from a return value if this is
328     # specified.
329     #
330     function subversion__get_repository_uri() {
331    
332     local repo_uri="${1:-${ESVN_REPO_URI}}"
333     local remove_peg_revision="${2}"
334    
335     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
336     debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
337 hattya 1.33
338 hattya 1.39 if [[ -z "${repo_uri}" ]]; then
339     die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
340     fi
341 hattya 1.33
342     # delete trailing slash
343     if [[ -z "${repo_uri##*/}" ]]; then
344     repo_uri="${repo_uri%/}"
345     fi
346    
347 hattya 1.39 if [[ -n "${remove_peg_revision}" ]]; then
348     if subversion__has_peg_revision "${repo_uri}"; then
349     repo_uri="${repo_uri%@*}"
350    
351     debug-print "${FUNCNAME}: repo_uri has a peg revision"
352     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
353     fi
354     fi
355    
356     echo "${repo_uri}"
357    
358     }
359    
360 hattya 1.33
361 hattya 1.39 ## -- subversion__get_wc_path() ---------------------------------------------- #
362     #
363     # @param $1 - a repository URI.
364     #
365     function subversion__get_wc_path() {
366    
367     local repo_uri="$(subversion__get_repository_uri "${1}" 1)"
368    
369     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
370    
371     echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
372    
373     }
374    
375    
376     ## -- subversion__has_peg_revision() ----------------------------------------- #
377     #
378     # @param $1 - a repository URI.
379     #
380     function subversion__has_peg_revision() {
381    
382     local repo_uri="${1}"
383    
384     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
385    
386     # repo_uri has peg revision ?
387     if [[ "${repo_uri}" != *@* ]]; then
388     debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
389 hattya 1.33 return 1
390     fi
391    
392 hattya 1.39 local peg_rev="${repo_uri##*@}"
393 hattya 1.41
394     case "$(subversion__to_upper_case "${peg_rev}")" in
395     [[:digit:]]*)
396     # NUMBER
397     ;;
398     HEAD|BASE|COMMITED|PREV)
399     ;;
400     {[^}]*})
401     # DATE
402     ;;
403     *)
404     debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
405     return 1
406     ;;
407     esac
408 hattya 1.33
409 hattya 1.39 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
410    
411 hattya 1.41 return 0
412    
413     }
414 hattya 1.39
415 hattya 1.33
416 hattya 1.41 ## -- subversion__to_upper_case() ----------------------------------------- #
417     #
418     # @param $@ - the strings to upper case.
419     #
420     function subversion__to_upper_case() {
421     echo "${@}" | tr "[a-z]" "[A-Z]"
422 hattya 1.33 }

  ViewVC Help
Powered by ViewVC 1.1.20