public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gcc-config:master commit in: /, tests/multi-configs/, tests/multi-configs/etc/env.d/gcc/
@ 2020-01-12 16:05 Sergei Trofimovich
  0 siblings, 0 replies; only message in thread
From: Sergei Trofimovich @ 2020-01-12 16:05 UTC (permalink / raw
  To: gentoo-commits

commit:     bc80e12ab133a00ece4059df40d672889fcf6bf0
Author:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
AuthorDate: Sun Jan 12 15:51:47 2020 +0000
Commit:     Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
CommitDate: Sun Jan 12 16:05:39 2020 +0000
URL:        https://gitweb.gentoo.org/proj/gcc-config.git/commit/?id=bc80e12a

gcc-config: add basic version sorting support

Before the change gcc version orderig was relying on bash sorting
in flob matches, like:
    cat /etc/env.d/gcc/${CHOST}-* | fgrep LDPATH | tail -n 1

This stopped working with gcc-10, which lexicographically goes
before gcc-9.

The workaround for now is to normalizeversions to fixed-width
and order them lexicographically:
    gcc-0009
    gcc-0010

Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>

 gcc-config                                         | 26 +++++++++++++++++++---
 .../etc/env.d/gcc/x86_64-pc-linux-gnu-10.0.0       |  9 ++++++++
 .../env.d/gcc/x86_64-pc-linux-gnu-11.0.0-pre9999   |  8 +++++++
 tests/multi-configs/test.list.exp                  |  2 ++
 4 files changed, 42 insertions(+), 3 deletions(-)

diff --git a/gcc-config b/gcc-config
index dd11c71..1ab646b 100755
--- a/gcc-config
+++ b/gcc-config
@@ -68,6 +68,25 @@ usage() {
 }
 [[ $# -lt 1 ]] && usage 1
 
+# Usage: version_sorted_paths <CHOST>
+# Returns paths ordered by version from olders to newest.
+# We use the following hack: assume the input containst digits only in places of versions
+# Normalizer:
+#    echo "hello-world-1.2.3.444.56778" | ${SED} -e 's/[0-9]\+/0000&/g' | ${SED} -e 's/0*\([0-9]\{4\}\)/\1/g'
+#    hello-world-0001.0002.0003.0444.56778
+# That way we can have 9.0 < 10.0 roder.
+version_sorted_paths() {
+	local p mangled_v
+	for p in "$@"; do
+		# TODO: avoid -r
+		mangled_v=$(printf "%s" "${p}" |
+			${SED} -e 's/[0-9]\+/0000&/g' |
+			${SED} -e 's/0*\([0-9]\{4\}\)/\1/g'
+		)
+		printf "%s %s\n" "${mangled_v}" "${p}"
+	done | LANG=C sort | $SED -e 's/^.* //g'
+}
+
 # Usage: source_var <var> <file> [default value]
 source_var() {
 	unset $1
@@ -319,7 +338,7 @@ handle_split_usr() {
 	# We use the same ordering logic as mentioned in the MY_LDPATH setup.
 	# We get the libs from the latest version available.
 	local LDPATH
-	eval $(grep -h '^LDPATH=' "${GCC_ENV_D}"/${CHOST}-* | tail -1)
+	eval $(grep -h '^LDPATH=' $(version_sorted_paths "${GCC_ENV_D}"/${CHOST}-*) | tail -1)
 	LDPATH=${LDPATH%%:*}
 
 	# If GCC directory is not in separate mountpoint than /lib,
@@ -538,6 +557,7 @@ prefix_copy_gcc_libs() {
 		rmdir "${sourcedir}"
 	}
 
+	# We don't rely on iteration order here.
 	local GCC_PROFILES=$(LC_ALL="C" ls ${GCC_ENV_D}/${CHOST}-*)
 
 	local targetdirs= GCC_PATH= LDPATH=
@@ -655,7 +675,7 @@ switch_profile() {
 		local MY_LDPATH
 		MY_LDPATH=$(${SED} -n \
 			-e '/^LDPATH=/{s|LDPATH=||;s|"||g;s|:|\n|g;p}' \
-			"${GCC_ENV_D}"/${CHOST}-* | tac
+			$(version_sorted_paths "${GCC_ENV_D}"/${CHOST}-*) | tac
 		)
 
 		# Pass all by default
@@ -797,7 +817,7 @@ list_profiles() {
 	source_var CURRENT "${GCC_ENV_D}"/config-${CTARGET}
 	CURRENT_NATIVE=${CURRENT}
 	local target=
-	for x in "${GCC_ENV_D}"/* ; do
+	for x in $(version_sorted_paths "${GCC_ENV_D}"/*) ; do
 		[[ -f ${x} ]] || continue
 		[[ ${x} == */config* ]] && continue
 

diff --git a/tests/multi-configs/etc/env.d/gcc/x86_64-pc-linux-gnu-10.0.0 b/tests/multi-configs/etc/env.d/gcc/x86_64-pc-linux-gnu-10.0.0
new file mode 100644
index 0000000..c863019
--- /dev/null
+++ b/tests/multi-configs/etc/env.d/gcc/x86_64-pc-linux-gnu-10.0.0
@@ -0,0 +1,9 @@
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/10.0.0"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/10.0.0:/usr/lib/gcc/x86_64-pc-linux-gnu/10.0.0/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/10.0.0/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/10.0.0/info"
+STDCXX_INCDIR="g++-v10"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib"
+

diff --git a/tests/multi-configs/etc/env.d/gcc/x86_64-pc-linux-gnu-11.0.0-pre9999 b/tests/multi-configs/etc/env.d/gcc/x86_64-pc-linux-gnu-11.0.0-pre9999
new file mode 100644
index 0000000..1654050
--- /dev/null
+++ b/tests/multi-configs/etc/env.d/gcc/x86_64-pc-linux-gnu-11.0.0-pre9999
@@ -0,0 +1,8 @@
+GCC_PATH="/usr/x86_64-pc-linux-gnu/gcc-bin/11.0.0-pre9999"
+LDPATH="/usr/lib/gcc/x86_64-pc-linux-gnu/11.0.0-pre9999:/usr/lib/gcc/x86_64-pc-linux-gnu/11.0.0-pre9999/32"
+MANPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/11.0.0-pre9999/man"
+INFOPATH="/usr/share/gcc-data/x86_64-pc-linux-gnu/11.0.0-pre9999/info"
+STDCXX_INCDIR="g++-v10"
+CTARGET="x86_64-pc-linux-gnu"
+GCC_SPECS=""
+MULTIOSDIRS="../lib64:../lib"

diff --git a/tests/multi-configs/test.list.exp b/tests/multi-configs/test.list.exp
index 18640e1..5e8db88 100644
--- a/tests/multi-configs/test.list.exp
+++ b/tests/multi-configs/test.list.exp
@@ -8,3 +8,5 @@ Using gcc-config info in @ROOT@/
  [4] x86_64-pc-linux-gnu-4.6.0
  [5] x86_64-pc-linux-gnu-4.6.1
  [6] x86_64-pc-linux-gnu-4.6.2 *
+ [7] x86_64-pc-linux-gnu-10.0.0
+ [8] x86_64-pc-linux-gnu-11.0.0-pre9999


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-12 16:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-12 16:05 [gentoo-commits] proj/gcc-config:master commit in: /, tests/multi-configs/, tests/multi-configs/etc/env.d/gcc/ Sergei Trofimovich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox