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

Contents of /eclass/subversion.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.45 - (hide annotations) (download)
Sun Feb 17 07:59:06 2008 UTC (6 years, 10 months ago) by hattya
Branch: MAIN
Changes since 1.44: +56 -13 lines
fixes bug #188255 and bug #205787.

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

  ViewVC Help
Powered by ViewVC 1.1.20