build_library: Fix setting gcc profile with latest gcc-config

In order to fix some bash-completion issues, the output of "gcc-config
-l" has changed slightly - it received one more leading space in the
output.

Old output:

 [1] aarch64-cros-linux-gnu-15 *

New output:

  [1] aarch64-cros-linux-gnu-15 *

This has added another field from cut's point of view, as it was
splitting the line into fields by single spaces, which means that
instead of getting "aarch64-cros-linux-gnu-15" we were getting
"[1]". This has caused grep to match nothing, setting the error status
in PIPESTATUS and finally a function failure.

Instead of fiddling with leading empty fields, just strip the leading
spaces, dammit.

Signed-off-by: Krzesimir Nowak <knowak@microsoft.com>
This commit is contained in:
Krzesimir Nowak 2026-01-22 11:00:18 +01:00
parent 7d1c684a0f
commit 59ef07e24f

View File

@ -490,10 +490,14 @@ binutils_set_latest_profile() {
# The extra flag can be blank, hardenednopie, and so on. See gcc-config -l
# Usage: gcc_get_latest_profile chost [extra]
gcc_get_latest_profile() {
local prefix="${1}-"
local suffix="${2+-$2}"
local prefix=${1}
local suffix=${2+-${2}}
local status
gcc-config -l | cut -d' ' -f3 | grep "^${prefix}[0-9\\.]*${suffix}$" | tail -n1
gcc-config --list-profiles --nocolor | \
sed -e 's/^\s*//' | \
cut -d' ' -f2 | \
grep "^${prefix}-[0-9\\.]*${suffix}$" | \
tail -n1
# return 1 if anything in the above pipe failed
for status in ${PIPESTATUS[@]}; do