Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH] flag-o-matic.eclass: Replace unnecessary evals
Date: Wed, 22 Feb 2017 19:27:51
Message-Id: 20170222192616.26624-1-mgorny@gentoo.org
1 Replace the evals used to export variables with plain export calls. Bash
2 expands variable references for exported variable name anyway, rendering
3 the eval completely unnecessary.
4
5 Replace the single eval used for indirect variable reference with the
6 ${!...} substitution which serves that exact purpose in bash.
7 ---
8 eclass/flag-o-matic.eclass | 11 +++++------
9 1 file changed, 5 insertions(+), 6 deletions(-)
10
11 diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
12 index 5b8a054079d2..10e637d51d52 100644
13 --- a/eclass/flag-o-matic.eclass
14 +++ b/eclass/flag-o-matic.eclass
15 @@ -117,7 +117,7 @@ _filter-var() {
16 done
17 new+=( "${f}" )
18 done
19 - eval export ${var}=\""${new[*]}"\"
20 + export ${var}="${new[*]}"
21 }
22
23 # @FUNCTION: filter-flags
24 @@ -271,7 +271,7 @@ replace-flags() {
25 [[ ${f} == ${1} ]] && f=${2}
26 new+=( "${f}" )
27 done
28 - eval export ${var}=\""${new[*]}"\"
29 + export ${var}="${new[*]}"
30 done
31
32 return 0
33 @@ -296,9 +296,8 @@ replace-cpu-flags() {
34 }
35
36 _is_flagq() {
37 - local x var
38 - eval var=\""\${$1[*]}"\"
39 - for x in ${var} ; do
40 + local x var="$1[*]"
41 + for x in ${!var} ; do
42 [[ ${x} == $2 ]] && return 0
43 done
44 return 1
45 @@ -412,7 +411,7 @@ strip-flags() {
46 if [[ ${!var} != "${new[*]}" ]] ; then
47 einfo "strip-flags: ${var}: changed '${!var}' to '${new[*]}'"
48 fi
49 - eval export ${var}=\""${new[*]}"\"
50 + export ${var}="${new[*]}"
51 done
52
53 set +f # re-enable pathname expansion
54 --
55 2.11.1