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

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.1 Revision 1.8
1# Copyright 1999-2002 Gentoo Technologies, Inc. 1# Copyright 1999-2002 Gentoo Technologies, Inc.
2# Distributed under the terms of the GNU General Public License v2 2# Distributed under the terms of the GNU General Public License v2
3# Author: Martin Schlemmer <azarah@gentoo.org> 3# Author: Martin Schlemmer <azarah@gentoo.org>
4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.1 2002/10/26 09:16:03 azarah Exp $ 4# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.8 2002/12/01 12:34:23 azarah Exp $
5# This eclass is for general purpose functions that most ebuilds 5# This eclass is for general purpose functions that most ebuilds
6# have to implement themselfs. 6# have to implement themselves.
7# 7#
8# NB: If you add anything, please comment it! 8# NB: If you add anything, please comment it!
9 9
10ECLASS=eutils 10ECLASS=eutils
11INHERITED="$INHERITED $ECLASS" 11INHERITED="$INHERITED $ECLASS"
47 more info. */ 47 more info. */
48GROUP ( /lib/libxxx ) 48GROUP ( /lib/libxxx )
49END_LDSCRIPT 49END_LDSCRIPT
50 50
51 dosed "s:libxxx:$1:" /usr/lib/$1 51 dosed "s:libxxx:$1:" /usr/lib/$1
52
53 return 0
52} 54}
53 55
56# Simple function to draw a line consisting of '=' the same length as $*
57#
58# <azarah@gentoo.org> (11 Nov 2002)
59#
60draw_line() {
61 local i=0
62 local str_length=""
63
64 # Handle calls that do not have args, or wc not being installed ...
65 if [ -z "$1" -o ! -x "$(which wc 2>/dev/null)" ]
66 then
67 echo "==============================================================="
68 return 0
69 fi
70
71 # Get the length of $*
72 str_length="$(echo -n "$*" | wc -m)"
73
74 while [ "$i" -lt "${str_length}" ]
75 do
76 echo -n "="
77
78 i=$((i + 1))
79 done
80
81 echo
82
83 return 0
84}
85
86# Default directory where patches are located
87EPATCH_SOURCE="${WORKDIR}/patch"
88# Default extension for patches
89EPATCH_SUFFIX="patch.bz2"
90# Default options for patch
91EPATCH_OPTS=""
92# List of patches not to apply. Not this is only file names,
93# and not the full path ..
94EPATCH_EXCLUDE=""
95
96# This function is for bulk patching, or in theory for just one
97# or two patches.
98#
99# It should work with .bz2, .gz, .zip and plain text patches.
100# Currently all patches should be the same format.
101#
102# You do not have to specify '-p' option to patch, as it will
103# try with -p0 to -p5 until it succeed, or fail at -p5.
104#
105# Above EPATCH_* variables can be used to control various defaults,
106# bug they should be left as is to ensure an ebuild can rely on
107# them for.
108#
109# Patches are applied in current directory.
110#
111# Bulk Patches should preferibly have the form of:
112#
113# ??_${ARCH}_foo.${EPATCH_SUFFIX}
114#
115# For example:
116#
117# 01_all_misc-fix.patch.bz2
118# 02_sparc_another-fix.patch.bz2
119#
120# This ensures that there are a set order, and you can have ARCH
121# specific patches.
122#
123# If you however give an argument to epatch(), it will treat it as a
124# single patch that need to be applied if its a file. If on the other
125# hand its a directory, it will set EPATCH_SOURCE to this.
126#
127# <azarah@gentoo.org> (10 Nov 2002)
128#
129epatch() {
130 local PIPE_CMD=""
131 local STDERR_TARGET="${T}/$$.out"
132 local PATCH_TARGET="${T}/$$.patch"
133 local PATCH_SUFFIX=""
134 local SINGLE_PATCH="no"
135 local x=""
136
137 if [ "$#" -gt 1 ]
138 then
139 eerror "Invalid arguments to epatch()"
140 die "Invalid arguments to epatch()"
141 fi
142
143 if [ -n "$1" -a -f "$1" ]
144 then
145 SINGLE_PATCH="yes"
146
147 local EPATCH_SOURCE="$1"
148 local EPATCH_SUFFIX="${1##*\.}"
149
150 elif [ -n "$1" -a -d "$1" ]
151 then
152 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}"
153 else
154 if [ ! -d ${EPATCH_SOURCE} ]
155 then
156 echo
157 eerror "Cannot find \$EPATCH_SOURCE!"
158 echo
159 die "Cannot find \$EPATCH_SOURCE!"
160 fi
161
162 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
163 fi
164
165 case ${EPATCH_SUFFIX##*\.} in
166 bz2)
167 PIPE_CMD="bzip2 -dc"
168 PATCH_SUFFIX="bz2"
169 ;;
170 gz|Z|z)
171 PIPE_CMD="gzip -dc"
172 PATCH_SUFFIX="gz"
173 ;;
174 ZIP|zip)
175 PIPE_CMD="unzip -p"
176 PATCH_SUFFIX="zip"
177 ;;
178 *)
179 PIPE_CMD="cat"
180 PATCH_SUFFIX="patch"
181 ;;
182 esac
183
184 if [ "${SINGLE_PATCH}" = "no" ]
185 then
186 einfo "Applying various patches (bugfixes/updates)..."
187 fi
188 for x in ${EPATCH_SOURCE}
189 do
190 # New ARCH dependant patch naming scheme...
191 #
192 # ???_arch_foo.patch
193 #
194 if [ -f ${x} ] && \
195 [ -n "$1" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ]
196 then
197 local count=0
198 local popts="${EPATCH_OPTS}"
199
200 if [ -n "${EPATCH_EXCLUDE}" ]
201 then
202 if [ "${EPATCH_EXCLUDE/${x##*/}}" != "${EPATCH_EXCLUDE}" ]
203 then
204 continue
205 fi
206 fi
207
208 if [ "${SINGLE_PATCH}" = "yes" ]
209 then
210 einfo "Applying ${x##*/}..."
211 else
212 einfo " ${x##*/}..."
213 fi
214
215 echo "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
216 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
217
218 # Allow for prefix to differ ... im lazy, so shoot me :/
219 while [ "${count}" -lt 5 ]
220 do
221 # Generate some useful debug info ...
222 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
223 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
224
225 if [ "${PATCH_SUFFIX}" != "patch" ]
226 then
227 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
228 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
229 else
230 PATCH_TARGET="${x}"
231 fi
232
233 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
234 echo "patch ${popts} -p${count} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
235
236 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
237 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
238
239 if [ "${PATCH_SUFFIX}" != "patch" ]
240 then
241 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
242 then
243 echo
244 eerror "Could not extract patch!"
245 #die "Could not extract patch!"
246 count=5
247 break
248 fi
249 fi
250
251 if patch ${popts} --dry-run -f -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/} 2>&1
252 then
253 draw_line "***** ${x##*/} *****" > ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
254 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
255 echo "ACTUALLY APPLYING ${x##*/}..." >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
256 echo >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
257 draw_line "***** ${x##*/} *****" >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
258
259 patch ${popts} -p${count} < ${PATCH_TARGET} >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real 2>&1
260
261 if [ "$?" -ne 0 ]
262 then
263 cat ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
264 echo
265 eerror "A dry-run of patch command succeeded, but actually"
266 eerror "applying the patch failed!"
267 #die "Real world sux compared to the dreamworld!"
268 count=5
269 fi
270
271 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}.real
272
273 break
274 fi
275
276 count=$((count + 1))
277 done
278
279 if [ "${PATCH_SUFFIX}" != "patch" ]
280 then
281 rm -f ${PATCH_TARGET}
282 fi
283
284 if [ "${count}" -eq 5 ]
285 then
286 echo
287 eerror "Failed Patch: ${x##*/}!"
288 eerror
289 eerror "Include in your bugreport the contents of:"
290 eerror
291 eerror " ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}"
292 echo
293 die "Failed Patch: ${x##*/}!"
294 fi
295
296 rm -f ${STDERR_TARGET%/*}/${x##*/}-${STDERR_TARGET##*/}
297
298 eend 0
299 fi
300 done
301 if [ "${SINGLE_PATCH}" = "no" ]
302 then
303 einfo "Done with patching"
304 fi
305}
306

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

  ViewVC Help
Powered by ViewVC 1.1.20