Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
Zelalem | 1af7a7b | 2020-08-04 17:34:32 -0500 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | scan_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 | |
| 40 | if [ -d $result_loc ]; then |
| 41 | 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 | } |