build(make): update arm/clang to latest versions

Update our testing framework to utilise Arm Compiler v6.18. On jenkins
and local runs, the LLVM toolchain is downloaded and its path prepended
to the PATH variable so that the host machine can find the latest tool
along with with its binutils.

Change-Id: Ie1c984ba01e3a8e0666e1e1f35b9303293b032cb
Signed-off-by: Harrison Mutai <harrison.mutai@arm.com>
diff --git a/group/tf-l1-build-clang/fvp-default-clang-bfd:nil b/group/tf-l1-build-clang/fvp-default-clang-bfd:nil
index d52947d..2883213 100644
--- a/group/tf-l1-build-clang/fvp-default-clang-bfd:nil
+++ b/group/tf-l1-build-clang/fvp-default-clang-bfd:nil
@@ -1,6 +1,10 @@
+#!/usr/bin/env bash
 #
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+pre_tf_build() {
+    setup_llvm_toolchain
+}
diff --git a/group/tf-l1-build-clang/fvp-default-clang:nil b/group/tf-l1-build-clang/fvp-default-clang:nil
index aab4796..0428f17 100644
--- a/group/tf-l1-build-clang/fvp-default-clang:nil
+++ b/group/tf-l1-build-clang/fvp-default-clang:nil
@@ -1,6 +1,10 @@
+#!/usr/bin/env bash
 #
-# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
+# Copyright (c) 2019-2022 Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+pre_tf_build() {
+    setup_llvm_toolchain
+}
diff --git a/group/tf-l1-build-clang/juno-default-clang:nil b/group/tf-l1-build-clang/juno-default-clang:nil
index aab4796..ad12cc1 100644
--- a/group/tf-l1-build-clang/juno-default-clang:nil
+++ b/group/tf-l1-build-clang/juno-default-clang:nil
@@ -1,6 +1,11 @@
+#!/usr/bin/env bash
 #
-# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
+# Copyright (c) 2019-2022 Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+
+pre_tf_build() {
+    setup_llvm_toolchain
+}
diff --git a/group/tf-l2-boot-tests-misc/fvp-default-clang,fvp-default:fvp-tftf-fip.tftf-aemv8a b/group/tf-l2-boot-tests-misc/fvp-default-clang,fvp-default:fvp-tftf-fip.tftf-aemv8a
index 0a342ff..2883213 100644
--- a/group/tf-l2-boot-tests-misc/fvp-default-clang,fvp-default:fvp-tftf-fip.tftf-aemv8a
+++ b/group/tf-l2-boot-tests-misc/fvp-default-clang,fvp-default:fvp-tftf-fip.tftf-aemv8a
@@ -1,5 +1,10 @@
+#!/usr/bin/env bash
 #
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
+
+pre_tf_build() {
+    setup_llvm_toolchain
+}
diff --git a/group/tf-l2-boot-tests-misc/fvp-default-clang-bfd,fvp-default:fvp-tftf-fip.tftf-aemv8a b/group/tf-l2-boot-tests-misc/fvp-default-clang-bfd,fvp-default:fvp-tftf-fip.tftf-aemv8a
index 0a342ff..2883213 100644
--- a/group/tf-l2-boot-tests-misc/fvp-default-clang-bfd,fvp-default:fvp-tftf-fip.tftf-aemv8a
+++ b/group/tf-l2-boot-tests-misc/fvp-default-clang-bfd,fvp-default:fvp-tftf-fip.tftf-aemv8a
@@ -1,5 +1,10 @@
+#!/usr/bin/env bash
 #
-# Copyright (c) 2020, Arm Limited. All rights reserved.
+# Copyright (c) 2020-2022, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
+
+pre_tf_build() {
+    setup_llvm_toolchain
+}
diff --git a/group/tftf-l2-juno/juno-default-clang,juno-default:juno-tftf b/group/tftf-l2-juno/juno-default-clang,juno-default:juno-tftf
index aab4796..d427d57 100644
--- a/group/tftf-l2-juno/juno-default-clang,juno-default:juno-tftf
+++ b/group/tftf-l2-juno/juno-default-clang,juno-default:juno-tftf
@@ -1,6 +1,10 @@
+#!/usr/bin/env bash
 #
 # Copyright (c) 2019-2020 Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
 
+pre_tf_build() {
+    setup_llvm_toolchain
+}
diff --git a/script/build_package.sh b/script/build_package.sh
index 80b58b6..d13d24b 100755
--- a/script/build_package.sh
+++ b/script/build_package.sh
@@ -502,6 +502,13 @@
 		set +a
 	fi
 
+	if is_arm_jenkins_env || upon "$local_ci"; then
+		path_list=(
+			"$llvm_dir/bin"
+		)
+		extend_path "PATH" "path_list"
+	fi
+
 	cd "$tf_root"
 
 	# Always distclean when running on Jenkins. Skip distclean when running
diff --git a/script/tf-coverity/common-def.sh b/script/tf-coverity/common-def.sh
index 5d2cf13..82f391e 100644
--- a/script/tf-coverity/common-def.sh
+++ b/script/tf-coverity/common-def.sh
@@ -65,10 +65,11 @@
 
 # Provide correct armclang toolchain based on environment
 set_armclang_toolchain() {
-    local armclang_path="/home/buildslave/tools/armclang-6.8/bin"
+    # FIXME: ARMCompiler 6.18 is symlinked to 6.17 until it is available on OpenCI.
+    local armclang_path="/home/buildslave/tools/armclang-6.17/bin"
 
     # if under arm enviroment, overide cross-compilation path
-    is_arm_jenkins_env || upon "$local_ci" && armclang_path="/arm/warehouse/Distributions/FA/ARMCompiler/6.8/25/standalone-linux-x86_64-rel/bin"
+    is_arm_jenkins_env || upon "$local_ci" && armclang_path="/arm/warehouse/Distributions/FA/ARMCompiler/6.18/19/standalone-linux-x86_64-rel/bin"
 
     echo "${armclang_path}/armclang"
 }
diff --git a/tf_config/fvp-default-armclang b/tf_config/fvp-default-armclang
index 5132bb0..161899e 100644
--- a/tf_config/fvp-default-armclang
+++ b/tf_config/fvp-default-armclang
@@ -1,3 +1,3 @@
-CC=/arm/warehouse/Distributions/FA/ARMCompiler/6.8/25/standalone-linux-x86_64-rel/bin/armclang
+CC=/arm/warehouse/Distributions/FA/ARMCompiler/6.18/19/standalone-linux-x86_64-rel/bin/armclang
 CROSS_COMPILE=aarch64-none-elf-
 PLAT=fvp
diff --git a/tf_config/fvp-default-clang b/tf_config/fvp-default-clang
index 7e39698..d7b3583 100644
--- a/tf_config/fvp-default-clang
+++ b/tf_config/fvp-default-clang
@@ -1,3 +1,2 @@
 CC=clang
-CROSS_COMPILE=aarch64-none-elf-
 PLAT=fvp
diff --git a/tf_config/fvp-default-clang-bfd b/tf_config/fvp-default-clang-bfd
index b460c11..1110b56 100644
--- a/tf_config/fvp-default-clang-bfd
+++ b/tf_config/fvp-default-clang-bfd
@@ -1,4 +1,3 @@
 CC=clang
-CROSS_COMPILE=aarch64-none-elf-
 LD=aarch64-none-elf-ld.bfd
 PLAT=fvp
diff --git a/tf_config/juno-default-armclang b/tf_config/juno-default-armclang
index bb229ea..61f1622 100644
--- a/tf_config/juno-default-armclang
+++ b/tf_config/juno-default-armclang
@@ -1,3 +1,3 @@
-CC=/arm/warehouse/Distributions/FA/ARMCompiler/6.8/25/standalone-linux-x86_64-rel/bin/armclang
+CC=/arm/warehouse/Distributions/FA/ARMCompiler/6.18/19/standalone-linux-x86_64-rel/bin/armclang
 CROSS_COMPILE=aarch64-none-elf-
 PLAT=juno
diff --git a/tf_config/juno-default-clang b/tf_config/juno-default-clang
index b5f67ff..c257b0b 100644
--- a/tf_config/juno-default-clang
+++ b/tf_config/juno-default-clang
@@ -1,3 +1,2 @@
 CC=clang
-CROSS_COMPILE=aarch64-none-elf-
 PLAT=juno
diff --git a/utils.sh b/utils.sh
index 4514fc4..82dd059 100644
--- a/utils.sh
+++ b/utils.sh
@@ -229,8 +229,22 @@
 	eval "$path_var=\"$array_val\""
 }
 
-# Extract files from compressed archive to target directory. Supports .zip and
-# .tar.gz format
+# Fetch and extract the latest supported version of the LLVM toolchain from
+# a compressed archive file to a target directory, if it is required.
+setup_llvm_toolchain() {
+	link="${1:-$llvm_archive}"
+	archive="${2:-"$workspace/llvm.tar.xz"}"
+	target_dir="${3:-$llvm_dir}"
+
+	if is_arm_jenkins_env || upon "$local_ci"; then
+		url="$link" saveas="$archive" fetch_file
+		mkdir -p $target_dir
+		extract_tarball $archive $target_dir --strip-components=1 -k
+	fi
+}
+
+# Extract files from compressed archive to target directory. Supports .zip,
+# .tar.gz, and tar.xf format
 extract_tarball() {
 	local archive="$1"
 	local target_dir="$2"
@@ -244,6 +258,9 @@
 		application/zip)
 				unzip -q $extra_params $archive
 				;;
+		application/x-xz)
+				tar -x  $extra_params -f $archive
+				;;
 	esac
 	popd "$target_dir"
 }
@@ -345,6 +362,12 @@
 # mbedTLS archive public hosting available at github.com
 mbedtls_archive="${mbedtls_archive:-https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v${mbedtls_version}.tar.gz}"
 
+# FIXME: workaround to allow all on-prem host machines to access the latest LLVM
+# LLVM archive public hosting available at github.com
+llvm_version="${llvm_version:-14.0.0}"
+llvm_dir="$workspace/llvm-$llvm_version"
+llvm_archive="${llvm_archive:-https://github.com/llvm/llvm-project/releases/download/llvmorg-$llvm_version/clang+llvm-$llvm_version-x86_64-linux-gnu-ubuntu-18.04.tar.xz}"
+
 coverity_path="${coverity_path:-${nfs_volume}/tools/coverity/static-analysis/2020.12}"
 coverity_default_checkers=(
 "--all"
@@ -370,6 +393,7 @@
 path_list=(
 		"${aarch64_none_elf_dir}/bin"
 		"${arm_none_eabi_dir}/bin"
+		"${llvm_dir}/bin"
 		"${nfs_volume}/pdsw/tools/gcc-arm-none-eabi-5_4-2016q3/bin"
 		"$coverity_path/bin"
 )