Sync scripts in 'script' directory with internal CI

Sync scripts with platform-ci commit:
539c151d0cd99a5e6ca6c0e6966f6d8579fe864e

Signed-off-by: Zelalem <zelalem.aweke@arm.com>
Change-Id: I455770dea2e3974f652de317b21e53cfc0b9199e
diff --git a/script/scan_build_wrapper.sh b/script/scan_build_wrapper.sh
new file mode 100644
index 0000000..5b52d5f
--- /dev/null
+++ b/script/scan_build_wrapper.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Copyright (c) 2019, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+
+scan_build_wrapper(){
+
+	local make_command="$(echo $@)"
+	local cross_compile="$(grep -oP "(?<=CROSS_COMPILE=)[a-z\-0-9]+" <<< $make_command)"
+	local build_config="$(echo $make_command | awk 'BEGIN {FS = "make "}{print $2}')"
+	local scan_build_flags="-v -analyze-headers -analyzer-config stable-report-filename=true "
+
+	# scan_build generates html and .js files to render bugs on code base
+	reports_dir="$workspace/scan-build-reports/"
+
+	# Get approprtiate compiler path
+	scan_build_flags+=" -o $reports_dir --use-cc=$(which ${cross_compile}gcc) \
+				--analyzer-target=${cross_compile}"
+
+	# Workaround a limiation in jenkins arch-dev nodes
+	if [ "$JENKINS_HOME" ]; then
+		export PATH=/usr/lib/llvm-6.0/bin/:$PATH
+		echo_w "Jenkins runs"
+		scan_build_artefacts="$BUILD_URL/artifact/artefacts/debug/scan-build-reports"
+	else
+		echo_w "Local runs"
+		scan_build_artefacts="$artefacts/debug/scan-build-reports"
+	fi
+
+	echo_w "Build config selected: $tf_config"
+	make realclean
+
+	local build_info=$(scan-build ${scan_build_flags} $make_command)
+	result_loc=$(echo $build_info | awk 'BEGIN {FS = "scan-view "}{print $2}' \
+			| awk 'BEGIN {FS = " to examine bug reports"}{print $1}' \
+			| awk '{ gsub("[:\47]" , ""); print $0}')
+
+	if [ -d $result_loc ]; then
+		local defects="$(find $result_loc -iname 'report*.html'| wc -l)"
+		if [ $defects -ge 1 ]; then
+			echo_w "$defects defect(s) found in build \"$build_config\" "
+			echo_w "Please view the detailed report here:"
+			echo_w "$scan_build_artefacts/$tf_config-reports/index.html"
+		fi
+		mv "$result_loc" "$reports_dir/$tf_config-reports"
+	fi
+}