| 1 | # Copyright 1999-2009 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.329 2010/01/28 22:00:12 betelgeuse Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.330 2010/02/15 02:10:39 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 |
| … | |
… | |
| 73 | [[ -z $* ]] && set -- . |
73 | [[ -z $* ]] && set -- . |
| 74 | find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf |
74 | find "$@" -type d -name '.svn' -prune -print0 | xargs -0 rm -rf |
| 75 | } |
75 | } |
| 76 | |
76 | |
| 77 | # @FUNCTION: eshopts_push |
77 | # @FUNCTION: eshopts_push |
| 78 | # @USAGE: [options to `set`] |
78 | # @USAGE: [options to `set` or `shopt`] |
| 79 | # @DESCRIPTION: |
79 | # @DESCRIPTION: |
| 80 | # Often times code will want to enable a shell option to change code behavior. |
80 | # Often times code will want to enable a shell option to change code behavior. |
| 81 | # Since changing shell options can easily break other pieces of code (which |
81 | # Since changing shell options can easily break other pieces of code (which |
| 82 | # assume the default state), eshopts_push is used to (1) push the current shell |
82 | # assume the default state), eshopts_push is used to (1) push the current shell |
| 83 | # options onto a stack and (2) pass the specified arguments to set. |
83 | # options onto a stack and (2) pass the specified arguments to set. |
|
|
84 | # |
|
|
85 | # If the first argument is '-s' or '-u', we assume you want to call `shopt` |
|
|
86 | # rather than `set` as there are some options only available via that. |
| 84 | # |
87 | # |
| 85 | # A common example is to disable shell globbing so that special meaning/care |
88 | # A common example is to disable shell globbing so that special meaning/care |
| 86 | # may be used with variables/arguments to custom functions. That would be: |
89 | # may be used with variables/arguments to custom functions. That would be: |
| 87 | # @CODE |
90 | # @CODE |
| 88 | # eshopts_push -o noglob |
91 | # eshopts_push -o noglob |
| … | |
… | |
| 96 | # @CODE |
99 | # @CODE |
| 97 | eshopts_push() { |
100 | eshopts_push() { |
| 98 | # have to assume __ESHOPTS_SAVE__ isn't screwed with |
101 | # have to assume __ESHOPTS_SAVE__ isn't screwed with |
| 99 | # as a `declare -a` here will reset its value |
102 | # as a `declare -a` here will reset its value |
| 100 | local i=${#__ESHOPTS_SAVE__[@]} |
103 | local i=${#__ESHOPTS_SAVE__[@]} |
|
|
104 | if [[ $1 == -[su] ]] ; then |
| 101 | __ESHOPTS_SAVE__[$i]=$- |
105 | __ESHOPTS_SAVE__[$i]=$(shopt -p) |
| 102 | [[ $# -eq 0 ]] && return 0 |
106 | [[ $# -eq 0 ]] && return 0 |
|
|
107 | shopt "$@" || die "eshopts_push: bad options to shopt: $*" |
|
|
108 | else |
|
|
109 | __ESHOPTS_SAVE__[$i]=$- |
|
|
110 | [[ $# -eq 0 ]] && return 0 |
| 103 | set "$@" || die "eshopts_push: bad options to set: $*" |
111 | set "$@" || die "eshopts_push: bad options to set: $*" |
|
|
112 | fi |
| 104 | } |
113 | } |
| 105 | |
114 | |
| 106 | # @FUNCTION: eshopts_pop |
115 | # @FUNCTION: eshopts_pop |
| 107 | # @USAGE: |
116 | # @USAGE: |
| 108 | # @DESCRIPTION: |
117 | # @DESCRIPTION: |
| … | |
… | |
| 112 | [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" |
121 | [[ $# -ne 0 ]] && die "eshopts_pop takes no arguments" |
| 113 | local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) |
122 | local i=$(( ${#__ESHOPTS_SAVE__[@]} - 1 )) |
| 114 | [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" |
123 | [[ ${i} -eq -1 ]] && die "eshopts_{push,pop}: unbalanced pair" |
| 115 | local s=${__ESHOPTS_SAVE__[$i]} |
124 | local s=${__ESHOPTS_SAVE__[$i]} |
| 116 | unset __ESHOPTS_SAVE__[$i] |
125 | unset __ESHOPTS_SAVE__[$i] |
|
|
126 | if [[ ${s} == "shopt -"* ]] ; then |
|
|
127 | eval "${s}" || die "eshopts_pop: sanity: invalid shopt options: ${s}" |
|
|
128 | else |
| 117 | set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" |
129 | set +$- || die "eshopts_pop: sanity: invalid shell settings: $-" |
| 118 | set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" |
130 | set -${s} || die "eshopts_pop: sanity: unable to restore saved shell settings: ${s}" |
|
|
131 | fi |
| 119 | } |
132 | } |
| 120 | |
133 | |
| 121 | # @VARIABLE: EPATCH_SOURCE |
134 | # @VARIABLE: EPATCH_SOURCE |
| 122 | # @DESCRIPTION: |
135 | # @DESCRIPTION: |
| 123 | # Default directory to search for patches. |
136 | # Default directory to search for patches. |