blob: af2d71f3982008f05cf9e554041ab21a5c18bb50 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Zelalem1af7a7b2020-08-04 17:34:32 -05002#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05003# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
Zelalem1af7a7b2020-08-04 17:34:32 -05004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8scan_build_wrapper(){
9
10 local make_command="$(echo $@)"
11 local cross_compile="$(grep -oP "(?<=CROSS_COMPILE=)[a-z\-0-9]+" <<< $make_command)"
12 local build_config="$(echo $make_command | awk 'BEGIN {FS = "make "}{print $2}')"
13 local scan_build_flags="-v -analyze-headers -analyzer-config stable-report-filename=true "
14
15 # scan_build generates html and .js files to render bugs on code base
16 reports_dir="$workspace/scan-build-reports/"
17
18 # Get approprtiate compiler path
19 scan_build_flags+=" -o $reports_dir --use-cc=$(which ${cross_compile}gcc) \
20 --analyzer-target=${cross_compile}"
21
22 # Workaround a limiation in jenkins arch-dev nodes
23 if [ "$JENKINS_HOME" ]; then
24 export PATH=/usr/lib/llvm-6.0/bin/:$PATH
25 echo_w "Jenkins runs"
26 scan_build_artefacts="$BUILD_URL/artifact/artefacts/debug/scan-build-reports"
27 else
28 echo_w "Local runs"
29 scan_build_artefacts="$artefacts/debug/scan-build-reports"
30 fi
31
32 echo_w "Build config selected: $tf_config"
33 make realclean
34
35 local build_info=$(scan-build ${scan_build_flags} $make_command)
36 result_loc=$(echo $build_info | awk 'BEGIN {FS = "scan-view "}{print $2}' \
37 | awk 'BEGIN {FS = " to examine bug reports"}{print $1}' \
38 | awk '{ gsub("[:\47]" , ""); print $0}')
39
Leonardo Sandoval752b7db2020-11-04 14:23:24 -060040 if [ -d "$result_loc" ]; then
Zelalem1af7a7b2020-08-04 17:34:32 -050041 local defects="$(find $result_loc -iname 'report*.html'| wc -l)"
42 if [ $defects -ge 1 ]; then
43 echo_w "$defects defect(s) found in build \"$build_config\" "
44 echo_w "Please view the detailed report here:"
45 echo_w "$scan_build_artefacts/$tf_config-reports/index.html"
46 fi
47 mv "$result_loc" "$reports_dir/$tf_config-reports"
48 fi
49}