fix prepend logic on extend_path function
Currently, prepending using the 'extend path' function, it reverse the original
order of the list to be prepended, i.e for PATH="X:Y:Z" and
path_list=(
"${aarch64_none_elf_dir}/bin"
"${arm_none_eabi_dir}/bin"
"${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin"
"$coverity_path/bin"
)
is prepended as
PATH="$coverity_path/bin:${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin:\
${arm_none_eabi_dir}/bin:${aarch64_none_elf_dir}/bin:X:Y:Z"
instead of
PATH="${aarch64_none_elf_dir}/bin:${arm_none_eabi_dir}/bin:\
${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin:X:Y:Z"
Order is important, otherwise older toolchain binary versions are picked first
instead of newer ones.
Change-Id: I8a08eb05c96215c53b2b9dc6b632520a150b4676
Signed-off-by: Leonardo Sandoval <leonardo.sandoval@linaro.org>
diff --git a/utils.sh b/utils.sh
index 0f35d04..43de353 100644
--- a/utils.sh
+++ b/utils.sh
@@ -200,20 +200,23 @@
extend_path() {
local path_var="$1"
local array_var="$2"
- local tmp_path="${!path_var}"
- local tmp_array
- local item
+ local path_val="${!path_var}"
local op="${op:-prepend}"
+ local sep=':'
+ local array_val
- eval "tmp_array=\"\${$array_var[@]}\""
- for item in $tmp_array; do
- if [ "$op" = "prepend" ]; then
- tmp_path="$item${tmp_path+:}$tmp_path"
- elif [ "$op" = "append" ]; then
- tmp_path="$tmp_path${tmp_path+:}$item"
- fi
- done
- eval "$path_var=\"$tmp_path\""
+ eval "array_val=\"\${$array_var[@]}\""
+ array_val="$(echo ${array_val// /:})"
+
+ [ -z "$path_val" ] && sep=''
+
+ if [ "$op" = "prepend" ]; then
+ array_val="${array_val}${sep}${path_val}"
+ elif [ "$op" = "append" ]; then
+ array_val="${path_val}${sep}${array_val}"
+ fi
+
+ eval "$path_var=\"$array_val\""
}
# Extract files from compressed archive to target directory. Supports .zip and