diff options
author | Mike Frysinger <vapier@gentoo.org> | 2010-02-15 02:10:39 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2010-02-15 02:10:39 +0000 |
commit | 2fdb468d1d6b2370782fe0b8f9984cf0753799ee (patch) | |
tree | e0354f0dda0dadf7b9dee0b992f3bafce37c439a /eclass/eutils.eclass | |
parent | Set SUPPORT_PYTHON_ABIS. Disable installation for Python 3 (bug #304505). (diff) | |
download | historical-2fdb468d1d6b2370782fe0b8f9984cf0753799ee.tar.gz historical-2fdb468d1d6b2370782fe0b8f9984cf0753799ee.tar.bz2 historical-2fdb468d1d6b2370782fe0b8f9984cf0753799ee.zip |
eshopts_{push,pop}: add support for the extended options available only via `shopt`
Diffstat (limited to 'eclass/eutils.eclass')
-rw-r--r-- | eclass/eutils.eclass | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass index 0f7cd3f5b91d..941fae17255b 100644 --- a/eclass/eutils.eclass +++ b/eclass/eutils.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.329 2010/01/28 22:00:12 betelgeuse Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.330 2010/02/15 02:10:39 vapier Exp $ # @ECLASS: eutils.eclass # @MAINTAINER: @@ -75,13 +75,16 @@ esvn_clean() { } # @FUNCTION: eshopts_push -# @USAGE: [options to `set`] +# @USAGE: [options to `set` or `shopt`] # @DESCRIPTION: # Often times code will want to enable a shell option to change code behavior. # Since changing shell options can easily break other pieces of code (which # assume the default state), eshopts_push is used to (1) push the current shell # options onto a stack and (2) pass the specified arguments to set. # +# If the first argument is '-s' or '-u', we assume you want to call `shopt` +# rather than `set` as there are some options only available via that. +# # A common example is to disable shell globbing so that special meaning/care # may be used with variables/arguments to custom functions. That would be: # @CODE @@ -98,9 +101,15 @@ eshopts_push() { # have to assume __ESHOPTS_SAVE__ isn't screwed with # as a `declare -a` here will reset its value local i=${#__ESHOPTS_SAVE__[@]} - __ESHOPTS_SAVE__[$i]=$- - [[ $# -eq 0 ]] && return 0 - set "$@" || die "eshopts_push: bad options to set: $*" + if [[ $1 == -[su] ]] ; then + __ESHOPTS_SAVE__[$i]=$(shopt -p) + [[ $# -eq 0 ]] && return 0 + shopt "$@" || die "eshopts_push: bad options to shopt: $*" + else + __ESHOPTS_SAVE__[$i]=$- + [[ $# -eq 0 ]] && return 0 + set "$@" || die "eshopts_push: bad options to set: $*" + fi } # @FUNCTION: eshopts_pop @@ -114,8 +123,12 @@ eshopts_pop() { [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" local s=${__ESHOPTS_SAVE__[$i]} unset __ESHOPTS_SAVE__[$i] - set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" - set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" + if [[ ${s} == "shopt -"* ]] ; then + eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" + else + set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" + set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" + fi } # @VARIABLE: EPATCH_SOURCE |