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

Diff of /eclass/eutils.eclass

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

Revision 1.296 Revision 1.328
1# Copyright 1999-2007 Gentoo Foundation 1# Copyright 1999-2009 Gentoo Foundation
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# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.296 2008/02/13 20:50:06 wolf31o2 Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.328 2010/01/10 15:58:58 scarabeus Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
47 sleep 1 47 sleep 1
48 done 48 done
49 fi 49 fi
50} 50}
51 51
52# Default directory where patches are located 52# @FUNCTION: ecvs_clean
53# @USAGE: [list of dirs]
54# @DESCRIPTION:
55# Remove CVS directories recursiveley. Useful when a source tarball contains
56# internal CVS directories. Defaults to $PWD.
57ecvs_clean() {
58 [[ -z $* ]] && set -- .
59 find "$@" -type d -name 'CVS' -prune -print0 | xargs -0 rm -rf
60 find "$@" -type f -name '.cvs*' -print0 | xargs -0 rm -rf
61}
62
63# @FUNCTION: esvn_clean
64# @USAGE: [list of dirs]
65# @DESCRIPTION:
66# Remove .svn directories recursiveley. Useful when a source tarball contains
67# internal Subversion directories. Defaults to $PWD.
68esvn_clean() {
69 [[ -z $* ]] && set -- .
70 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
71}
72
73# @FUNCTION: eshopts_push
74# @USAGE: [options to `set`]
75# @DESCRIPTION:
76# Often times code will want to enable a shell option to change code behavior.
77# Since changing shell options can easily break other pieces of code (which
78# assume the default state), eshopts_push is used to (1) push the current shell
79# options onto a stack and (2) pass the specified arguments to set.
80#
81# A common example is to disable shell globbing so that special meaning/care
82# may be used with variables/arguments to custom functions. That would be:
83# @CODE
84# eshopts_push -o noglob
85# for x in ${foo} ; do
86# if ...some check... ; then
87# eshopts_pop
88# return 0
89# fi
90# done
91# eshopts_pop
92# @CODE
93eshopts_push() {
94 # have to assume __ESHOPTS_SAVE__ isn't screwed with
95 # as a `declare -a` here will reset its value
96 local i=${#__ESHOPTS_SAVE__[@]}
97 __ESHOPTS_SAVE__[$i]=$-
98 [[ $# -eq 0 ]] && return 0
99 set "$@" || die "eshopts_push: bad options to set: $*"
100}
101
102# @FUNCTION: eshopts_pop
103# @USAGE:
104# @DESCRIPTION:
105# Restore the shell options to the state saved with the corresponding
106# eshopts_push call. See that function for more details.
107eshopts_pop() {
108 [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments"
109 local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 ))
110 [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair"
111 local s=${__ESHOPTS_SAVE__[$i]}
112 unset __ESHOPTS_SAVE__[$i]
113 set +$- || die "eshopts_pop: sanity: invalid shell settings: $-"
114 set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}"
115}
116
117# @VARIABLE: EPATCH_SOURCE
118# @DESCRIPTION:
119# Default directory to search for patches.
53EPATCH_SOURCE="${WORKDIR}/patch" 120EPATCH_SOURCE="${WORKDIR}/patch"
54# Default extension for patches 121# @VARIABLE: EPATCH_SUFFIX
122# @DESCRIPTION:
123# Default extension for patches (do not prefix the period yourself).
55EPATCH_SUFFIX="patch.bz2" 124EPATCH_SUFFIX="patch.bz2"
125# @VARIABLE: EPATCH_OPTS
126# @DESCRIPTION:
56# Default options for patch 127# Default options for patch:
128# @CODE
57# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571 129# -g0 - keep RCS, ClearCase, Perforce and SCCS happy #24571
58# Set --no-backup-if-mismatch so we don't leave '.orig' files behind. 130# --no-backup-if-mismatch - do not leave .orig files behind
59# Set -E to automatically remove empty files. 131# -E - automatically remove empty files
132# @CODE
60EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 133EPATCH_OPTS="-g0 -E --no-backup-if-mismatch"
134# @VARIABLE: EPATCH_EXCLUDE
135# @DESCRIPTION:
61# List of patches not to apply. Not this is only file names, 136# List of patches not to apply. Note this is only file names,
62# and not the full path .. 137# and not the full path. Globs accepted.
63EPATCH_EXCLUDE="" 138EPATCH_EXCLUDE=""
139# @VARIABLE: EPATCH_SINGLE_MSG
140# @DESCRIPTION:
64# Change the printed message for a single patch. 141# Change the printed message for a single patch.
65EPATCH_SINGLE_MSG="" 142EPATCH_SINGLE_MSG=""
143# @VARIABLE: EPATCH_MULTI_MSG
144# @DESCRIPTION:
66# Change the printed message for multiple patches. 145# Change the printed message for multiple patches.
67EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..." 146EPATCH_MULTI_MSG="Applying various patches (bugfixes/updates) ..."
68# Force applying bulk patches even if not following the style: 147# @VARIABLE: EPATCH_FORCE
69# 148# @DESCRIPTION:
70# ??_${ARCH}_foo.${EPATCH_SUFFIX} 149# Only require patches to match EPATCH_SUFFIX rather than the extended
71# 150# arch naming style.
72EPATCH_FORCE="no" 151EPATCH_FORCE="no"
73 152
74# This function is for bulk patching, or in theory for just one 153# @FUNCTION: epatch
75# or two patches. 154# @USAGE: [patches] [dirs of patches]
155# @DESCRIPTION:
156# epatch is designed to greatly simplify the application of patches. It can
157# process patch files directly, or directories of patches. The patches may be
158# compressed (bzip/gzip/etc...) or plain text. You generally need not specify
159# the -p option as epatch will automatically attempt -p0 to -p5 until things
160# apply successfully.
76# 161#
77# It should work with .bz2, .gz, .zip and plain text patches. 162# If you do not specify any options, then epatch will default to the directory
78# Currently all patches should be the same format. 163# specified by EPATCH_SOURCE.
79# 164#
80# You do not have to specify '-p' option to patch, as it will 165# When processing directories, epatch will apply all patches that match:
81# try with -p0 to -p5 until it succeed, or fail at -p5. 166# @CODE
82# 167# ${EPATCH_FORCE} == "yes"
83# Above EPATCH_* variables can be used to control various defaults,
84# bug they should be left as is to ensure an ebuild can rely on
85# them for.
86#
87# Patches are applied in current directory.
88#
89# Bulk Patches should preferibly have the form of:
90#
91# ??_${ARCH}_foo.${EPATCH_SUFFIX} 168# ??_${ARCH}_foo.${EPATCH_SUFFIX}
169# else
170# *.${EPATCH_SUFFIX}
171# @CODE
172# The leading ?? are typically numbers used to force consistent patch ordering.
173# The arch field is used to apply patches only for the host architecture with
174# the special value of "all" means apply for everyone. Note that using values
175# other than "all" is highly discouraged -- you should apply patches all the
176# time and let architecture details be detected at configure/compile time.
92# 177#
93# For example: 178# If EPATCH_SUFFIX is empty, then no period before it is implied when searching
179# for patches to apply.
94# 180#
95# 01_all_misc-fix.patch.bz2 181# Refer to the other EPATCH_xxx variables for more customization of behavior.
96# 02_sparc_another-fix.patch.bz2
97#
98# This ensures that there are a set order, and you can have ARCH
99# specific patches.
100#
101# If you however give an argument to epatch(), it will treat it as a
102# single patch that need to be applied if its a file. If on the other
103# hand its a directory, it will set EPATCH_SOURCE to this.
104#
105# <azarah@gentoo.org> (10 Nov 2002)
106#
107epatch() { 182epatch() {
108 _epatch_draw_line() { 183 _epatch_draw_line() {
184 # create a line of same length as input string
109 [[ -z $1 ]] && set "$(printf "%65s" '')" 185 [[ -z $1 ]] && set "$(printf "%65s" '')"
110 echo "${1//?/=}" 186 echo "${1//?/=}"
111 } 187 }
112 _epatch_assert() { local _pipestatus=${PIPESTATUS[*]}; [[ ${_pipestatus// /} -eq 0 ]] ; }
113 local PIPE_CMD=""
114 local STDERR_TARGET="${T}/$$.out"
115 local PATCH_TARGET="${T}/$$.patch"
116 local PATCH_SUFFIX=""
117 local SINGLE_PATCH="no"
118 local x=""
119 188
120 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402 189 unset P4CONFIG P4PORT P4USER # keep perforce at bay #56402
121 190
122 if [ "$#" -gt 1 ] 191 # Let the rest of the code process one user arg at a time --
123 then 192 # each arg may expand into multiple patches, and each arg may
193 # need to start off with the default global EPATCH_xxx values
194 if [[ $# -gt 1 ]] ; then
124 local m="" 195 local m
125 for m in "$@" ; do 196 for m in "$@" ; do
126 epatch "${m}" 197 epatch "${m}"
127 done 198 done
128 return 0 199 return 0
129 fi 200 fi
130 201
131 if [ -n "$1" -a -f "$1" ] 202 local SINGLE_PATCH="no"
132 then 203 # no args means process ${EPATCH_SOURCE}
204 [[ $# -eq 0 ]] && set -- "${EPATCH_SOURCE}"
205
206 if [[ -f $1 ]] ; then
133 SINGLE_PATCH="yes" 207 SINGLE_PATCH="yes"
134 208 set -- "$1"
135 local EPATCH_SOURCE="$1" 209 # Use the suffix from the single patch (localize it); the code
210 # below will find the suffix for us
136 local EPATCH_SUFFIX="${1##*\.}" 211 local EPATCH_SUFFIX=$1
137 212
138 elif [ -n "$1" -a -d "$1" ] 213 elif [[ -d $1 ]] ; then
139 then 214 # Some people like to make dirs of patches w/out suffixes (vim)
140 # Allow no extension if EPATCH_FORCE=yes ... used by vim for example ... 215 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
141 if [ "${EPATCH_FORCE}" = "yes" ] && [ -z "${EPATCH_SUFFIX}" ] 216
217 else
218 # sanity check ... if it isn't a dir or file, wtf man ?
219 [[ $# -ne 0 ]] && EPATCH_SOURCE=$1
220 echo
221 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:"
222 eerror
223 eerror " ${EPATCH_SOURCE}"
224 eerror " ( ${EPATCH_SOURCE##*/} )"
225 echo
226 die "Cannot find \$EPATCH_SOURCE!"
227 fi
228
229 local PIPE_CMD
230 case ${EPATCH_SUFFIX##*\.} in
231 xz) PIPE_CMD="xz -dc" ;;
232 lzma) PIPE_CMD="lzma -dc" ;;
233 bz2) PIPE_CMD="bzip2 -dc" ;;
234 gz|Z|z) PIPE_CMD="gzip -dc" ;;
235 ZIP|zip) PIPE_CMD="unzip -p" ;;
236 *) ;;
237 esac
238
239 [[ ${SINGLE_PATCH} == "no" ]] && einfo "${EPATCH_MULTI_MSG}"
240
241 local x
242 for x in "$@" ; do
243 # If the patch dir given contains subdirs, or our EPATCH_SUFFIX
244 # didn't match anything, ignore continue on
245 [[ ! -f ${x} ]] && continue
246
247 local patchname=${x##*/}
248
249 # Apply single patches, or forced sets of patches, or
250 # patches with ARCH dependant names.
251 # ???_arch_foo.patch
252 # Else, skip this input altogether
253 local a=${patchname#*_} # strip the ???_
254 a=${a%%_*} # strip the _foo.patch
255 if ! [[ ${SINGLE_PATCH} == "yes" || \
256 ${EPATCH_FORCE} == "yes" || \
257 ${a} == all || \
258 ${a} == ${ARCH} ]]
142 then 259 then
143 local EPATCH_SOURCE="$1/*" 260 continue
261 fi
262
263 # Let people filter things dynamically
264 if [[ -n ${EPATCH_EXCLUDE} ]] ; then
265 # let people use globs in the exclude
266 eshopts_push -o noglob
267
268 local ex
269 for ex in ${EPATCH_EXCLUDE} ; do
270 if [[ ${patchname} == ${ex} ]] ; then
271 eshopts_pop
272 continue 2
273 fi
274 done
275
276 eshopts_pop
277 fi
278
279 if [[ ${SINGLE_PATCH} == "yes" ]] ; then
280 if [[ -n ${EPATCH_SINGLE_MSG} ]] ; then
281 einfo "${EPATCH_SINGLE_MSG}"
282 else
283 einfo "Applying ${patchname} ..."
284 fi
144 else 285 else
145 local EPATCH_SOURCE="$1/*.${EPATCH_SUFFIX}" 286 einfo " ${patchname} ..."
146 fi 287 fi
147 else 288
148 if [[ ! -d ${EPATCH_SOURCE} ]] || [[ -n $1 ]] ; then 289 # most of the time, there will only be one run per unique name,
149 if [ -n "$1" -a "${EPATCH_SOURCE}" = "${WORKDIR}/patch" ] 290 # but if there are more, make sure we get unique log filenames
150 then 291 local STDERR_TARGET="${T}/${patchname}.out"
151 EPATCH_SOURCE="$1" 292 if [[ -e ${STDERR_TARGET} ]] ; then
293 STDERR_TARGET="${T}/${patchname}-$$.out"
294 fi
295
296 printf "***** %s *****\n\n" "${patchname}" > "${STDERR_TARGET}"
297
298 # Decompress the patch if need be
299 local count=0
300 local PATCH_TARGET
301 if [[ -n ${PIPE_CMD} ]] ; then
302 PATCH_TARGET="${T}/$$.patch"
303 echo "PIPE_COMMAND: ${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> "${STDERR_TARGET}"
304
305 if ! (${PIPE_CMD} "${x}" > "${PATCH_TARGET}") >> "${STDERR_TARGET}" 2>&1 ; then
306 echo
307 eerror "Could not extract patch!"
308 #die "Could not extract patch!"
309 count=5
310 break
152 fi 311 fi
312 else
313 PATCH_TARGET=${x}
314 fi
153 315
316 # Check for absolute paths in patches. If sandbox is disabled,
317 # people could (accidently) patch files in the root filesystem.
318 # Or trigger other unpleasantries #237667. So disallow -p0 on
319 # such patches.
320 local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }')
321 if [[ -n ${abs_paths} ]] ; then
322 count=1
323 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
324 fi
325
326 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
327 while [[ ${count} -lt 5 ]] ; do
328 # Generate some useful debug info ...
329 (
330 _epatch_draw_line "***** ${patchname} *****"
154 echo 331 echo
155 eerror "Cannot find \$EPATCH_SOURCE! Value for \$EPATCH_SOURCE is:" 332 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'"
333 echo
334 _epatch_draw_line "***** ${patchname} *****"
335 ) >> "${STDERR_TARGET}"
336
337 if (patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}") >> "${STDERR_TARGET}" 2>&1 ; then
338 (
339 _epatch_draw_line "***** ${patchname} *****"
340 echo
341 echo "ACTUALLY APPLYING ${patchname} ..."
342 echo
343 _epatch_draw_line "***** ${patchname} *****"
344 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1
345 ) >> "${STDERR_TARGET}"
346
347 if [ $? -ne 0 ] ; then
348 echo
349 eerror "A dry-run of patch command succeeded, but actually"
350 eerror "applying the patch failed!"
351 #die "Real world sux compared to the dreamworld!"
352 count=5
353 fi
354 break
355 fi
356
357 : $(( count++ ))
358 done
359
360 # if we had to decompress the patch, delete the temp one
361 if [[ -n ${PIPE_CMD} ]] ; then
362 rm -f "${PATCH_TARGET}"
363 fi
364
365 if [[ ${count} -ge 5 ]] ; then
366 echo
367 eerror "Failed Patch: ${patchname} !"
368 eerror " ( ${PATCH_TARGET} )"
156 eerror 369 eerror
157 eerror " ${EPATCH_SOURCE}" 370 eerror "Include in your bugreport the contents of:"
158 eerror " ( ${EPATCH_SOURCE##*/} )" 371 eerror
372 eerror " ${STDERR_TARGET}"
159 echo 373 echo
160 die "Cannot find \$EPATCH_SOURCE!"
161 fi
162
163 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
164 fi
165
166 case ${EPATCH_SUFFIX##*\.} in
167 bz2)
168 PIPE_CMD="bzip2 -dc"
169 PATCH_SUFFIX="bz2"
170 ;;
171 gz|Z|z)
172 PIPE_CMD="gzip -dc"
173 PATCH_SUFFIX="gz"
174 ;;
175 ZIP|zip)
176 PIPE_CMD="unzip -p"
177 PATCH_SUFFIX="zip"
178 ;;
179 *)
180 PIPE_CMD="cat"
181 PATCH_SUFFIX="patch"
182 ;;
183 esac
184
185 if [ "${SINGLE_PATCH}" = "no" ]
186 then
187 einfo "${EPATCH_MULTI_MSG}"
188 fi
189 for x in ${EPATCH_SOURCE}
190 do
191 # New ARCH dependant patch naming scheme ...
192 #
193 # ???_arch_foo.patch
194 #
195 if [ -f ${x} ] && \
196 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "${x/_${ARCH}_}" != "${x}" ] || \
197 [ "${EPATCH_FORCE}" = "yes" ])
198 then
199 local count=0
200 local popts="${EPATCH_OPTS}"
201 local patchname=${x##*/}
202
203 if [ -n "${EPATCH_EXCLUDE}" ]
204 then
205 if [ "${EPATCH_EXCLUDE/${patchname}}" != "${EPATCH_EXCLUDE}" ]
206 then
207 continue
208 fi
209 fi
210
211 if [ "${SINGLE_PATCH}" = "yes" ]
212 then
213 if [ -n "${EPATCH_SINGLE_MSG}" ]
214 then
215 einfo "${EPATCH_SINGLE_MSG}"
216 else
217 einfo "Applying ${patchname} ..."
218 fi
219 else
220 einfo " ${patchname} ..."
221 fi
222
223 echo "***** ${patchname} *****" > ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
224 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
225
226 # Allow for prefix to differ ... im lazy, so shoot me :/
227 while [ "${count}" -lt 5 ]
228 do
229 # Generate some useful debug info ...
230 _epatch_draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
231 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
232
233 if [ "${PATCH_SUFFIX}" != "patch" ]
234 then
235 echo -n "PIPE_COMMAND: " >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
236 echo "${PIPE_CMD} ${x} > ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
237 else
238 PATCH_TARGET="${x}"
239 fi
240
241 echo -n "PATCH COMMAND: " >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
242 echo "patch -p${count} ${popts} < ${PATCH_TARGET}" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
243
244 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
245 _epatch_draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
246
247 if [ "${PATCH_SUFFIX}" != "patch" ]
248 then
249 if ! (${PIPE_CMD} ${x} > ${PATCH_TARGET}) >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 2>&1
250 then
251 echo
252 eerror "Could not extract patch!"
253 #die "Could not extract patch!"
254 count=5
255 break
256 fi
257 fi
258
259 if (cat ${PATCH_TARGET} | patch -p${count} ${popts} --dry-run -f ; _epatch_assert) >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 2>&1
260 then
261 _epatch_draw_line "***** ${patchname} *****" > ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
262 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
263 echo "ACTUALLY APPLYING ${patchname} ..." >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
264 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
265 _epatch_draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
266
267 cat ${PATCH_TARGET} | patch -p${count} ${popts} >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 2>&1
268 _epatch_assert
269
270 if [ "$?" -ne 0 ]
271 then
272 cat ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
273 echo
274 eerror "A dry-run of patch command succeeded, but actually"
275 eerror "applying the patch failed!"
276 #die "Real world sux compared to the dreamworld!"
277 count=5
278 fi
279
280 rm -f ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
281
282 break
283 fi
284
285 count=$((count + 1))
286 done
287
288 if [ "${PATCH_SUFFIX}" != "patch" ]
289 then
290 rm -f ${PATCH_TARGET}
291 fi
292
293 if [ "${count}" -eq 5 ]
294 then
295 echo
296 eerror "Failed Patch: ${patchname} !"
297 eerror " ( ${PATCH_TARGET} )"
298 eerror
299 eerror "Include in your bugreport the contents of:"
300 eerror
301 eerror " ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}"
302 echo
303 die "Failed Patch: ${patchname}!" 374 die "Failed Patch: ${patchname}!"
304 fi 375 fi
305 376
306 rm -f ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 377 # if everything worked, delete the patch log
307 378 rm -f "${STDERR_TARGET}"
308 eend 0 379 eend 0
309 fi
310 done 380 done
311 if [ "${SINGLE_PATCH}" = "no" ] 381
312 then 382 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
313 einfo "Done with patching" 383 : # everything worked
384}
385epatch_user() {
386 [[ $# -ne 0 ]] && die "epatch_user takes no options"
387
388 # don't clobber any EPATCH vars that the parent might want
389 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
390 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
391 EPATCH_SOURCE=${base}/${CTARGET}/${check}
392 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
393 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
394 if [[ -d ${EPATCH_SOURCE} ]] ; then
395 EPATCH_SOURCE=${EPATCH_SOURCE} \
396 EPATCH_SUFFIX="patch" \
397 EPATCH_FORCE="yes" \
398 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
399 epatch
400 break
314 fi 401 fi
402 done
315} 403}
316 404
317# @FUNCTION: emktemp 405# @FUNCTION: emktemp
318# @USAGE: [temp dir] 406# @USAGE: [temp dir]
319# @DESCRIPTION: 407# @DESCRIPTION:
355# base-system@gentoo.org (Linux) 443# base-system@gentoo.org (Linux)
356# Joe Jezak <josejx@gmail.com> (OS X) 444# Joe Jezak <josejx@gmail.com> (OS X)
357# usata@gentoo.org (OS X) 445# usata@gentoo.org (OS X)
358# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD) 446# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD)
359# @DESCRIPTION: 447# @DESCRIPTION:
360# Small wrapper for getent (Linux), nidump (Mac OS X), 448# Small wrapper for getent (Linux),
449# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5),
361# and pw (FreeBSD) used in enewuser()/enewgroup() 450# and pw (FreeBSD) used in enewuser()/enewgroup()
362egetent() { 451egetent() {
363 case ${CHOST} in 452 case ${CHOST} in
364 *-darwin*) 453 *-darwin[678])
365 case "$2" in 454 case "$2" in
366 *[!0-9]*) # Non numeric 455 *[!0-9]*) # Non numeric
367 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" 456 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
368 ;; 457 ;;
369 *) # Numeric 458 *) # Numeric
370 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 459 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
460 ;;
461 esac
462 ;;
463 *-darwin*)
464 local mytype=$1
465 [[ "passwd" == $mytype ]] && mytype="Users"
466 [[ "group" == $mytype ]] && mytype="Groups"
467 case "$2" in
468 *[!0-9]*) # Non numeric
469 dscl . -read /$mytype/$2 2>/dev/null |grep RecordName
470 ;;
471 *) # Numeric
472 local mykey="UniqueID"
473 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID"
474 dscl . -search /$mytype $mykey $2 2>/dev/null
371 ;; 475 ;;
372 esac 476 esac
373 ;; 477 ;;
374 *-freebsd*|*-dragonfly*) 478 *-freebsd*|*-dragonfly*)
375 local opts action="user" 479 local opts action="user"
575 fi 679 fi
576 ;; 680 ;;
577 681
578 *) 682 *)
579 if [[ -z $@ ]] ; then 683 if [[ -z $@ ]] ; then
580 useradd ${opts} ${euser} \ 684 useradd ${opts} \
581 -c "added by portage for ${PN}" \ 685 -c "added by portage for ${PN}" \
686 ${euser} \
582 || die "enewuser failed" 687 || die "enewuser failed"
583 else 688 else
584 einfo " - Extra: $@" 689 einfo " - Extra: $@"
585 useradd ${opts} ${euser} "$@" \ 690 useradd ${opts} "$@" \
691 ${euser} \
586 || die "enewuser failed" 692 || die "enewuser failed"
587 fi 693 fi
588 ;; 694 ;;
589 esac 695 esac
590 696
872 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" 978 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
873 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 979 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
874 980
875 cat <<-EOF > "${desktop}" 981 cat <<-EOF > "${desktop}"
876 [Desktop Entry] 982 [Desktop Entry]
877 Version=1.0
878 Name=${name} 983 Name=${name}
879 Type=Application 984 Type=Application
880 Comment=${DESCRIPTION} 985 Comment=${DESCRIPTION}
881 Exec=${exec} 986 Exec=${exec}
882 TryExec=${exec%% *} 987 TryExec=${exec%% *}
921 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo." 1026 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
922 fi 1027 fi
923} 1028}
924 1029
925# @FUNCTION: make_session_desktop 1030# @FUNCTION: make_session_desktop
926# @USAGE: <title> <command> 1031# @USAGE: <title> <command> [command args...]
927# @DESCRIPTION: 1032# @DESCRIPTION:
928# Make a GDM/KDM Session file. The title is the file to execute to start the 1033# Make a GDM/KDM Session file. The title is the file to execute to start the
929# Window Manager. The command is the name of the Window Manager. 1034# Window Manager. The command is the name of the Window Manager.
1035#
1036# You can set the name of the file via the ${wm} variable.
930make_session_desktop() { 1037make_session_desktop() {
931 [[ -z $1 ]] && eerror "make_session_desktop: You must specify the title" && return 1 1038 [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1
932 [[ -z $2 ]] && eerror "make_session_desktop: You must specify the command" && return 1 1039 [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1
933 1040
934 local title=$1 1041 local title=$1
935 local command=$2 1042 local command=$2
936 local desktop=${T}/${wm}.desktop 1043 local desktop=${T}/${wm:-${PN}}.desktop
1044 shift 2
937 1045
938 cat <<-EOF > "${desktop}" 1046 cat <<-EOF > "${desktop}"
939 [Desktop Entry] 1047 [Desktop Entry]
940 Name=${title} 1048 Name=${title}
941 Comment=This session logs you into ${title} 1049 Comment=This session logs you into ${title}
942 Exec=${command} 1050 Exec=${command} $*
943 TryExec=${command} 1051 TryExec=${command}
944 Type=Application 1052 Type=XSession
945 EOF 1053 EOF
946 1054
947 ( 1055 (
948 # wrap the env here so that the 'insinto' call 1056 # wrap the env here so that the 'insinto' call
949 # doesn't corrupt the env of the caller 1057 # doesn't corrupt the env of the caller
1261 lic="${PWD}/${lic}" 1369 lic="${PWD}/${lic}"
1262 elif [ -e "${lic}" ] ; then 1370 elif [ -e "${lic}" ] ; then
1263 lic="${lic}" 1371 lic="${lic}"
1264 fi 1372 fi
1265 fi 1373 fi
1266 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1267 local l="`basename ${lic}`" 1374 local l="`basename ${lic}`"
1268 1375
1269 # here is where we check for the licenses the user already 1376 # here is where we check for the licenses the user already
1270 # accepted ... if we don't find a match, we make the user accept 1377 # accepted ... if we don't find a match, we make the user accept
1271 local shopts=$-
1272 local alic 1378 local alic
1273 set -o noglob #so that bash doesn't expand "*" 1379 eshopts_push -o noglob # so that bash doesn't expand "*"
1274 for alic in ${ACCEPT_LICENSE} ; do 1380 for alic in ${ACCEPT_LICENSE} ; do
1275 if [[ ${alic} == ${l} ]]; then 1381 if [[ ${alic} == ${l} ]]; then
1276 set +o noglob; set -${shopts} #reset old shell opts 1382 eshopts_pop
1277 return 0 1383 return 0
1278 fi 1384 fi
1279 done 1385 done
1280 set +o noglob; set -$shopts #reset old shell opts 1386 eshopts_pop
1387 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1281 1388
1282 local licmsg=$(emktemp) 1389 local licmsg=$(emktemp)
1283 cat <<-EOF > ${licmsg} 1390 cat <<-EOF > ${licmsg}
1284 ********************************************************** 1391 **********************************************************
1285 The following license outlines the terms of use of this 1392 The following license outlines the terms of use of this
1532# of the lists. 1639# of the lists.
1533strip-linguas() { 1640strip-linguas() {
1534 local ls newls nols 1641 local ls newls nols
1535 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then 1642 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
1536 local op=$1; shift 1643 local op=$1; shift
1537 ls=$(find "$1" -name '*.po' -exec basename {} .po \;); shift 1644 ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
1538 local d f 1645 local d f
1539 for d in "$@" ; do 1646 for d in "$@" ; do
1540 if [[ ${op} == "-u" ]] ; then 1647 if [[ ${op} == "-u" ]] ; then
1541 newls=${ls} 1648 newls=${ls}
1542 else 1649 else
1543 newls="" 1650 newls=""
1544 fi 1651 fi
1545 for f in $(find "$d" -name '*.po' -exec basename {} .po \;) ; do 1652 for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
1546 if [[ ${op} == "-i" ]] ; then 1653 if [[ ${op} == "-i" ]] ; then
1547 hasq ${f} ${ls} && newls="${newls} ${f}" 1654 hasq ${f} ${ls} && newls="${newls} ${f}"
1548 else 1655 else
1549 hasq ${f} ${ls} || newls="${newls} ${f}" 1656 hasq ${f} ${ls} || newls="${newls} ${f}"
1550 fi 1657 fi
1563 else 1670 else
1564 nols="${nols} ${f}" 1671 nols="${nols} ${f}"
1565 fi 1672 fi
1566 done 1673 done
1567 [[ -n ${nols} ]] \ 1674 [[ -n ${nols} ]] \
1568 && ewarn "Sorry, but ${PN} does not support the LINGUAs:" ${nols} 1675 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1569 export LINGUAS=${newls:1} 1676 export LINGUAS=${newls:1}
1570} 1677}
1571 1678
1572# @FUNCTION: preserve_old_lib 1679# @FUNCTION: preserve_old_lib
1573# @USAGE: <libs to preserve> [more libs] 1680# @USAGE: <libs to preserve> [more libs]
1583 eerror "preserve_old_lib() must be called from pkg_preinst() only" 1690 eerror "preserve_old_lib() must be called from pkg_preinst() only"
1584 die "Invalid preserve_old_lib() usage" 1691 die "Invalid preserve_old_lib() usage"
1585 fi 1692 fi
1586 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]" 1693 [[ -z $1 ]] && die "Usage: preserve_old_lib <library to preserve> [more libraries to preserve]"
1587 1694
1695 # let portage worry about it
1696 has preserve-libs ${FEATURES} && return 0
1697
1588 local lib dir 1698 local lib dir
1589 for lib in "$@" ; do 1699 for lib in "$@" ; do
1590 [[ -e ${ROOT}/${lib} ]] || continue 1700 [[ -e ${ROOT}/${lib} ]] || continue
1591 dir=${lib%/*} 1701 dir=${lib%/*}
1592 dodir ${dir} || die "dodir ${dir} failed" 1702 dodir ${dir} || die "dodir ${dir} failed"
1602preserve_old_lib_notify() { 1712preserve_old_lib_notify() {
1603 if [[ ${EBUILD_PHASE} != "postinst" ]] ; then 1713 if [[ ${EBUILD_PHASE} != "postinst" ]] ; then
1604 eerror "preserve_old_lib_notify() must be called from pkg_postinst() only" 1714 eerror "preserve_old_lib_notify() must be called from pkg_postinst() only"
1605 die "Invalid preserve_old_lib_notify() usage" 1715 die "Invalid preserve_old_lib_notify() usage"
1606 fi 1716 fi
1717
1718 # let portage worry about it
1719 has preserve-libs ${FEATURES} && return 0
1607 1720
1608 local lib notice=0 1721 local lib notice=0
1609 for lib in "$@" ; do 1722 for lib in "$@" ; do
1610 [[ -e ${ROOT}/${lib} ]] || continue 1723 [[ -e ${ROOT}/${lib} ]] || continue
1611 if [[ ${notice} -eq 0 ]] ; then 1724 if [[ ${notice} -eq 0 ]] ; then
1620 ewarn " # revdep-rebuild --library ${lib##*/}" 1733 ewarn " # revdep-rebuild --library ${lib##*/}"
1621 done 1734 done
1622 if [[ ${notice} -eq 1 ]] ; then 1735 if [[ ${notice} -eq 1 ]] ; then
1623 ewarn 1736 ewarn
1624 ewarn "Once you've finished running revdep-rebuild, it should be safe to" 1737 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1625 ewarn "delete the old libraries." 1738 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1739 for lib in "$@" ; do
1740 ewarn " # rm '${lib}'"
1741 done
1626 fi 1742 fi
1627} 1743}
1628 1744
1629# @FUNCTION: built_with_use 1745# @FUNCTION: built_with_use
1630# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags> 1746# @USAGE: [--hidden] [--missing <action>] [-a|-o] <DEPEND ATOM> <List of USE flags>
1635# --missing option controls the behavior if called on a package that does 1751# --missing option controls the behavior if called on a package that does
1636# not actually support the defined USE flags (aka listed in IUSE). 1752# not actually support the defined USE flags (aka listed in IUSE).
1637# The default is to abort (call die). The -a and -o flags control 1753# The default is to abort (call die). The -a and -o flags control
1638# the requirements of the USE flags. They correspond to "and" and "or" 1754# the requirements of the USE flags. They correspond to "and" and "or"
1639# logic. So the -a flag means all listed USE flags must be enabled 1755# logic. So the -a flag means all listed USE flags must be enabled
1640# while the -o flag means at least one of the listed fIUSE flags must be 1756# while the -o flag means at least one of the listed IUSE flags must be
1641# enabled. The --hidden option is really for internal use only as it 1757# enabled. The --hidden option is really for internal use only as it
1642# means the USE flag we're checking is hidden expanded, so it won't be found 1758# means the USE flag we're checking is hidden expanded, so it won't be found
1643# in IUSE like normal USE flags. 1759# in IUSE like normal USE flags.
1644# 1760#
1645# Remember that this function isn't terribly intelligent so order of optional 1761# Remember that this function isn't terribly intelligent so order of optional
1680 die) die "Unable to determine what USE flags $PKG was built with";; 1796 die) die "Unable to determine what USE flags $PKG was built with";;
1681 esac 1797 esac
1682 fi 1798 fi
1683 1799
1684 if [[ ${hidden} == "no" ]] ; then 1800 if [[ ${hidden} == "no" ]] ; then
1685 local IUSE_BUILT=$(<${IUSEFILE}) 1801 local IUSE_BUILT=( $(<"${IUSEFILE}") )
1686 # Don't check USE_EXPAND #147237 1802 # Don't check USE_EXPAND #147237
1687 local expand 1803 local expand
1688 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do 1804 for expand in $(echo ${USE_EXPAND} | tr '[:upper:]' '[:lower:]') ; do
1689 if [[ $1 == ${expand}_* ]] ; then 1805 if [[ $1 == ${expand}_* ]] ; then
1690 expand="" 1806 expand=""
1691 break 1807 break
1692 fi 1808 fi
1693 done 1809 done
1694 if [[ -n ${expand} ]] ; then 1810 if [[ -n ${expand} ]] ; then
1695 if ! has $1 ${IUSE_BUILT} ; then 1811 if ! has $1 ${IUSE_BUILT[@]#[-+]} ; then
1696 case ${missing_action} in 1812 case ${missing_action} in
1697 true) return 0;; 1813 true) return 0;;
1698 false) return 1;; 1814 false) return 1;;
1699 die) die "$PKG does not actually support the $1 USE flag!";; 1815 die) die "$PKG does not actually support the $1 USE flag!";;
1700 esac 1816 esac
1764 ) || die 1880 ) || die
1765 else 1881 else
1766 newbin "${tmpwrapper}" "${wrapper}" || die 1882 newbin "${tmpwrapper}" "${wrapper}" || die
1767 fi 1883 fi
1768} 1884}
1885
1886# @FUNCTION: prepalldocs
1887# @USAGE:
1888# @DESCRIPTION:
1889# Compress files in /usr/share/doc which are not already
1890# compressed, excluding /usr/share/doc/${PF}/html.
1891# Uses the ecompressdir to do the compression.
1892# 2009-02-18 by betelgeuse:
1893# Commented because ecompressdir is even more internal to
1894# Portage than prepalldocs (it's not even mentioned in man 5
1895# ebuild). Please submit a better version for review to gentoo-dev
1896# if you want prepalldocs here.
1897#prepalldocs() {
1898# if [[ -n $1 ]] ; then
1899# ewarn "prepalldocs: invalid usage; takes no arguments"
1900# fi
1901
1902# cd "${D}"
1903# [[ -d usr/share/doc ]] || return 0
1904
1905# find usr/share/doc -exec gzip {} +
1906# ecompressdir --ignore /usr/share/doc/${PF}/html
1907# ecompressdir --queue /usr/share/doc
1908#}

Legend:
Removed from v.1.296  
changed lines
  Added in v.1.328

  ViewVC Help
Powered by ViewVC 1.1.20