1 |
-----BEGIN PGP SIGNED MESSAGE----- |
2 |
Hash: SHA1 |
3 |
|
4 |
The purpose of this patch is to expose a generic function, namely _use, which |
5 |
can be used to build your own use* variant if you need that. I reimplemented |
6 |
all other current use function using _use (and _if) to cut out duplicate and |
7 |
verbose code. Comments expected. I didn't test this code. |
8 |
|
9 |
Marijn |
10 |
|
11 |
diff -uw /usr/lib64/portage/bin/ebuild.sh ~/ebuild.sh |
12 |
@@ -150,40 +150,68 @@ |
13 |
return 0 |
14 |
} |
15 |
|
16 |
- -use() { |
17 |
- - useq ${1} |
18 |
+_if() { |
19 |
+ $1 && echo $2 || echo $3 |
20 |
} |
21 |
|
22 |
- -usev() { |
23 |
- - if useq ${1}; then |
24 |
- - echo "${1}" |
25 |
- - return 0 |
26 |
- - fi |
27 |
+# Fully generic conditional use flag function. |
28 |
+# $1: calling function |
29 |
+# $2: use flag to check |
30 |
+# $3: string to echo on success |
31 |
+# $4: string to echo on failure |
32 |
+_use() { |
33 |
+ if [[ $# = 1 ]]; then |
34 |
+ echo "!!! $1() called without a parameter." >&2 |
35 |
+ echo "!!! $1 <USEFLAG> [<flagname> [value]]" >&2 |
36 |
return 1 |
37 |
- -} |
38 |
+ fi |
39 |
|
40 |
- -useq() { |
41 |
- - local u=$1 |
42 |
+ local flag=$2 |
43 |
+ local string_success=$3 |
44 |
+ local string_failure=$4 |
45 |
local found=0 |
46 |
|
47 |
- - # if we got something like '!flag', then invert the return value |
48 |
- - if [[ ${u:0:1} == "!" ]] ; then |
49 |
- - u=${u:1} |
50 |
- - found=1 |
51 |
- - fi |
52 |
+ # when $flag is '!blah', invert the return value and strip the '!' from flag |
53 |
+ [[ ${flag} = !* ]] && { found=1 ; flag=${flag:1} } |
54 |
|
55 |
# Make sure we have this USE flag in IUSE |
56 |
- - if ! hasq "${u}" ${IUSE} ${E_IUSE} && ! hasq "${u}" |
57 |
${PORTAGE_ARCHLIST} selinux; then |
58 |
- - eqawarn "QA Notice: USE Flag '${u}' not in IUSE for |
59 |
${CATEGORY}/${PF}" |
60 |
+ if ! hasq "${flag}" ${IUSE} ${E_IUSE} && ! hasq "${u}" |
61 |
${PORTAGE_ARCHLIST} selinux; then |
62 |
+ eqawarn "QA Notice: USE Flag '${flag}' not in IUSE for |
63 |
${CATEGORY}/${PF}" |
64 |
fi |
65 |
|
66 |
- - if hasq ${u} ${USE} ; then |
67 |
- - return ${found} |
68 |
+ if hasq ${flag} ${USE} ; then |
69 |
+ echo ${string_success}; return ${found} |
70 |
else |
71 |
- - return $((!found)) |
72 |
+ echo ${string_failure}; return $((!found)) |
73 |
fi |
74 |
} |
75 |
|
76 |
+use() { |
77 |
+ _use ${FUNCNAME[0]} ${1} |
78 |
+} |
79 |
+ |
80 |
+useq() { |
81 |
+ _use ${FUNCNAME[0]} ${1} |
82 |
+} |
83 |
+ |
84 |
+usev() { |
85 |
+ _use ${FUNCNAME[0]} ${1} ${1} |
86 |
+} |
87 |
+ |
88 |
+use_with() { |
89 |
+ local SUFFIX="$(_if [ -z $3 ] "" "=$3")" |
90 |
+ local WORD="$(_if [ -z $2 ] $1 $2)" |
91 |
+ |
92 |
+ _use ${FUNCNAME[0]} $1 "--with-${WORD}${SUFFIX}" "--without-${WORD}" |
93 |
+} |
94 |
+ |
95 |
+use_enable() { |
96 |
+ local SUFFIX="$(_if [ -z $3 ] "" "=$3")" |
97 |
+ local WORD="$(_if [ -z $2 ] $1 $2)" |
98 |
+ |
99 |
+ _use ${FUNCNAME[0]} $1 "--enable-${WORD}${SUFFIX}" "--disable-${WORD}" |
100 |
+} |
101 |
+ |
102 |
has_version() { |
103 |
if [ "${EBUILD_PHASE}" == "depend" ]; then |
104 |
die "portageq calls (has_version calls portageq) are not |
105 |
allowed in the global scope" |
106 |
@@ -227,56 +255,6 @@ |
107 |
"${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1" |
108 |
} |
109 |
|
110 |
- -use_with() { |
111 |
- - if [ -z "$1" ]; then |
112 |
- - echo "!!! use_with() called without a parameter." >&2 |
113 |
- - echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2 |
114 |
- - return 1 |
115 |
- - fi |
116 |
- - |
117 |
- - local UW_SUFFIX="" |
118 |
- - if [ ! -z "${3}" ]; then |
119 |
- - UW_SUFFIX="=${3}" |
120 |
- - fi |
121 |
- - |
122 |
- - local UWORD="$2" |
123 |
- - if [ -z "${UWORD}" ]; then |
124 |
- - UWORD="$1" |
125 |
- - fi |
126 |
- - |
127 |
- - if useq $1; then |
128 |
- - echo "--with-${UWORD}${UW_SUFFIX}" |
129 |
- - else |
130 |
- - echo "--without-${UWORD}" |
131 |
- - fi |
132 |
- - return 0 |
133 |
- -} |
134 |
- - |
135 |
- -use_enable() { |
136 |
- - if [ -z "$1" ]; then |
137 |
- - echo "!!! use_enable() called without a parameter." >&2 |
138 |
- - echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2 |
139 |
- - return 1 |
140 |
- - fi |
141 |
- - |
142 |
- - local UE_SUFFIX="" |
143 |
- - if [ ! -z "${3}" ]; then |
144 |
- - UE_SUFFIX="=${3}" |
145 |
- - fi |
146 |
- - |
147 |
- - local UWORD="$2" |
148 |
- - if [ -z "${UWORD}" ]; then |
149 |
- - UWORD="$1" |
150 |
- - fi |
151 |
- - |
152 |
- - if useq $1; then |
153 |
- - echo "--enable-${UWORD}${UE_SUFFIX}" |
154 |
- - else |
155 |
- - echo "--disable-${UWORD}" |
156 |
- - fi |
157 |
- - return 0 |
158 |
- -} |
159 |
- - |
160 |
|
161 |
- -- |
162 |
Marijn Schouten (hkBst), Gentoo Lisp project |
163 |
<http://www.gentoo.org/proj/en/lisp/>, #gentoo-lisp on FreeNode |
164 |
-----BEGIN PGP SIGNATURE----- |
165 |
Version: GnuPG v2.0.7 (GNU/Linux) |
166 |
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org |
167 |
|
168 |
iD8DBQFHJ3jUp/VmCx0OL2wRAnduAJ9BkYDzf7ROLUeVVOQ4m5oVZ3TNoQCeIlQ9 |
169 |
9XN6WDbj4CtojnRX9Zc9ny8= |
170 |
=4pj9 |
171 |
-----END PGP SIGNATURE----- |
172 |
-- |
173 |
gentoo-portage-dev@g.o mailing list |