1 |
A few ebuilds use bash '[[ ${foo} < ${bar} ]]' comparison to compare |
2 |
numbers and package versions. |
3 |
|
4 |
In bash '<' is for lexicographical string comparison (see man bash |
5 |
'CONDITIONAL EXPRESSIONS' section). It's almost never what |
6 |
you want: |
7 |
|
8 |
$ [[ 1.2.3 < 1.2.3 ]] && echo yes || echo no |
9 |
no # ok |
10 |
$ [[ 1.2.9 < 1.2.3 ]] && echo yes || echo no |
11 |
no # ok |
12 |
$ [[ 1.2.9 < 1.2.10 ]] && echo yes || echo no |
13 |
no # whoops |
14 |
|
15 |
A very crude grep shows many affected packages: |
16 |
$ git grep -E '\[\[.*[<>]\s*[0-9]+.*\]\]' | cat |
17 |
app-misc/unfoo/unfoo-1.0.8.ebuild: elif [[ ${REPLACING_VERSIONS} < 1.0.7 ]]; then |
18 |
dev-db/libzdb/libzdb-3.1-r1.ebuild: if [[ $(gcc-version) < 4.1 ]];then |
19 |
dev-db/libzdb/libzdb-3.1.ebuild: if [[ $(gcc-version) < 4.1 ]];then |
20 |
eclass/kernel-2.eclass: if [[ ${K_SYMLINK} > 0 ]]; then |
21 |
eclass/kernel-2.eclass: if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.24 ]] ; then |
22 |
eclass/kernel-2.eclass: if [[ ${KV_MAJOR} -ge 3 || ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} > 2.6.28 ]]; then |
23 |
eclass/kernel-2.eclass: if [[ -n ${KV_MINOR} && ${KV_MAJOR}.${KV_MINOR}.${KV_PATCH} < 2.6.27 ]] ; then |
24 |
... <list goes on and on> ... |
25 |
|
26 |
Some of them are benign like '[[ ${foo} > 0 ]]': I think it's still worth fixing them. |
27 |
Some of them are worse like [[ $(gcc-version) < 4.1 ]]: gcc-version=10 will break here. |
28 |
|
29 |
I've created a tracker and dumped a few suspects there: |
30 |
https://bugs.gentoo.org/705240 |
31 |
|
32 |
I'm sure there are more creative ways to hide version (or just number) |
33 |
compare behind lexicographical string comparison. If you have an idea how |
34 |
grep those out please do report and fix them :) |
35 |
|
36 |
Thank you! |
37 |
|
38 |
-- |
39 |
|
40 |
Sergei |