blob: 882e9e1e9d41b5298d69dfe77d90389371fefeff [file] [log] [blame]
Fathi Boudra422bf772019-12-02 11:10:16 +02001#!/bin/bash
2#
3# Copyright (c) 2019, Arm Limited. All rights reserved.
4#
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
18# Initialize log file
19
20export LOG_TEST_FILENAME=$(pwd)/static-checks.log
21
22echo
23echo "###### Static checks ######"
24echo
25
26echo "###### Static checks ######" > "$LOG_TEST_FILENAME"
27echo >> "$LOG_TEST_FILENAME"
28
29# Reset error counters
30
31ERROR_COUNT=0
32WARNING_COUNT=0
33
34# Ensure all the files contain a copyright
35
36echo 'Checking copyright in source files...'
37echo
38"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh .
39if [ "$?" != 0 ]; then
40 echo "Copyright test: FAILURE"
41 ((ERROR_COUNT++))
42else
43 echo "Copyright test: PASS"
44fi
45echo
46
47# Check alphabetic order of headers included.
48
49if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
50 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh . patch
51else
52 "$CI_ROOT"/script/static-checks/static-checks-include-order.sh .
53fi
54if [ "$?" != 0 ]; then
55 echo "Include order test: FAILURE"
56 ((WARNING_COUNT++))
57else
58 echo "Include order test: PASS"
59fi
60echo
61
62# Check line endings
63
Leonardo Sandoval239e8ac2020-07-27 15:14:59 -050064if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
65 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
66else
67 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
68fi
69
Fathi Boudra422bf772019-12-02 11:10:16 +020070if [ "$?" != 0 ]; then
71 echo "Line ending test: FAILURE"
72 ((ERROR_COUNT++))
73else
74 echo "Line ending test: PASS"
75fi
76echo
77
78# Check coding style
79
80echo 'Checking coding style compliance...'
81echo
82if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
83 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
84else
85 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
86fi
87if [ "$?" != 0 ]; then
88 echo "Coding style test: FAILURE"
89 ((ERROR_COUNT++))
90else
91 echo "Coding style test: PASS"
92fi
93echo
94
Zelalem219df412020-05-17 19:21:20 -050095# Check for any Banned API usage
96
97echo 'Checking Banned API usage...'
98echo
99if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
100 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
101else
102 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
103fi
104if [ "$?" != 0 ]; then
105 echo "Banned API check: FAILURE"
106 ((ERROR_COUNT++))
107else
108 echo "Banned API check: PASS"
109fi
110echo
111
112
Fathi Boudra422bf772019-12-02 11:10:16 +0200113# Check error count
114
115if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
116 echo "Some static checks have failed."
117fi
118
119if [ "$ERROR_COUNT" != 0 ]; then
120 exit 1
121fi
122
123exit 0