blob: 5e9edbb98b38faa1eba9717cebc7e845aa1d6942 [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Paul Sokolovsky422020c2024-06-18 23:21:07 +03003# Copyright (c) 2019-2024 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8echo '----------------------------------------------'
9echo '-- Running static checks on the source code --'
10echo '----------------------------------------------'
11
12# Find the absolute path of the scripts' top directory
13
14cd "$(dirname "$0")/../.."
15export CI_ROOT=$(pwd)
16cd -
17
Paul Sokolovsky422020c2024-06-18 23:21:07 +030018. $CI_ROOT/script/static-checks/common.sh
19
Harrison Mutai5d470c12025-07-16 08:26:58 +000020merge_base=$(get_merge_base)
21if [[ -z "$merge_base" ]]; then
22 echo "Failed to find merge base, fetching entire change history"
23
24 # Set GERRIT_REFSPEC if not already defined
25 if [[ -z "$GERRIT_REFSPEC" ]]; then
26 if [[ "$TF_GERRIT_PROJECT" == *tf-a-tests ]]; then
27 GERRIT_REFSPEC="$TFTF_GERRIT_REFSPEC"
28 else
29 GERRIT_REFSPEC="$TF_GERRIT_REFSPEC"
30 fi
31 fi
32
Harrison Mutai4014ba62025-07-21 14:19:10 +000033 git fetch --unshallow --update-shallow origin "$GERRIT_REFSPEC"
Harrison Mutai5d470c12025-07-16 08:26:58 +000034 git checkout FETCH_HEAD
35
36 merge_base=$(get_merge_base)
37
38 if [[ -z "$merge_base" ]]; then
39 echo "Failed to determine merge base after fetching. Exiting." >&2
40 exit 1
41 fi
42fi
43
44export merge_base
Fathi Boudra422bf772019-12-02 11:10:16 +020045
46export LOG_TEST_FILENAME=$(pwd)/static-checks.log
47
48echo
49echo "###### Static checks ######"
50echo
51
52echo "###### Static checks ######" > "$LOG_TEST_FILENAME"
53echo >> "$LOG_TEST_FILENAME"
54
Paul Sokolovsky422020c2024-06-18 23:21:07 +030055echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
Harrison Mutai5d470c12025-07-16 08:26:58 +000056git log --oneline ${merge_base}..HEAD >> "$LOG_TEST_FILENAME"
Paul Sokolovsky422020c2024-06-18 23:21:07 +030057echo >> "$LOG_TEST_FILENAME"
58echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
Harrison Mutai5d470c12025-07-16 08:26:58 +000059git log --oneline -1 ${merge_base} >> "$LOG_TEST_FILENAME"
60
Paul Sokolovsky422020c2024-06-18 23:21:07 +030061
62echo >> "$LOG_TEST_FILENAME"
63
Fathi Boudra422bf772019-12-02 11:10:16 +020064# Reset error counters
65
66ERROR_COUNT=0
67WARNING_COUNT=0
68
69# Ensure all the files contain a copyright
70
71echo 'Checking copyright in source files...'
72echo
73"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh .
74if [ "$?" != 0 ]; then
75 echo "Copyright test: FAILURE"
76 ((ERROR_COUNT++))
77else
78 echo "Copyright test: PASS"
79fi
80echo
81
82# Check alphabetic order of headers included.
83
84if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
85 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh . patch
86else
87 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh .
88fi
89if [ "$?" != 0 ]; then
90 echo "Include order test: FAILURE"
91 ((WARNING_COUNT++))
92else
93 echo "Include order test: PASS"
94fi
95echo
96
97# Check line endings
98
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050099if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
100 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
101else
102 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
103fi
104
Fathi Boudra422bf772019-12-02 11:10:16 +0200105if [ "$?" != 0 ]; then
106 echo "Line ending test: FAILURE"
107 ((ERROR_COUNT++))
108else
109 echo "Line ending test: PASS"
110fi
111echo
112
113# Check coding style
114
115echo 'Checking coding style compliance...'
116echo
117if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
118 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
119else
120 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
121fi
122if [ "$?" != 0 ]; then
123 echo "Coding style test: FAILURE"
124 ((ERROR_COUNT++))
125else
126 echo "Coding style test: PASS"
127fi
128echo
129
Zelalem219df412020-05-17 19:21:20 -0500130# Check for any Banned API usage
131
132echo 'Checking Banned API usage...'
133echo
134if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
135 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
136else
137 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
138fi
139if [ "$?" != 0 ]; then
140 echo "Banned API check: FAILURE"
141 ((ERROR_COUNT++))
142else
143 echo "Banned API check: PASS"
144fi
145echo
146
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100147# Check to ensure newly added source files are detected for Coverity Scan analysis
148
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100149# Check to be executed only on trusted-firmware repository.
Manish V Badarkhe8b846f42021-10-13 15:43:58 +0100150if [ "$REPO_UNDER_TEST" = "trusted-firmware" ] || [ "$REPO_UNDER_TEST" = "trusted-firmware-a" ]; then
Jayanth Dodderi Chidanand253b3392021-09-10 12:40:00 +0100151 echo 'Checking whether the newly added source files are detected for Coverity Scan analysis...'
152 echo
153 "$CI_ROOT"/script/static-checks/static-checks-detect-newly-added-files.sh
154 if [ "$?" != 0 ]; then
155 echo "Files Detection check: FAILURE"
156 ((ERROR_COUNT++))
157 else
158 echo "Files Detection check: PASS"
159 fi
160 echo
Jayanth Dodderi Chidanand5132cb12021-08-09 17:54:47 +0100161fi
Zelalem219df412020-05-17 19:21:20 -0500162
Fathi Boudra422bf772019-12-02 11:10:16 +0200163# Check error count
164
165if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
166 echo "Some static checks have failed."
167fi
168
169if [ "$ERROR_COUNT" != 0 ]; then
170 exit 1
171fi
172
173exit 0