blob: 4483b1591a16c0385c67afb3df844c4a4417692e [file] [log] [blame]
Leonardo Sandoval9dfdd1b2020-08-06 17:08:11 -05001#!/usr/bin/env bash
Fathi Boudra422bf772019-12-02 11:10:16 +02002#
Leonardo Sandoval579c7372020-10-23 15:23:32 -05003# Copyright (c) 2019-2020 Arm Limited. All rights reserved.
Fathi Boudra422bf772019-12-02 11:10:16 +02004#
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
Paul Sokolovsky5abd1382024-06-19 13:34:24 +030012this_dir="$(readlink -f "$(dirname "$0")")"
13. $this_dir/common.sh
14
15
Fathi Boudra422bf772019-12-02 11:10:16 +020016TEST_CASE="Coding style on current patch"
17
18echo "# Check coding style on the last patch"
19
20git show --summary
21
22LOG_FILE=$(mktemp -t coding-style-check.XXXX)
23
Fathi Boudra422bf772019-12-02 11:10:16 +020024chmod +x $CI_ROOT/script/static-checks/checkpatch.pl
25
26CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \
Paul Sokolovsky5abd1382024-06-19 13:34:24 +030027 make checkpatch BASE_COMMIT=$(get_merge_base) &> "$LOG_FILE"
Fathi Boudra422bf772019-12-02 11:10:16 +020028RES=$?
29
30if [[ "$RES" == 0 ]]; then
31 # Ignore warnings, only mark the test as failed if there are errors.
32 grep --quiet "total: [^0][0-9]* errors" "$LOG_FILE"
33 RES=$?
34else
35 RES=0
36fi
37
38if [[ "$RES" == 0 ]]; then
39 EXIT_VALUE=1
40else
41 EXIT_VALUE=0
42fi
43
44echo >> "$LOG_TEST_FILENAME"
45echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
46echo >> "$LOG_TEST_FILENAME"
47if [[ "$EXIT_VALUE" == 0 ]]; then
48 echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
49else
50 echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
51fi
52# Always print the script output to show the warnings
53echo >> "$LOG_TEST_FILENAME"
54cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
55echo >> "$LOG_TEST_FILENAME"
56
57rm -f "$LOG_FILE"
58
59exit "$EXIT_VALUE"