blob: 374e7fa330131c3b07f3f4eb7e2efd66598cd109 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Zelalemc9531f82020-08-04 15:37:08 -05003# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# This file is sourced from the build_package.sh script to use
9# coverity_wrapper() function as a build wrapper.
10#
11# This wrapper supports two work flows:
12#
13# - Compare the branch under test with that of master, and print defects. If
14# there are defects, we arrange the build to be marked as unstable. Set
15# $cov_run_type to 'branch-report-compare' to use this.
16#
17# - Commit and create snapshot for the entire branch. Set $cov_run_type to
18# 'branch-report-full' to use this.
19#
20# Coverity analysis involves contacting the server, which have shown to be very
21# slow. Depending on the type of analysis performed, we might have to do
22# analysis more than once, and doing that in series would only increase the turn
Zelalemc9531f82020-08-04 15:37:08 -050023# around time. To mitigate this, all Coverity commands, are called from a
24# Makefile, and run in parallel.
Fathi Boudra422bf772019-12-02 11:10:16 +020025
26coverity_wrapper() {
27 local cov_dir="$workspace/coverity"
Fathi Boudra422bf772019-12-02 11:10:16 +020028 local cov_compiler="${cov_compiler:-${CROSS_COMPILE}gcc}"
29
Fathi Boudra422bf772019-12-02 11:10:16 +020030 local auth_file="${cov_auth_file:-$ci_root/coverity/tfcibot@$coverity_host}"
Zelalemc9531f82020-08-04 15:37:08 -050031 local makefile="$ci_root/script/coverity-Makefile"
32 local defects_summary="$workspace/defects-summary.txt"
Fathi Boudra422bf772019-12-02 11:10:16 +020033
Fathi Boudra422bf772019-12-02 11:10:16 +020034 local description
35 local need_compare
36
37 echo_w
38 mkdir -p "$cov_dir"
39
40 if echo "${cov_run_type:?}" | grep -iq "branch-report-compare"; then
41 need_compare=1
42 local golden_url="${cov_golden_url:-$tf_src_repo_url}"
43 local golden_ref="${cov_golden_ref:-master}"
Zelalemc9531f82020-08-04 15:37:08 -050044 local defects_file="$workspace/diff-defects.txt"
45 else
46 local defects_file="$workspace/full-defects.txt"
Fathi Boudra422bf772019-12-02 11:10:16 +020047 fi
48
49 if upon "$local_ci"; then
50 description="$USER-local ${cov_checker:?}"
Fathi Boudra422bf772019-12-02 11:10:16 +020051 else
52 description="$JOB_NAME#$BUILD_NUMBER ${cov_checker:?}"
Fathi Boudra422bf772019-12-02 11:10:16 +020053 fi
54
55 # Create a stream and assign to Trusted Firmware project
56 chmod 400 "$auth_file"
57
Fathi Boudra422bf772019-12-02 11:10:16 +020058 local minus_j="-j"
59 if upon "$cov_serial_build"; then
60 minus_j=
61 fi
62
63 # Call Coverity targets
64 echo "Coverity run type: ${cov_run_type:?}"
Zelalemc9531f82020-08-04 15:37:08 -050065 # Remove the `make` from the front of the command line as we need to
66 # insert -C <directory> inside the makefile
67 shift
68 MAKEFLAGS= SUBMAKE="$@" make -r $minus_j -f "$makefile" -C "$workspace" \
69 auth_file=$auth_file\
70 golden_url=$golden_url\
71 golden_ref=$golden_ref\
72 tf_src_repo_url=$tf_src_repo_url\
73 cov_compiler=$cov_compiler\
74 minus_j=$minus_j\
75 description="$description"\
76 ci_root="$ci_root"\
77 $cov_run_type 2>&3 || exit 1
Fathi Boudra422bf772019-12-02 11:10:16 +020078
79 # If there were defects, print them out to the console. For local CI,
80 # print them in yellow--the same color we'd use for UNSTABLE builds.
81 if [ -s "$defects_file" ]; then
82 echo_w
83 echo_w "Coverity defects found:"
84 echo_w
85 if upon "$local_ci"; then
86 echo_w "$(tput setaf 3)"
87 fi
88 cat "$defects_file" >&3
89 if upon "$local_ci"; then
90 echo_w "$(tput sgr0)"
91 fi
92 echo_w
Zelalemc9531f82020-08-04 15:37:08 -050093 cat $defects_summary >&3
Fathi Boudra422bf772019-12-02 11:10:16 +020094 echo_w
95 build_unstable >&3
96 echo_w
97 else
98 echo_w
99 echo_w "No coverity defects found."
100 echo_w
101 fi
102}