1 |
commit: c68523143e0a69b2a8d409cb679ca96aa4370a9b |
2 |
Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Feb 28 09:38:55 2021 +0000 |
4 |
Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Feb 28 09:38:55 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/binutils-config.git/commit/?id=c6852314 |
7 |
|
8 |
binutils-config: add support for special 'latest' version for profile switch |
9 |
|
10 |
To ease switching to latest version add special 'latest' verison. |
11 |
Works for both "latest" and "<CTARGET>-latest" forms. |
12 |
|
13 |
Bug: https://bugs.gentoo.org/765664 |
14 |
Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org> |
15 |
|
16 |
src/binutils-config | 46 +++++++++++++++++++++++++++++++++++++++------- |
17 |
1 file changed, 39 insertions(+), 7 deletions(-) |
18 |
|
19 |
diff --git a/src/binutils-config b/src/binutils-config |
20 |
index 625c1b8..6604a14 100755 |
21 |
--- a/src/binutils-config |
22 |
+++ b/src/binutils-config |
23 |
@@ -31,6 +31,10 @@ esyslog() { :; } |
24 |
die() { eerror "${argv0}: $*"; exit 1; } |
25 |
umask 022 |
26 |
|
27 |
+# *BSD SED does not work as-is, use GNU SED. TODO: find details. |
28 |
+SED=$(type -P gsed) |
29 |
+: ${SED:=$(type -P sed)} |
30 |
+ |
31 |
usage() { |
32 |
cat << USAGE_END |
33 |
Usage: ${HILITE}binutils-config${NORMAL} ${GOOD}[options]${NORMAL} ${BRACKET}[binutils profile]${NORMAL} |
34 |
@@ -47,7 +51,8 @@ ${HILITE}General Options:${NORMAL} |
35 |
${GOOD}-L, --get-lib-path${NORMAL} Print path where libraries of the given/current |
36 |
profile are located. |
37 |
|
38 |
-Profile names are of the form: ${BRACKET}<CTARGET>-<binutils version>${NORMAL} |
39 |
+Profile names are of the form: ${BRACKET}<CTARGET>-<binutils version>${NORMAL}, ${BRACKET}latest${NORMAL}, |
40 |
+ ${BRACKET}<CTARGET>-latest${NORMAL}, ${BRACKET}latest${NORMAL}. |
41 |
For example: ${BRACKET}i686-pc-linux-gnu-2.15.92.0.2${NORMAL} |
42 |
|
43 |
For more info, please see ${HILITE}binutils-config${NORMAL}(8). |
44 |
@@ -56,6 +61,26 @@ USAGE_END |
45 |
exit ${1:-1} |
46 |
} |
47 |
|
48 |
+# Usage: version_sorted_paths <CHOST> |
49 |
+# Returns paths ordered by version from olders to newest. |
50 |
+# We use the following hack: assume the input containst digits only in places of versions |
51 |
+# Normalizer: |
52 |
+# echo "hello-world-1.2.3.444.56778" | ${SED} -e 's/[0-9]\+/0000&/g' | ${SED} -e 's/0*\([0-9]\{4\}\)/\1/g' |
53 |
+# hello-world-0001.0002.0003.0444.56778 |
54 |
+# That way we can have 9.0 < 10.0 order. |
55 |
+# TODO: explore how portable 'sort -V' is and try using that instead. |
56 |
+version_sorted_paths() { |
57 |
+ local p mangled_v |
58 |
+ for p in "$@"; do |
59 |
+ # TODO: avoid -r |
60 |
+ mangled_v=$(printf "%s" "${p}" | |
61 |
+ ${SED} -e 's/[0-9]\+/0000&/g' | |
62 |
+ ${SED} -e 's/0*\([0-9]\{4\}\)/\1/g' |
63 |
+ ) |
64 |
+ printf "%s %s\n" "${mangled_v}" "${p}" |
65 |
+ done | LANG=C sort | $SED -e 's/^.* //g' |
66 |
+} |
67 |
+ |
68 |
mv_if_diff() { |
69 |
if cmp -s "$1" "$2" ; then |
70 |
rm -f "$1" |
71 |
@@ -454,7 +479,7 @@ switch_profile) |
72 |
x=${UARG:-$(TARGET=${HOST} set_current_profile)} |
73 |
PROFILE="" |
74 |
if [[ -z $(echo ${x} | tr -d '[:digit:]') ]] ; then |
75 |
- # User gave us a # representing the profile |
76 |
+ # User gave us a profile index number from '--list-profiles' |
77 |
i=1 |
78 |
for y in "${ENV_D}"/* ; do |
79 |
[[ ${y/config-} != ${y} ]] && continue |
80 |
@@ -468,15 +493,22 @@ switch_profile) |
81 |
fi |
82 |
|
83 |
if [[ -z ${PROFILE} ]] ; then |
84 |
- # User gave us a full HOST-ver |
85 |
+ # User gave us "latest" or "<CTARGET>-latest". |
86 |
+ if [[ ${x} == latest ]]; then |
87 |
+ x=$(version_sorted_paths "${ENV_D}"/${HOST}-* | tail -1) |
88 |
+ elif [[ ${x} == *-latest ]]; then |
89 |
+ x=$(version_sorted_paths "${ENV_D}"/${x%-latest}-* | tail -1) |
90 |
+ fi |
91 |
+ |
92 |
+ # User gave us a full <CTARGET-version>, <CTARGET> or <version> |
93 |
x=${x##*/} |
94 |
if [[ -f ${ENV_D}/${x} ]] ; then |
95 |
- # Valid HOST-ver yeah! |
96 |
+ # Valid <CTARGET-version> |
97 |
PROFILE=${x} |
98 |
else |
99 |
- # Not a valid HOST-ver ... |
100 |
+ # Not a valid <CTARGET-version> |
101 |
if [[ ! -f ${ENV_D}/config-${x} ]] ; then |
102 |
- # Maybe they just gave us a ver ... |
103 |
+ # Maybe they just gave us a <version>. Infer <CTARGET>. |
104 |
if [[ -f ${ENV_D}/${HOST}-${x} ]] ; then |
105 |
x=${HOST}-${x} |
106 |
else |
107 |
@@ -484,7 +516,7 @@ switch_profile) |
108 |
fi |
109 |
PROFILE=${x} |
110 |
else |
111 |
- # Maybe they just gave us a target ... pick active profile |
112 |
+ # Maybe they just gave us a <CTARGET>. Pick active profile |
113 |
PROFILE=$(TARGET=${x} set_current_profile) |
114 |
fi |
115 |
fi |