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

Diff of /eclass/eutils.eclass

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

Revision 1.321 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.321 2009/10/18 07:52:23 grobian 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
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
1341 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}" 1385 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1342 local l="`basename ${lic}`" 1386 local l="`basename ${lic}`"
1343 1387
1344 # here is where we check for the licenses the user already 1388 # here is where we check for the licenses the user already
1345 # 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
1346 local shopts=$-
1347 local alic 1390 local alic
1348 set -o noglob #so that bash doesn't expand "*" 1391 eshopts_push -o noglob # so that bash doesn't expand "*"
1349 for alic in ${ACCEPT_LICENSE} ; do 1392 for alic in ${ACCEPT_LICENSE} ; do
1350 if [[ ${alic} == ${l} ]]; then 1393 if [[ ${alic} == ${l} ]]; then
1351 set +o noglob; set -${shopts} #reset old shell opts 1394 eshopts_pop
1352 return 0 1395 return 0
1353 fi 1396 fi
1354 done 1397 done
1355 set +o noglob; set -$shopts #reset old shell opts 1398 eshopts_pop
1356 1399
1357 local licmsg=$(emktemp) 1400 local licmsg=$(emktemp)
1358 cat <<-EOF > ${licmsg} 1401 cat <<-EOF > ${licmsg}
1359 ********************************************************** 1402 **********************************************************
1360 The following license outlines the terms of use of this 1403 The following license outlines the terms of use of this

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

  ViewVC Help
Powered by ViewVC 1.1.20