blob: 6bae729d035e0cda1426338e59197cf1dc33d205 [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
64"$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
65if [ "$?" != 0 ]; then
66 echo "Line ending test: FAILURE"
67 ((ERROR_COUNT++))
68else
69 echo "Line ending test: PASS"
70fi
71echo
72
73# Check coding style
74
75echo 'Checking coding style compliance...'
76echo
77if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
78 "$CI_ROOT"/script/static-checks/static-checks-coding-style.sh
79else
80 "$CI_ROOT"/script/static-checks/static-checks-coding-style-entire-src-tree.sh
81fi
82if [ "$?" != 0 ]; then
83 echo "Coding style test: FAILURE"
84 ((ERROR_COUNT++))
85else
86 echo "Coding style test: PASS"
87fi
88echo
89
Zelalem219df412020-05-17 19:21:20 -050090# Check for any Banned API usage
91
92echo 'Checking Banned API usage...'
93echo
94if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
95 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh . patch
96else
97 "$CI_ROOT"/script/static-checks/static-checks-banned-apis.sh
98fi
99if [ "$?" != 0 ]; then
100 echo "Banned API check: FAILURE"
101 ((ERROR_COUNT++))
102else
103 echo "Banned API check: PASS"
104fi
105echo
106
107
Fathi Boudra422bf772019-12-02 11:10:16 +0200108# Check error count
109
110if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
111 echo "Some static checks have failed."
112fi
113
114if [ "$ERROR_COUNT" != 0 ]; then
115 exit 1
116fi
117
118exit 0