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

Contents of /eclass/subversion.eclass

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.43 - (hide annotations) (download)
Sun Jul 1 23:19:42 2007 UTC (6 years, 9 months ago) by peper
Branch: MAIN
Changes since 1.42: +22 -55 lines
(QA) Little improvements.

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 peper 1.43 # $Header: /var/cvsroot/gentoo-x86/eclass/subversion.eclass,v 1.42 2007/04/23 18:55:15 cardoe 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 ferringb 1.26 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 peper 1.43 : ${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 peper 1.43 : ${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 peper 1.43 : ${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 peper 1.43 # Patches are searched both in / and ${FILESDIR}, if not found in both locations,
103     # the installation dies.
104 hattya 1.8 #
105 peper 1.43 : ${ESVN_PATCHES=}
106 hattya 1.33
107    
108     ## -- ESVN_RESTRICT:
109     #
110 hattya 1.39 # this should be a space delimited list of subversion eclass features to
111     # restrict.
112 hattya 1.33 # export)
113     # don't export the working copy to S.
114     #
115 peper 1.43 : ${ESVN_RESTRICT=}
116 hattya 1.33
117    
118     ## -- subversion_fetch() ----------------------------------------------------- #
119 hattya 1.39 #
120     # @param $1 - a repository URI. default is the ESVN_REPO_URI.
121 hattya 1.40 # @param $2 - a check out path in S.
122 hattya 1.39 #
123 hattya 1.33 function subversion_fetch() {
124 hattya 1.39 local repo_uri="$(subversion__get_repository_uri "${1}")"
125     local S_dest="${2}"
126 hattya 1.25
127 hattya 1.33 # check for the protocol
128 hattya 1.39 local protocol="${repo_uri%%:*}"
129 hattya 1.1
130 hattya 1.33 case "${protocol}" in
131 vapier 1.24 http|https)
132 hattya 1.25 if built_with_use dev-util/subversion nowebdav; then
133 hattya 1.34 echo
134 vapier 1.24 eerror "In order to emerge this package, you need to"
135     eerror "re-emerge subversion with USE=-nowebdav"
136 hattya 1.34 echo
137     die "${ESVN}: please run 'USE=-nowebdav emerge subversion'"
138 vapier 1.24 fi
139     ;;
140 hattya 1.33 svn|svn+ssh)
141     ;;
142 hattya 1.5 *)
143 hattya 1.33 die "${ESVN}: fetch from "${protocol}" is not yet implemented."
144 hattya 1.5 ;;
145     esac
146 hattya 1.1
147 hattya 1.38 addread "/etc/subversion"
148     addwrite "${ESVN_STORE_DIR}"
149    
150 hattya 1.33 if [[ ! -d "${ESVN_STORE_DIR}" ]]; then
151 hattya 1.17 debug-print "${FUNCNAME}: initial checkout. creating subversion directory"
152 hattya 1.33 mkdir -p "${ESVN_STORE_DIR}" || die "${ESVN}: can't mkdir ${ESVN_STORE_DIR}."
153 hattya 1.1 fi
154    
155 hattya 1.33 cd "${ESVN_STORE_DIR}" || die "${ESVN}: can't chdir to ${ESVN_STORE_DIR}"
156 hattya 1.1
157 hattya 1.39 local wc_path="$(subversion__get_wc_path "${repo_uri}")"
158 hattya 1.38 local options="${ESVN_OPTIONS} --config-dir ${ESVN_STORE_DIR}/.subversion"
159 hattya 1.1
160 hattya 1.39 debug-print "${FUNCNAME}: wc_path = \"${wc_path}\""
161 hattya 1.25 debug-print "${FUNCNAME}: ESVN_OPTIONS = \"${ESVN_OPTIONS}\""
162 hattya 1.38 debug-print "${FUNCNAME}: options = \"${options}\""
163 joker 1.37
164 hattya 1.33 if [[ ! -d "${wc_path}/.svn" ]]; then
165 hattya 1.1 # first check out
166     einfo "subversion check out start -->"
167 hattya 1.33 einfo " repository: ${repo_uri}"
168 hattya 1.1
169 hattya 1.39 debug-print "${FUNCNAME}: ${ESVN_FETCH_CMD} ${options} ${repo_uri}"
170    
171     mkdir -p "${ESVN_PROJECT}" || die "${ESVN}: can't mkdir ${ESVN_PROJECT}."
172     cd "${ESVN_PROJECT}" || die "${ESVN}: can't chdir to ${ESVN_PROJECT}"
173 hattya 1.38 ${ESVN_FETCH_CMD} ${options} "${repo_uri}" || die "${ESVN}: can't fetch from ${repo_uri}."
174 hattya 1.12
175 hattya 1.1 else
176 hattya 1.39 if [ "${ESVN_WC_URL}" != "$(subversion__get_repository_uri "${repo_uri}" 1)" ]; then
177 hattya 1.38 die "${ESVN}: ESVN_REPO_URI (or specified URI) and working copy's URL are not matched."
178 hattya 1.34 fi
179    
180 hattya 1.1 # update working copy
181     einfo "subversion update start -->"
182 hattya 1.33 einfo " repository: ${repo_uri}"
183 hattya 1.25
184 hattya 1.39 debug-print "${FUNCNAME}: ${ESVN_UPDATE_CMD} ${options}"
185    
186     cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
187 hattya 1.38 ${ESVN_UPDATE_CMD} ${options} || die "${ESVN}: can't update from ${repo_uri}."
188 peper 1.43 fi
189 hattya 1.1
190 peper 1.43 subversion_wc_info "${repo_uri}" || die "${ESVN}: unknown problem occurred while accessing working copy."
191 hattya 1.8
192 hattya 1.39 einfo " working copy: ${wc_path}"
193 hattya 1.33
194     if ! has "export" ${ESVN_RESTRICT}; then
195 hattya 1.39 cd "${wc_path}" || die "${ESVN}: can't chdir to ${wc_path}"
196    
197     local S="${S}/${S_dest}"
198 hattya 1.33
199     # export to the ${WORKDIR}
200     #* "svn export" has a bug. see http://bugs.gentoo.org/119236
201     #* svn export . "${S}" || die "${ESVN}: can't export to ${S}."
202     rsync -rlpgo --exclude=".svn/" . "${S}" || die "${ESVN}: can't export to ${S}."
203     fi
204 hattya 1.1
205 hattya 1.8 echo
206 hattya 1.1 }
207    
208    
209     ## -- subversion_bootstrap() ------------------------------------------------ #
210 hattya 1.39 #
211 hattya 1.17 function subversion_bootstrap() {
212 hattya 1.33 if has "export" ${ESVN_RESTRICT}; then
213     return
214     fi
215 hattya 1.1
216 hattya 1.8 cd "${S}"
217    
218 hattya 1.33 if [[ -n "${ESVN_PATCHES}" ]]; then
219 hattya 1.15 einfo "apply patches -->"
220 hattya 1.12
221 peper 1.43 local patch fpatch
222     for patch in ${ESVN_PATCHES}; do
223     if [[ -f "${patch}" ]]; then
224     epatch "${patch}"
225 hattya 1.8 else
226 peper 1.43 for fpatch in ${FILESDIR}/${patch}; do
227     if [[ -f "${fpatch}" ]]; then
228     epatch "${fpatch}"
229 hattya 1.8 else
230 peper 1.43 die "${ESVN}: ${patch} not found"
231 hattya 1.8 fi
232     done
233     fi
234     done
235     echo
236     fi
237    
238 hattya 1.33 if [[ -n "${ESVN_BOOTSTRAP}" ]]; then
239 hattya 1.8 einfo "begin bootstrap -->"
240 hattya 1.12
241 hattya 1.33 if [[ -f "${ESVN_BOOTSTRAP}" && -x "${ESVN_BOOTSTRAP}" ]]; then
242 hattya 1.8 einfo " bootstrap with a file: ${ESVN_BOOTSTRAP}"
243     eval "./${ESVN_BOOTSTRAP}" || die "${ESVN}: can't execute ESVN_BOOTSTRAP."
244     else
245 peper 1.43 einfo " bootstrap with command: ${ESVN_BOOTSTRAP}"
246 hattya 1.8 eval "${ESVN_BOOTSTRAP}" || die "${ESVN}: can't eval ESVN_BOOTSTRAP."
247 hattya 1.1 fi
248     fi
249     }
250    
251     ## -- subversion_src_unpack() ------------------------------------------------ #
252 hattya 1.39 #
253 hattya 1.17 function subversion_src_unpack() {
254 hattya 1.34 subversion_fetch || die "${ESVN}: unknown problem occurred in subversion_fetch."
255     subversion_bootstrap || die "${ESVN}: unknown problem occurred in subversion_bootstrap."
256 hattya 1.1 }
257 hattya 1.33
258    
259     ## -- subversion_wc_info() --------------------------------------------------- #
260 hattya 1.39 #
261     # @param $1 - repository URI. default is ESVN_REPO_URI.
262     #
263     function subversion_wc_info() {
264     local repo_uri="$(subversion__get_repository_uri "${1}")"
265     local wc_path="$(subversion__get_wc_path "${repo_uri}")"
266    
267     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
268     debug-print "${FUNCNAME}: wc_path = ${wc_path}"
269    
270     if [[ ! -e "${wc_path}" ]]; then
271     return 1
272     fi
273    
274     local k
275     for k in url revision; do
276 hattya 1.41 export ESVN_WC_$(subversion__to_upper_case "${k}")="$(subversion__svn_info "${wc_path}" "${k}")"
277 hattya 1.39 done
278     }
279    
280     ## -- Private Functions
281    
282    
283     ## -- subversion__svn_info() ------------------------------------------------- #
284     #
285     # @param $1 - a target.
286     # @param $2 - a key name.
287     #
288     function subversion__svn_info() {
289     local target="${1}"
290     local key="${2}"
291    
292     env LC_ALL=C svn info "${target}" | grep -i "^${key}" | cut -d" " -f2-
293     }
294    
295    
296     ## -- subversion__get_repository_uri() --------------------------------------- #
297     #
298     # @param $1 - a repository URI.
299     # @param $2 - a peg revision is deleted from a return value if this is
300     # specified.
301     #
302     function subversion__get_repository_uri() {
303     local repo_uri="${1:-${ESVN_REPO_URI}}"
304     local remove_peg_revision="${2}"
305    
306     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
307     debug-print "${FUNCNAME}: remove_peg_revision = ${remove_peg_revision}"
308 hattya 1.33
309 hattya 1.39 if [[ -z "${repo_uri}" ]]; then
310     die "${ESVN}: ESVN_REPO_URI (or specified URI) is empty."
311     fi
312 hattya 1.33
313     # delete trailing slash
314     if [[ -z "${repo_uri##*/}" ]]; then
315     repo_uri="${repo_uri%/}"
316     fi
317    
318 hattya 1.39 if [[ -n "${remove_peg_revision}" ]]; then
319     if subversion__has_peg_revision "${repo_uri}"; then
320     repo_uri="${repo_uri%@*}"
321    
322     debug-print "${FUNCNAME}: repo_uri has a peg revision"
323     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
324     fi
325     fi
326    
327     echo "${repo_uri}"
328     }
329    
330 hattya 1.33
331 hattya 1.39 ## -- subversion__get_wc_path() ---------------------------------------------- #
332     #
333     # @param $1 - a repository URI.
334     #
335     function subversion__get_wc_path() {
336     local repo_uri="$(subversion__get_repository_uri "${1}" 1)"
337    
338     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
339    
340     echo "${ESVN_STORE_DIR}/${ESVN_PROJECT}/${repo_uri##*/}"
341     }
342    
343    
344     ## -- subversion__has_peg_revision() ----------------------------------------- #
345     #
346     # @param $1 - a repository URI.
347     #
348     function subversion__has_peg_revision() {
349     local repo_uri="${1}"
350    
351     debug-print "${FUNCNAME}: repo_uri = ${repo_uri}"
352    
353     # repo_uri has peg revision ?
354     if [[ "${repo_uri}" != *@* ]]; then
355     debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
356 hattya 1.33 return 1
357     fi
358    
359 hattya 1.39 local peg_rev="${repo_uri##*@}"
360 hattya 1.41
361     case "$(subversion__to_upper_case "${peg_rev}")" in
362     [[:digit:]]*)
363     # NUMBER
364     ;;
365     HEAD|BASE|COMMITED|PREV)
366     ;;
367     {[^}]*})
368     # DATE
369     ;;
370     *)
371     debug-print "${FUNCNAME}: repo_uri does not have a peg revision."
372     return 1
373     ;;
374     esac
375 hattya 1.33
376 hattya 1.39 debug-print "${FUNCNAME}: peg_rev = ${peg_rev}"
377    
378 hattya 1.41 return 0
379     }
380 hattya 1.39
381 hattya 1.33
382 hattya 1.41 ## -- subversion__to_upper_case() ----------------------------------------- #
383     #
384     # @param $@ - the strings to upper case.
385     #
386     function subversion__to_upper_case() {
387     echo "${@}" | tr "[a-z]" "[A-Z]"
388 hattya 1.33 }

  ViewVC Help
Powered by ViewVC 1.1.20