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

Diff of /eclass/eutils.eclass

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

Revision 1.304 Revision 1.322
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.304 2008/09/20 18:45:26 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.322 2009/12/11 20:31:34 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
68esvn_clean() { 68esvn_clean() {
69 [[ -z $* ]] && set -- . 69 [[ -z $* ]] && set -- .
70 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf 70 find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf
71} 71}
72 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
73# Default directory where patches are located 117# Default directory where patches are located
74EPATCH_SOURCE="${WORKDIR}/patch" 118EPATCH_SOURCE="${WORKDIR}/patch"
75# Default extension for patches 119# Default extension for patches
76EPATCH_SUFFIX="patch.bz2" 120EPATCH_SUFFIX="patch.bz2"
77# Default options for patch 121# Default options for patch
78# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571 122# Set -g0 to keep RCS, ClearCase, Perforce and SCCS happy. Bug #24571
79# Set --no-backup-if-mismatch so we don't leave '.orig' files behind. 123# Set --no-backup-if-mismatch so we don't leave '.orig' files behind.
80# Set -E to automatically remove empty files. 124# Set -E to automatically remove empty files.
81EPATCH_OPTS="-g0 -E --no-backup-if-mismatch" 125EPATCH_OPTS="-g0 -E --no-backup-if-mismatch"
82# List of patches not to apply. Not this is only file names, 126# List of patches not to apply. Note this is only file names,
83# and not the full path .. 127# and not the full path ..
84EPATCH_EXCLUDE="" 128EPATCH_EXCLUDE=""
85# Change the printed message for a single patch. 129# Change the printed message for a single patch.
86EPATCH_SINGLE_MSG="" 130EPATCH_SINGLE_MSG=""
87# Change the printed message for multiple patches. 131# Change the printed message for multiple patches.
105# bug they should be left as is to ensure an ebuild can rely on 149# bug they should be left as is to ensure an ebuild can rely on
106# them for. 150# them for.
107# 151#
108# Patches are applied in current directory. 152# Patches are applied in current directory.
109# 153#
110# Bulk Patches should preferibly have the form of: 154# Bulk Patches should preferably have the form of:
111# 155#
112# ??_${ARCH}_foo.${EPATCH_SUFFIX} 156# ??_${ARCH}_foo.${EPATCH_SUFFIX}
113# 157#
114# For example: 158# For example:
115# 159#
183 227
184 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}" 228 local EPATCH_SOURCE="${EPATCH_SOURCE}/*.${EPATCH_SUFFIX}"
185 fi 229 fi
186 230
187 case ${EPATCH_SUFFIX##*\.} in 231 case ${EPATCH_SUFFIX##*\.} in
232 xz)
233 PIPE_CMD="xz -dc"
234 PATCH_SUFFIX="xz"
235 ;;
188 lzma) 236 lzma)
189 PIPE_CMD="lzma -dc" 237 PIPE_CMD="lzma -dc"
190 PATCH_SUFFIX="lzma" 238 PATCH_SUFFIX="lzma"
191 ;; 239 ;;
192 bz2) 240 bz2)
262 fi 310 fi
263 else 311 else
264 PATCH_TARGET="${x}" 312 PATCH_TARGET="${x}"
265 fi 313 fi
266 314
315 # Check for absolute paths in patches. If sandbox is disabled,
316 # people could (accidently) patch files in the root filesystem.
317 # Or trigger other unpleasantries #237667. So disallow -p0 on
318 # such patches.
319 local abs_paths=$(egrep -n '^[-+]{3} /' "${PATCH_TARGET}" | awk '$2 != "/dev/null" { print }')
320 if [[ -n ${abs_paths} ]] ; then
321 count=1
322 echo "NOTE: skipping -p0 due to absolute paths in patch:" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
323 echo "${abs_paths}" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
324 fi
325
267 # Allow for prefix to differ ... im lazy, so shoot me :/ 326 # Allow for prefix to differ ... im lazy, so shoot me :/
268 while [ "${count}" -lt 5 ] 327 while [ "${count}" -lt 5 ]
269 do 328 do
270 # Generate some useful debug info ... 329 # Generate some useful debug info ...
271 _epatch_draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 330 _epatch_draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
331 done 390 done
332 if [ "${SINGLE_PATCH}" = "no" ] 391 if [ "${SINGLE_PATCH}" = "no" ]
333 then 392 then
334 einfo "Done with patching" 393 einfo "Done with patching"
335 fi 394 fi
395}
396epatch_user() {
397 [[ $# -ne 0 ]] && die "epatch_user takes no options"
398
399 # don't clobber any EPATCH vars that the parent might want
400 local EPATCH_SOURCE check base=${PORTAGE_CONFIGROOT}/etc/portage/patches
401 for check in {${CATEGORY}/${PF},${CATEGORY}/${P},${CATEGORY}/${PN}}; do
402 EPATCH_SOURCE=${base}/${CTARGET}/${check}
403 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${CHOST}/${check}
404 [[ -r ${EPATCH_SOURCE} ]] || EPATCH_SOURCE=${base}/${check}
405 if [[ -d ${EPATCH_SOURCE} ]] ; then
406 EPATCH_SOURCE=${EPATCH_SOURCE} \
407 EPATCH_SUFFIX="patch" \
408 EPATCH_FORCE="yes" \
409 EPATCH_MULTI_MSG="Applying user patches from ${EPATCH_SOURCE} ..." \
410 epatch
411 break
412 fi
413 done
336} 414}
337 415
338# @FUNCTION: emktemp 416# @FUNCTION: emktemp
339# @USAGE: [temp dir] 417# @USAGE: [temp dir]
340# @DESCRIPTION: 418# @DESCRIPTION:
376# base-system@gentoo.org (Linux) 454# base-system@gentoo.org (Linux)
377# Joe Jezak <josejx@gmail.com> (OS X) 455# Joe Jezak <josejx@gmail.com> (OS X)
378# usata@gentoo.org (OS X) 456# usata@gentoo.org (OS X)
379# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD) 457# Aaron Walker <ka0ttic@gentoo.org> (FreeBSD)
380# @DESCRIPTION: 458# @DESCRIPTION:
381# Small wrapper for getent (Linux), nidump (Mac OS X), 459# Small wrapper for getent (Linux),
460# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5),
382# and pw (FreeBSD) used in enewuser()/enewgroup() 461# and pw (FreeBSD) used in enewuser()/enewgroup()
383egetent() { 462egetent() {
384 case ${CHOST} in 463 case ${CHOST} in
385 *-darwin*) 464 *-darwin[678])
386 case "$2" in 465 case "$2" in
387 *[!0-9]*) # Non numeric 466 *[!0-9]*) # Non numeric
388 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" 467 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
389 ;; 468 ;;
390 *) # Numeric 469 *) # Numeric
391 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 470 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
471 ;;
472 esac
473 ;;
474 *-darwin*)
475 local mytype=$1
476 [[ "passwd" == $mytype ]] && mytype="Users"
477 [[ "group" == $mytype ]] && mytype="Groups"
478 case "$2" in
479 *[!0-9]*) # Non numeric
480 dscl . -read /$mytype/$2 2>/dev/null |grep RecordName
481 ;;
482 *) # Numeric
483 local mykey="UniqueID"
484 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID"
485 dscl . -search /$mytype $mykey $2 2>/dev/null
392 ;; 486 ;;
393 esac 487 esac
394 ;; 488 ;;
395 *-freebsd*|*-dragonfly*) 489 *-freebsd*|*-dragonfly*)
396 local opts action="user" 490 local opts action="user"
596 fi 690 fi
597 ;; 691 ;;
598 692
599 *) 693 *)
600 if [[ -z $@ ]] ; then 694 if [[ -z $@ ]] ; then
601 useradd ${opts} ${euser} \ 695 useradd ${opts} \
602 -c "added by portage for ${PN}" \ 696 -c "added by portage for ${PN}" \
697 ${euser} \
603 || die "enewuser failed" 698 || die "enewuser failed"
604 else 699 else
605 einfo " - Extra: $@" 700 einfo " - Extra: $@"
606 useradd ${opts} ${euser} "$@" \ 701 useradd ${opts} "$@" \
702 ${euser} \
607 || die "enewuser failed" 703 || die "enewuser failed"
608 fi 704 fi
609 ;; 705 ;;
610 esac 706 esac
611 707
893 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop" 989 local desktop="${T}/$(echo ${exec} | sed 's:[[:space:]/:]:_:g')-${desktop_name}.desktop"
894 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 990 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
895 991
896 cat <<-EOF > "${desktop}" 992 cat <<-EOF > "${desktop}"
897 [Desktop Entry] 993 [Desktop Entry]
898 Version=1.0
899 Name=${name} 994 Name=${name}
900 Type=Application 995 Type=Application
901 Comment=${DESCRIPTION} 996 Comment=${DESCRIPTION}
902 Exec=${exec} 997 Exec=${exec}
903 TryExec=${exec%% *} 998 TryExec=${exec%% *}
942 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo." 1037 einfo "Passing desktop entry validity check. Install dev-util/desktop-file-utils, if you want to help to improve Gentoo."
943 fi 1038 fi
944} 1039}
945 1040
946# @FUNCTION: make_session_desktop 1041# @FUNCTION: make_session_desktop
947# @USAGE: <title> <command> 1042# @USAGE: <title> <command> [command args...]
948# @DESCRIPTION: 1043# @DESCRIPTION:
949# Make a GDM/KDM Session file. The title is the file to execute to start the 1044# Make a GDM/KDM Session file. The title is the file to execute to start the
950# Window Manager. The command is the name of the Window Manager. 1045# Window Manager. The command is the name of the Window Manager.
1046#
1047# You can set the name of the file via the ${wm} variable.
951make_session_desktop() { 1048make_session_desktop() {
952 [[ -z $1 ]] && eerror "make_session_desktop: You must specify the title" && return 1 1049 [[ -z $1 ]] && eerror "$0: You must specify the title" && return 1
953 [[ -z $2 ]] && eerror "make_session_desktop: You must specify the command" && return 1 1050 [[ -z $2 ]] && eerror "$0: You must specify the command" && return 1
954 1051
955 local title=$1 1052 local title=$1
956 local command=$2 1053 local command=$2
957 local desktop=${T}/${wm}.desktop 1054 local desktop=${T}/${wm:-${PN}}.desktop
1055 shift 2
958 1056
959 cat <<-EOF > "${desktop}" 1057 cat <<-EOF > "${desktop}"
960 [Desktop Entry] 1058 [Desktop Entry]
961 Name=${title} 1059 Name=${title}
962 Comment=This session logs you into ${title} 1060 Comment=This session logs you into ${title}
963 Exec=${command} 1061 Exec=${command} $*
964 TryExec=${command} 1062 TryExec=${command}
965 Type=Application 1063 Type=XSession
966 EOF 1064 EOF
967 1065
968 ( 1066 (
969 # wrap the env here so that the 'insinto' call 1067 # wrap the env here so that the 'insinto' call
970 # doesn't corrupt the env of the caller 1068 # doesn't corrupt the env of the caller
1287 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}" 1385 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1288 local l="`basename ${lic}`" 1386 local l="`basename ${lic}`"
1289 1387
1290 # here is where we check for the licenses the user already 1388 # here is where we check for the licenses the user already
1291 # accepted ... if we don't find a match, we make the user accept 1389 # accepted ... if we don't find a match, we make the user accept
1292 local shopts=$-
1293 local alic 1390 local alic
1294 set -o noglob #so that bash doesn't expand "*" 1391 eshopts_push -o noglob # so that bash doesn't expand "*"
1295 for alic in ${ACCEPT_LICENSE} ; do 1392 for alic in ${ACCEPT_LICENSE} ; do
1296 if [[ ${alic} == ${l} ]]; then 1393 if [[ ${alic} == ${l} ]]; then
1297 set +o noglob; set -${shopts} #reset old shell opts 1394 eshopts_pop
1298 return 0 1395 return 0
1299 fi 1396 fi
1300 done 1397 done
1301 set +o noglob; set -$shopts #reset old shell opts 1398 eshopts_pop
1302 1399
1303 local licmsg=$(emktemp) 1400 local licmsg=$(emktemp)
1304 cat <<-EOF > ${licmsg} 1401 cat <<-EOF > ${licmsg}
1305 ********************************************************** 1402 **********************************************************
1306 The following license outlines the terms of use of this 1403 The following license outlines the terms of use of this
1553# of the lists. 1650# of the lists.
1554strip-linguas() { 1651strip-linguas() {
1555 local ls newls nols 1652 local ls newls nols
1556 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then 1653 if [[ $1 == "-i" ]] || [[ $1 == "-u" ]] ; then
1557 local op=$1; shift 1654 local op=$1; shift
1558 ls=$(find "$1" -name '*.po' -exec basename {} .po \;); shift 1655 ls=$(find "$1" -name '*.po' -exec basename {} .po ';'); shift
1559 local d f 1656 local d f
1560 for d in "$@" ; do 1657 for d in "$@" ; do
1561 if [[ ${op} == "-u" ]] ; then 1658 if [[ ${op} == "-u" ]] ; then
1562 newls=${ls} 1659 newls=${ls}
1563 else 1660 else
1564 newls="" 1661 newls=""
1565 fi 1662 fi
1566 for f in $(find "$d" -name '*.po' -exec basename {} .po \;) ; do 1663 for f in $(find "$d" -name '*.po' -exec basename {} .po ';') ; do
1567 if [[ ${op} == "-i" ]] ; then 1664 if [[ ${op} == "-i" ]] ; then
1568 hasq ${f} ${ls} && newls="${newls} ${f}" 1665 hasq ${f} ${ls} && newls="${newls} ${f}"
1569 else 1666 else
1570 hasq ${f} ${ls} || newls="${newls} ${f}" 1667 hasq ${f} ${ls} || newls="${newls} ${f}"
1571 fi 1668 fi
1584 else 1681 else
1585 nols="${nols} ${f}" 1682 nols="${nols} ${f}"
1586 fi 1683 fi
1587 done 1684 done
1588 [[ -n ${nols} ]] \ 1685 [[ -n ${nols} ]] \
1589 && ewarn "Sorry, but ${PN} does not support the LINGUAs:" ${nols} 1686 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1590 export LINGUAS=${newls:1} 1687 export LINGUAS=${newls:1}
1591} 1688}
1592 1689
1593# @FUNCTION: preserve_old_lib 1690# @FUNCTION: preserve_old_lib
1594# @USAGE: <libs to preserve> [more libs] 1691# @USAGE: <libs to preserve> [more libs]
1794 ) || die 1891 ) || die
1795 else 1892 else
1796 newbin "${tmpwrapper}" "${wrapper}" || die 1893 newbin "${tmpwrapper}" "${wrapper}" || die
1797 fi 1894 fi
1798} 1895}
1896
1897# @FUNCTION: prepalldocs
1898# @USAGE:
1899# @DESCRIPTION:
1900# Compress files in /usr/share/doc which are not already
1901# compressed, excluding /usr/share/doc/${PF}/html.
1902# Uses the ecompressdir to do the compression.
1903# 2009-02-18 by betelgeuse:
1904# Commented because ecompressdir is even more internal to
1905# Portage than prepalldocs (it's not even mentioned in man 5
1906# ebuild). Please submit a better version for review to gentoo-dev
1907# if you want prepalldocs here.
1908#prepalldocs() {
1909# if [[ -n $1 ]] ; then
1910# ewarn "prepalldocs: invalid usage; takes no arguments"
1911# fi
1912
1913# cd "${D}"
1914# [[ -d usr/share/doc ]] || return 0
1915
1916# find usr/share/doc -exec gzip {} +
1917# ecompressdir --ignore /usr/share/doc/${PF}/html
1918# ecompressdir --queue /usr/share/doc
1919#}

Legend:
Removed from v.1.304  
changed lines
  Added in v.1.322

  ViewVC Help
Powered by ViewVC 1.1.20