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

Diff of /eclass/eutils.eclass

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

Revision 1.315 Revision 1.323
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.315 2009/02/21 23:28:21 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.323 2009/12/19 00:01:04 zmedico 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
66# Remove .svn directories recursiveley. Useful when a source tarball contains 66# Remove .svn directories recursiveley. Useful when a source tarball contains
67# internal Subversion directories. Defaults to $PWD. 67# internal Subversion directories. Defaults to $PWD.
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}
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}"
71} 115}
72 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
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)
343 if [ "${SINGLE_PATCH}" = "no" ] 391 if [ "${SINGLE_PATCH}" = "no" ]
344 then 392 then
345 einfo "Done with patching" 393 einfo "Done with patching"
346 fi 394 fi
347} 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
414}
348 415
349# @FUNCTION: emktemp 416# @FUNCTION: emktemp
350# @USAGE: [temp dir] 417# @USAGE: [temp dir]
351# @DESCRIPTION: 418# @DESCRIPTION:
352# Cheap replacement for when debianutils (and thus mktemp) 419# Cheap replacement for when debianutils (and thus mktemp)
392# Small wrapper for getent (Linux), 459# Small wrapper for getent (Linux),
393# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5), 460# nidump (< Mac OS X 10.5), dscl (Mac OS X 10.5),
394# and pw (FreeBSD) used in enewuser()/enewgroup() 461# and pw (FreeBSD) used in enewuser()/enewgroup()
395egetent() { 462egetent() {
396 case ${CHOST} in 463 case ${CHOST} in
464 *-darwin[678])
465 case "$2" in
466 *[!0-9]*) # Non numeric
467 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
468 ;;
469 *) # Numeric
470 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
471 ;;
472 esac
473 ;;
397 *-darwin9) 474 *-darwin*)
398 local mytype=$1 475 local mytype=$1
399 [[ "passwd" == $mytype ]] && mytype="Users" 476 [[ "passwd" == $mytype ]] && mytype="Users"
400 [[ "group" == $mytype ]] && mytype="Groups" 477 [[ "group" == $mytype ]] && mytype="Groups"
401 case "$2" in 478 case "$2" in
402 *[!0-9]*) # Non numeric 479 *[!0-9]*) # Non numeric
404 ;; 481 ;;
405 *) # Numeric 482 *) # Numeric
406 local mykey="UniqueID" 483 local mykey="UniqueID"
407 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID" 484 [[ $mytype == "Groups" ]] && mykey="PrimaryGroupID"
408 dscl . -search /$mytype $mykey $2 2>/dev/null 485 dscl . -search /$mytype $mykey $2 2>/dev/null
409 ;;
410 esac
411 ;;
412 *-darwin*)
413 case "$2" in
414 *[!0-9]*) # Non numeric
415 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
416 ;;
417 *) # Numeric
418 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
419 ;; 486 ;;
420 esac 487 esac
421 ;; 488 ;;
422 *-freebsd*|*-dragonfly*) 489 *-freebsd*|*-dragonfly*)
423 local opts action="user" 490 local opts action="user"
623 fi 690 fi
624 ;; 691 ;;
625 692
626 *) 693 *)
627 if [[ -z $@ ]] ; then 694 if [[ -z $@ ]] ; then
628 useradd ${opts} ${euser} \ 695 useradd ${opts} \
629 -c "added by portage for ${PN}" \ 696 -c "added by portage for ${PN}" \
697 ${euser} \
630 || die "enewuser failed" 698 || die "enewuser failed"
631 else 699 else
632 einfo " - Extra: $@" 700 einfo " - Extra: $@"
633 useradd ${opts} ${euser} "$@" \ 701 useradd ${opts} "$@" \
702 ${euser} \
634 || die "enewuser failed" 703 || die "enewuser failed"
635 fi 704 fi
636 ;; 705 ;;
637 esac 706 esac
638 707
920 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"
921 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop 990 #local desktop=${T}/${exec%% *:-${desktop_name}}.desktop
922 991
923 cat <<-EOF > "${desktop}" 992 cat <<-EOF > "${desktop}"
924 [Desktop Entry] 993 [Desktop Entry]
925 Version=1.0
926 Name=${name} 994 Name=${name}
927 Type=Application 995 Type=Application
928 Comment=${DESCRIPTION} 996 Comment=${DESCRIPTION}
929 Exec=${exec} 997 Exec=${exec}
930 TryExec=${exec%% *} 998 TryExec=${exec%% *}
1317 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}" 1385 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1318 local l="`basename ${lic}`" 1386 local l="`basename ${lic}`"
1319 1387
1320 # here is where we check for the licenses the user already 1388 # here is where we check for the licenses the user already
1321 # 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
1322 local shopts=$-
1323 local alic 1390 local alic
1324 set -o noglob #so that bash doesn't expand "*" 1391 eshopts_push -o noglob # so that bash doesn't expand "*"
1325 for alic in ${ACCEPT_LICENSE} ; do 1392 for alic in ${ACCEPT_LICENSE} ; do
1326 if [[ ${alic} == ${l} ]]; then 1393 if [[ ${alic} == ${l} ]]; then
1327 set +o noglob; set -${shopts} #reset old shell opts 1394 eshopts_pop
1328 return 0 1395 return 0
1329 fi 1396 fi
1330 done 1397 done
1331 set +o noglob; set -$shopts #reset old shell opts 1398 eshopts_pop
1332 1399
1333 local licmsg=$(emktemp) 1400 local licmsg=$(emktemp)
1334 cat <<-EOF > ${licmsg} 1401 cat <<-EOF > ${licmsg}
1335 ********************************************************** 1402 **********************************************************
1336 The following license outlines the terms of use of this 1403 The following license outlines the terms of use of this
1614 else 1681 else
1615 nols="${nols} ${f}" 1682 nols="${nols} ${f}"
1616 fi 1683 fi
1617 done 1684 done
1618 [[ -n ${nols} ]] \ 1685 [[ -n ${nols} ]] \
1619 && ewarn "Sorry, but ${PN} does not support the LINGUAs:" ${nols} 1686 && ewarn "Sorry, but ${PN} does not support the LINGUAS:" ${nols}
1620 export LINGUAS=${newls:1} 1687 export LINGUAS=${newls:1}
1621} 1688}
1622 1689
1623# @FUNCTION: preserve_old_lib 1690# @FUNCTION: preserve_old_lib
1624# @USAGE: <libs to preserve> [more libs] 1691# @USAGE: <libs to preserve> [more libs]

Legend:
Removed from v.1.315  
changed lines
  Added in v.1.323

  ViewVC Help
Powered by ViewVC 1.1.20