blob: a4497961ddca06d5b8957482553d5f2e66e1c7e2 [file] [log] [blame]
Leonardo Sandoval314eed82020-08-05 13:32:04 -05001#!/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
Leonardo Sandovala9b86762020-08-05 13:50:59 -050014cd "$(dirname "$0")"
Leonardo Sandoval314eed82020-08-05 13:32:04 -050015export 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
64if [ "$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
70if [ "$?" != 0 ]; then
71 echo "Line ending test: FAILURE"
72 ((ERROR_COUNT++))
73else
74 echo "Line ending test: PASS"
75fi
76echo
77
Leonardo Sandoval314eed82020-08-05 13:32:04 -050078# Check for any Banned API usage
79
80echo 'Checking Banned API usage...'
81echo
82if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
83 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
84else
85 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
86fi
87if [ "$?" != 0 ]; then
88 echo "Banned API check: FAILURE"
89 ((ERROR_COUNT++))
90else
91 echo "Banned API check: PASS"
92fi
93echo
94
95
96# Check error count
97
98if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
99 echo "Some static checks have failed."
100fi
101
102if [ "$ERROR_COUNT" != 0 ]; then
103 exit 1
104fi
105
106exit 0