commit:     e5fdfd991ec21885d4141440da97189f29dfa7b9
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Apr 14 05:37:33 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Apr 14 05:38:47 2016 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e5fdfd99

toolchain.eclass: automatically select latest gcc-config profile when unmerging 
active version #529608

If the user is unmerging the current version, try and automatically
switch to a better version.  We blindly pick the latest one available
for the target in question since there's not really a better metric
to figure out which one the user actually would want.

 eclass/toolchain.eclass | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index 03e550d..b875e19 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -2050,26 +2050,36 @@ do_gcc_config() {
                return 0
        fi
 
-       local current_gcc_config="" current_specs="" use_specs=""
+       local current_gcc_config target
 
        current_gcc_config=$(env -i ROOT="${ROOT}" gcc-config -c ${CTARGET} 
2>/dev/null)
        if [[ -n ${current_gcc_config} ]] ; then
+               local current_specs use_specs
                # figure out which specs-specific config is active
                current_specs=$(gcc-config -S ${current_gcc_config} | awk 
'{print $3}')
                [[ -n ${current_specs} ]] && use_specs=-${current_specs}
-       fi
-       if [[ -n ${use_specs} ]] && \
-          [[ ! -e 
${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
-       then
-               ewarn "The currently selected specs-specific gcc config,"
-               ewarn "${current_specs}, doesn't exist anymore. This is usually"
-               ewarn "due to enabling/disabling hardened or switching to a 
version"
-               ewarn "of gcc that doesnt create multiple specs files. The 
default"
-               ewarn "config will be used, and the previous preference 
forgotten."
-               use_specs=""
+
+               if [[ -n ${use_specs} ]] && \
+                  [[ ! -e 
${ROOT}/etc/env.d/gcc/${CTARGET}-${GCC_CONFIG_VER}${use_specs} ]]
+               then
+                       ewarn "The currently selected specs-specific gcc 
config,"
+                       ewarn "${current_specs}, doesn't exist anymore. This is 
usually"
+                       ewarn "due to enabling/disabling hardened or switching 
to a version"
+                       ewarn "of gcc that doesnt create multiple specs files. 
The default"
+                       ewarn "config will be used, and the previous preference 
forgotten."
+                       use_specs=""
+               fi
+
+               target="${CTARGET}-${GCC_CONFIG_VER}${use_specs}"
+       else
+               # The curent target is invalid.  Attempt to switch to a valid 
one.
+               # Blindly pick the latest version.  #529608
+               # TODO: Should update gcc-config to accept `-l ${CTARGET}` 
rather than
+               # doing a partial grep like this.
+               target=$(gcc-config -l 2>/dev/null | grep " ${CTARGET}-[0-9]" | 
tail -1 | awk '{print $2}')
        fi
 
-       gcc-config ${CTARGET}-${GCC_CONFIG_VER}${use_specs}
+       gcc-config "${target}"
 }
 
 should_we_gcc_config() {

Reply via email to