blob: c9b980cd335585e2e7b0a9f73d2ebd787c1620f5 [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
90# Check error count
91
92if [ "$ERROR_COUNT" != 0 ] || [ "$WARNING_COUNT" != 0 ]; then
93 echo "Some static checks have failed."
94fi
95
96if [ "$ERROR_COUNT" != 0 ]; then
97 exit 1
98fi
99
100exit 0