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

Diff of /eclass/eutils.eclass

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

Revision 1.435 Revision 1.436
1# Copyright 1999-2013 Gentoo Foundation 1# Copyright 1999-2014 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.435 2014/07/04 08:01:51 ulm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.436 2014/07/11 08:21:58 ulm 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
13# home rather than having multiple ebuilds implementing the same thing. 13# home rather than having multiple ebuilds implementing the same thing.
14# 14#
15# Due to the nature of this eclass, some functions may have maintainers 15# Due to the nature of this eclass, some functions may have maintainers
16# different from the overall eclass! 16# different from the overall eclass!
17 17
18if [[ ${___ECLASS_ONCE_EUTILS} != "recur -_+^+_- spank" ]] ; then 18if [[ -z ${_EUTILS_ECLASS} ]]; then
19___ECLASS_ONCE_EUTILS="recur -_+^+_- spank" 19_EUTILS_ECLASS=1
20 20
21inherit multilib toolchain-funcs 21inherit multilib toolchain-funcs
22 22
23if has "${EAPI:-0}" 0 1 2; then 23if has "${EAPI:-0}" 0 1 2; then
24 24
112# echo "${i}" 112# echo "${i}"
113# done 113# done
114# @CODE 114# @CODE
115estack_push() { 115estack_push() {
116 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments" 116 [[ $# -eq 0 ]] && die "estack_push: incorrect # of arguments"
117 local stack_name="__ESTACK_$1__" ; shift 117 local stack_name="_ESTACK_$1_" ; shift
118 eval ${stack_name}+=\( \"\$@\" \) 118 eval ${stack_name}+=\( \"\$@\" \)
119} 119}
120 120
121# @FUNCTION: estack_pop 121# @FUNCTION: estack_pop
122# @USAGE: <stack> [variable] 122# @USAGE: <stack> [variable]
125# the popped item is stored there. If no more items are available, return 125# the popped item is stored there. If no more items are available, return
126# 1, else return 0. See estack_push for more info. 126# 1, else return 0. See estack_push for more info.
127estack_pop() { 127estack_pop() {
128 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments" 128 [[ $# -eq 0 || $# -gt 2 ]] && die "estack_pop: incorrect # of arguments"
129 129
130 # We use the fugly __estack_xxx var names to avoid collision with 130 # We use the fugly _estack_xxx var names to avoid collision with
131 # passing back the return value. If we used "local i" and the 131 # passing back the return value. If we used "local i" and the
132 # caller ran `estack_pop ... i`, we'd end up setting the local 132 # caller ran `estack_pop ... i`, we'd end up setting the local
133 # copy of "i" rather than the caller's copy. The __estack_xxx 133 # copy of "i" rather than the caller's copy. The _estack_xxx
134 # garbage is preferable to using $1/$2 everywhere as that is a 134 # garbage is preferable to using $1/$2 everywhere as that is a
135 # bit harder to read. 135 # bit harder to read.
136 local __estack_name="__ESTACK_$1__" ; shift 136 local _estack_name="_ESTACK_$1_" ; shift
137 local __estack_retvar=$1 ; shift 137 local _estack_retvar=$1 ; shift
138 eval local __estack_i=\${#${__estack_name}\[@\]} 138 eval local _estack_i=\${#${_estack_name}\[@\]}
139 # Don't warn -- let the caller interpret this as a failure 139 # Don't warn -- let the caller interpret this as a failure
140 # or as normal behavior (akin to `shift`) 140 # or as normal behavior (akin to `shift`)
141 [[ $(( --__estack_i )) -eq -1 ]] && return 1 141 [[ $(( --_estack_i )) -eq -1 ]] && return 1
142 142
143 if [[ -n ${__estack_retvar} ]] ; then 143 if [[ -n ${_estack_retvar} ]] ; then
144 eval ${__estack_retvar}=\"\${${__estack_name}\[${__estack_i}\]}\" 144 eval ${_estack_retvar}=\"\${${_estack_name}\[${_estack_i}\]}\"
145 fi 145 fi
146 eval unset ${__estack_name}\[${__estack_i}\] 146 eval unset ${_estack_name}\[${_estack_i}\]
147} 147}
148 148
149# @FUNCTION: evar_push 149# @FUNCTION: evar_push
150# @USAGE: <variable to save> [more vars to save] 150# @USAGE: <variable to save> [more vars to save]
151# @DESCRIPTION: 151# @DESCRIPTION:
172evar_push() { 172evar_push() {
173 local var val 173 local var val
174 for var ; do 174 for var ; do
175 [[ ${!var+set} == "set" ]] \ 175 [[ ${!var+set} == "set" ]] \
176 && val=${!var} \ 176 && val=${!var} \
177 || val="${___ECLASS_ONCE_EUTILS}" 177 || val="unset_76fc3c462065bb4ca959f939e6793f94"
178 estack_push evar "${var}" "${val}" 178 estack_push evar "${var}" "${val}"
179 done 179 done
180} 180}
181 181
182# @FUNCTION: evar_push_set 182# @FUNCTION: evar_push_set
209 209
210 local var val 210 local var val
211 while (( cnt-- )) ; do 211 while (( cnt-- )) ; do
212 estack_pop evar val || die "${FUNCNAME}: unbalanced push" 212 estack_pop evar val || die "${FUNCNAME}: unbalanced push"
213 estack_pop evar var || die "${FUNCNAME}: unbalanced push" 213 estack_pop evar var || die "${FUNCNAME}: unbalanced push"
214 [[ ${val} == "${___ECLASS_ONCE_EUTILS}" ]] \ 214 [[ ${val} == "unset_76fc3c462065bb4ca959f939e6793f94" ]] \
215 && unset ${var} \ 215 && unset ${var} \
216 || printf -v "${var}" '%s' "${val}" 216 || printf -v "${var}" '%s' "${val}"
217 done 217 done
218} 218}
219 219

Legend:
Removed from v.1.435  
changed lines
  Added in v.1.436

  ViewVC Help
Powered by ViewVC 1.1.20