blob: 5341e34e2d312b45a562c1cc3b01781ea17f2a8d [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
8# Check the coding style of the current patch (not the entire code base)
9# against the Linux coding style using the checkpatch.pl script from
10# the Linux kernel source tree.
11
12TEST_CASE="Coding style on current patch"
13
14echo "# Check coding style on the last patch"
15
16git show --summary
17
18LOG_FILE=$(mktemp -t coding-style-check.XXXX)
19
20# Make the patch against the specified remote branch
21if [ -n "$CODING_STYLE_BASE_BRANCH" ]; then
22 BASE_COMMIT="BASE_COMMIT=$CODING_STYLE_BASE_BRANCH"
23fi
24
25chmod +x $CI_ROOT/script/static-checks/checkpatch.pl
26
27CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \
28 make checkpatch &> "$LOG_FILE"
29RES=$?
30
31if [[ "$RES" == 0 ]]; then
32 # Ignore warnings, only mark the test as failed if there are errors.
33 grep --quiet "total: [^0][0-9]* errors" "$LOG_FILE"
34 RES=$?
35else
36 RES=0
37fi
38
39if [[ "$RES" == 0 ]]; then
40 EXIT_VALUE=1
41else
42 EXIT_VALUE=0
43fi
44
45echo >> "$LOG_TEST_FILENAME"
46echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
47echo >> "$LOG_TEST_FILENAME"
48if [[ "$EXIT_VALUE" == 0 ]]; then
49 echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
50else
51 echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
52fi
53# Always print the script output to show the warnings
54echo >> "$LOG_TEST_FILENAME"
55cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
56echo >> "$LOG_TEST_FILENAME"
57
58rm -f "$LOG_FILE"
59
60exit "$EXIT_VALUE"