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

Diff of /eclass/eutils.eclass

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

Revision 1.349 Revision 1.361
1# Copyright 1999-2009 Gentoo Foundation 1# Copyright 1999-2011 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.349 2010/08/19 21:32:26 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.361 2011/08/08 02:01:40 vapier 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
200# If you do not specify any options, then epatch will default to the directory 200# If you do not specify any options, then epatch will default to the directory
201# specified by EPATCH_SOURCE. 201# specified by EPATCH_SOURCE.
202# 202#
203# When processing directories, epatch will apply all patches that match: 203# When processing directories, epatch will apply all patches that match:
204# @CODE 204# @CODE
205# ${EPATCH_FORCE} == "yes" 205# if ${EPATCH_FORCE} != "yes"
206# ??_${ARCH}_foo.${EPATCH_SUFFIX} 206# ??_${ARCH}_foo.${EPATCH_SUFFIX}
207# else 207# else
208# *.${EPATCH_SUFFIX} 208# *.${EPATCH_SUFFIX}
209# @CODE 209# @CODE
210# The leading ?? are typically numbers used to force consistent patch ordering. 210# The leading ?? are typically numbers used to force consistent patch ordering.
249 local EPATCH_SUFFIX=$1 249 local EPATCH_SUFFIX=$1
250 250
251 elif [[ -d $1 ]] ; then 251 elif [[ -d $1 ]] ; then
252 # Some people like to make dirs of patches w/out suffixes (vim) 252 # Some people like to make dirs of patches w/out suffixes (vim)
253 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"} 253 set -- "$1"/*${EPATCH_SUFFIX:+."${EPATCH_SUFFIX}"}
254
255 elif [[ -f ${EPATCH_SOURCE}/$1 ]] ; then
256 # Re-use EPATCH_SOURCE as a search dir
257 epatch "${EPATCH_SOURCE}/$1"
258 return $?
254 259
255 else 260 else
256 # sanity check ... if it isn't a dir or file, wtf man ? 261 # sanity check ... if it isn't a dir or file, wtf man ?
257 [[ $# -ne 0 ]] && EPATCH_SOURCE=$1 262 [[ $# -ne 0 ]] && EPATCH_SOURCE=$1
258 echo 263 echo
289 # ???_arch_foo.patch 294 # ???_arch_foo.patch
290 # Else, skip this input altogether 295 # Else, skip this input altogether
291 local a=${patchname#*_} # strip the ???_ 296 local a=${patchname#*_} # strip the ???_
292 a=${a%%_*} # strip the _foo.patch 297 a=${a%%_*} # strip the _foo.patch
293 if ! [[ ${SINGLE_PATCH} == "yes" || \ 298 if ! [[ ${SINGLE_PATCH} == "yes" || \
294 ${EPATCH_FORCE} == "yes" || \ 299 ${EPATCH_FORCE} == "yes" || \
295 ${a} == all || \ 300 ${a} == all || \
296 ${a} == ${ARCH} ]] 301 ${a} == ${ARCH} ]]
297 then 302 then
298 continue 303 continue
299 fi 304 fi
300 305
301 # Let people filter things dynamically 306 # Let people filter things dynamically
358 local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }') 363 local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }')
359 if [[ -n ${abs_paths} ]] ; then 364 if [[ -n ${abs_paths} ]] ; then
360 count=1 365 count=1
361 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}" 366 printf "NOTE: skipping -p0 due to absolute paths in patch:\n%s\n" "${abs_paths}" >> "${STDERR_TARGET}"
362 fi 367 fi
368 # Similar reason, but with relative paths.
369 local rel_paths=$(egrep -n '^[-+]{3} [^ ]*[.][.]/' "${PATCH_TARGET}")
370 if [[ -n ${rel_paths} ]] ; then
371 eqawarn "QA Notice: Your patch uses relative paths '../'."
372 eqawarn " In the future this will cause a failure."
373 eqawarn "${rel_paths}"
374 fi
363 375
364 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/ 376 # Dynamically detect the correct -p# ... i'm lazy, so shoot me :/
365 while [[ ${count} -lt 5 ]] ; do 377 while [[ ${count} -lt 5 ]] ; do
366 # Generate some useful debug info ... 378 # Generate some useful debug info ...
367 ( 379 (
368 _epatch_draw_line "***** ${patchname} *****" 380 _epatch_draw_line "***** ${patchname} *****"
369 echo 381 echo
370 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'" 382 echo "PATCH COMMAND: patch -p${count} ${EPATCH_OPTS} < '${PATCH_TARGET}'"
371 echo 383 echo
372 _epatch_draw_line "***** ${patchname} *****" 384 _epatch_draw_line "***** ${patchname} *****"
385 patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}" 2>&1
386 ret=$?
387 echo
388 echo "patch program exited with status ${ret}"
389 exit ${ret}
373 ) >> "${STDERR_TARGET}" 390 ) >> "${STDERR_TARGET}"
374 391
375 if (patch -p${count} ${EPATCH_OPTS} --dry-run -f < "${PATCH_TARGET}") >> "${STDERR_TARGET}" 2>&1 ; then 392 if [ $? -eq 0 ] ; then
376 ( 393 (
377 _epatch_draw_line "***** ${patchname} *****" 394 _epatch_draw_line "***** ${patchname} *****"
378 echo 395 echo
379 echo "ACTUALLY APPLYING ${patchname} ..." 396 echo "ACTUALLY APPLYING ${patchname} ..."
380 echo 397 echo
381 _epatch_draw_line "***** ${patchname} *****" 398 _epatch_draw_line "***** ${patchname} *****"
382 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1 399 patch -p${count} ${EPATCH_OPTS} < "${PATCH_TARGET}" 2>&1
400 ret=$?
401 echo
402 echo "patch program exited with status ${ret}"
403 exit ${ret}
383 ) >> "${STDERR_TARGET}" 404 ) >> "${STDERR_TARGET}"
384 405
385 if [ $? -ne 0 ] ; then 406 if [ $? -ne 0 ] ; then
386 echo 407 echo
387 eerror "A dry-run of patch command succeeded, but actually" 408 eerror "A dry-run of patch command succeeded, but actually"
418 done 439 done
419 440
420 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching" 441 [[ ${SINGLE_PATCH} == "no" ]] && einfo "Done with patching"
421 : # everything worked 442 : # everything worked
422} 443}
444
445# @FUNCTION: epatch_user
446# @USAGE:
447# @DESCRIPTION:
448# Applies user-provided patches to the source tree. The patches are
449# taken from /etc/portage/patches/<CATEGORY>/<PF|P|PN>/, where the first
450# of these three directories to exist will be the one to use, ignoring
451# any more general directories which might exist as well.
452#
453# User patches are intended for quick testing of patches without ebuild
454# modifications, as well as for permanent customizations a user might
455# desire. Obviously, there can be no official support for arbitrarily
456# patched ebuilds. So whenever a build log in a bug report mentions that
457# user patches were applied, the user should be asked to reproduce the
458# problem without these.
459#
460# Not all ebuilds do call this function, so placing patches in the
461# stated directory might or might not work, depending on the package and
462# the eclasses it inherits and uses. It is safe to call the function
463# repeatedly, so it is always possible to add a call at the ebuild
464# level. The first call is the time when the patches will be
465# applied.
466#
467# Ideally, this function should be called after gentoo-specific patches
468# have been applied, so that their code can be modified as well, but
469# before calls to e.g. eautoreconf, as the user patches might affect
470# autotool input files as well.
423epatch_user() { 471epatch_user() {
424 [[ $# -ne 0 ]] && die "epatch_user takes no options" 472 [[ $# -ne 0 ]] && die "epatch_user takes no options"
473
474 # Allow multiple calls to this function; ignore all but the first
475 local applied="${T}/epach_user.applied"
476 [[ -e ${applied} ]] && return 2
425 477
426 # don't clobber any EPATCH vars that the parent might want 478 # don't clobber any EPATCH vars that the parent might want
427 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches 479 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
428 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do 480 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
429 EPATCH_SOURCE=${base}/${CTARGET}/${check} 481 EPATCH_SOURCE=${base}/${CTARGET}/${check}
433 EPATCH_SOURCE=${EPATCH_SOURCE} \ 485 EPATCH_SOURCE=${EPATCH_SOURCE} \
434 EPATCH_SUFFIX="patch" \ 486 EPATCH_SUFFIX="patch" \
435 EPATCH_FORCE="yes" \ 487 EPATCH_FORCE="yes" \
436 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \ 488 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
437 epatch 489 epatch
490 echo "${EPATCH_SOURCE}" > "${applied}"
438 return 0 491 return 0
439 fi 492 fi
440 done 493 done
494 echo "none" > "${applied}"
441 return 1 495 return 1
442} 496}
443 497
444# @FUNCTION: emktemp 498# @FUNCTION: emktemp
445# @USAGE: [temp dir] 499# @USAGE: [temp dir]
490egetent() { 544egetent() {
491 case ${CHOST} in 545 case ${CHOST} in
492 *-darwin[678]) 546 *-darwin[678])
493 case "$2" in 547 case "$2" in
494 *[!0-9]*) # Non numeric 548 *[!0-9]*) # Non numeric
495 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" 549 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2\$/) {print \$0;exit;} }"
496 ;; 550 ;;
497 *) # Numeric 551 *) # Numeric
498 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 552 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
499 ;; 553 ;;
500 esac 554 esac
1384 dd) exe="dd ibs=${skip} skip=1 if='${src}'";; 1438 dd) exe="dd ibs=${skip} skip=1 if='${src}'";;
1385 *) die "makeself cant handle exe '${exe}'" 1439 *) die "makeself cant handle exe '${exe}'"
1386 esac 1440 esac
1387 1441
1388 # lets grab the first few bytes of the file to figure out what kind of archive it is 1442 # lets grab the first few bytes of the file to figure out what kind of archive it is
1389 local tmpfile=$(emktemp) 1443 local filetype tmpfile=$(emktemp)
1390 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" 1444 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1391 local filetype=$(file -b "${tmpfile}") 1445 filetype=$(file -b "${tmpfile}") || die
1392 case ${filetype} in 1446 case ${filetype} in
1393 *tar\ archive*) 1447 *tar\ archive*)
1394 eval ${exe} | tar --no-same-owner -xf - 1448 eval ${exe} | tar --no-same-owner -xf -
1395 ;; 1449 ;;
1396 bzip2*) 1450 bzip2*)
1706 else 1760 else
1707 newls="" 1761 newls=""
1708 fi 1762 fi
1709 for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do 1763 for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
1710 if [[ ${op} == "-i" ]] ; then 1764 if [[ ${op} == "-i" ]] ; then
1711 hasq ${f} ${ls} && newls="${newls} ${f}" 1765 has ${f} ${ls} && newls="${newls} ${f}"
1712 else 1766 else
1713 hasq ${f} ${ls} || newls="${newls} ${f}" 1767 has ${f} ${ls} || newls="${newls} ${f}"
1714 fi 1768 fi
1715 done 1769 done
1716 ls=${newls} 1770 ls=${newls}
1717 done 1771 done
1718 else 1772 else
1720 fi 1774 fi
1721 1775
1722 nols="" 1776 nols=""
1723 newls="" 1777 newls=""
1724 for f in ${LINGUAS} ; do 1778 for f in ${LINGUAS} ; do
1725 if hasq ${f} ${ls} ; then 1779 if has ${f} ${ls} ; then
1726 newls="${newls} ${f}" 1780 newls="${newls} ${f}"
1727 else 1781 else
1728 nols="${nols} ${f}" 1782 nols="${nols} ${f}"
1729 fi 1783 fi
1730 done 1784 done
1785 ewarn "the libraries are not being removed. You need to run revdep-rebuild" 1839 ewarn "the libraries are not being removed. You need to run revdep-rebuild"
1786 ewarn "in order to remove these old dependencies. If you do not have this" 1840 ewarn "in order to remove these old dependencies. If you do not have this"
1787 ewarn "helper program, simply emerge the 'gentoolkit' package." 1841 ewarn "helper program, simply emerge the 'gentoolkit' package."
1788 ewarn 1842 ewarn
1789 fi 1843 fi
1844 # temp hack for #348634 #357225
1845 [[ ${PN} == "mpfr" ]] && lib=${lib##*/}
1790 ewarn " # revdep-rebuild --library ${lib##*/}" 1846 ewarn " # revdep-rebuild --library '${lib}'"
1791 done 1847 done
1792 if [[ ${notice} -eq 1 ]] ; then 1848 if [[ ${notice} -eq 1 ]] ; then
1793 ewarn 1849 ewarn
1794 ewarn "Once you've finished running revdep-rebuild, it should be safe to" 1850 ewarn "Once you've finished running revdep-rebuild, it should be safe to"
1795 ewarn "delete the old libraries. Here is a copy & paste for the lazy:" 1851 ewarn "delete the old libraries. Here is a copy & paste for the lazy:"
1941 else 1997 else
1942 newbin "${tmpwrapper}" "${wrapper}" || die 1998 newbin "${tmpwrapper}" "${wrapper}" || die
1943 fi 1999 fi
1944} 2000}
1945 2001
1946# @FUNCTION: prepalldocs 2002# @FUNCTION: path_exists
1947# @USAGE: 2003# @USAGE: [-a|-o] <paths>
1948# @DESCRIPTION: 2004# @DESCRIPTION:
1949# Compress files in /usr/share/doc which are not already 2005# Check if the specified paths exist. Works for all types of paths
1950# compressed, excluding /usr/share/doc/${PF}/html. 2006# (files/dirs/etc...). The -a and -o flags control the requirements
1951# Uses the ecompressdir to do the compression. 2007# of the paths. They correspond to "and" and "or" logic. So the -a
1952# 2009-02-18 by betelgeuse: 2008# flag means all the paths must exist while the -o flag means at least
1953# Commented because ecompressdir is even more internal to 2009# one of the paths must exist. The default behavior is "and". If no
1954# Portage than prepalldocs (it's not even mentioned in man 5 2010# paths are specified, then the return value is "false".
1955# ebuild). Please submit a better version for review to gentoo-dev 2011path_exists() {
1956# if you want prepalldocs here. 2012 local opt=$1
1957#prepalldocs() { 2013 [[ ${opt} == -[ao] ]] && shift || opt="-a"
1958# if [[ -n $1 ]] ; then
1959# ewarn "prepalldocs: invalid usage; takes no arguments"
1960# fi
1961 2014
1962# cd "${D}" 2015 # no paths -> return false
1963# [[ -d usr/share/doc ]] || return 0 2016 # same behavior as: [[ -e "" ]]
2017 [[ $# -eq 0 ]] && return 1
1964 2018
1965# find usr/share/doc -exec gzip {} + 2019 local p r=0
1966# ecompressdir --ignore /usr/share/doc/${PF}/html 2020 for p in "$@" ; do
1967# ecompressdir --queue /usr/share/doc 2021 [[ -e ${p} ]]
1968#} 2022 : $(( r += $? ))
2023 done
2024
2025 case ${opt} in
2026 -a) return $(( r != 0 )) ;;
2027 -o) return $(( r == $# )) ;;
2028 esac
2029}

Legend:
Removed from v.1.349  
changed lines
  Added in v.1.361

  ViewVC Help
Powered by ViewVC 1.1.20