Leonardo Sandoval | 9dfdd1b | 2020-08-06 17:08:11 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 2 | # |
Leonardo Sandoval | 579c737 | 2020-10-23 15:23:32 -0500 | [diff] [blame] | 3 | # Copyright (c) 2019-2020 Arm Limited. All rights reserved. |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 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 | |
Paul Sokolovsky | e311dae | 2024-06-19 13:34:24 +0300 | [diff] [blame] | 12 | this_dir="$(readlink -f "$(dirname "$0")")" |
| 13 | . $this_dir/common.sh |
| 14 | |
| 15 | |
| 16 | TEST_CASE="Coding style on current patch" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 17 | |
Paul Sokolovsky | b187f67 | 2024-06-24 18:48:17 +0300 | [diff] [blame] | 18 | echo "# Check coding style on the last patch" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 19 | |
Paul Sokolovsky | b187f67 | 2024-06-24 18:48:17 +0300 | [diff] [blame] | 20 | git show --summary |
Paul Sokolovsky | 09e1a6e | 2024-06-17 18:18:09 +0300 | [diff] [blame] | 21 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 22 | LOG_FILE=$(mktemp -t coding-style-check.XXXX) |
| 23 | |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 24 | chmod +x $CI_ROOT/script/static-checks/checkpatch.pl |
| 25 | |
| 26 | CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \ |
Paul Sokolovsky | e311dae | 2024-06-19 13:34:24 +0300 | [diff] [blame] | 27 | make checkpatch BASE_COMMIT=$(get_merge_base) &> "$LOG_FILE" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 28 | RES=$? |
| 29 | |
| 30 | if [[ "$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=$? |
| 34 | else |
| 35 | RES=0 |
| 36 | fi |
| 37 | |
| 38 | if [[ "$RES" == 0 ]]; then |
| 39 | EXIT_VALUE=1 |
| 40 | else |
| 41 | EXIT_VALUE=0 |
| 42 | fi |
| 43 | |
| 44 | echo >> "$LOG_TEST_FILENAME" |
| 45 | echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME" |
| 46 | echo >> "$LOG_TEST_FILENAME" |
Fathi Boudra | 422bf77 | 2019-12-02 11:10:16 +0200 | [diff] [blame] | 47 | if [[ "$EXIT_VALUE" == 0 ]]; then |
| 48 | echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME" |
| 49 | else |
| 50 | echo "Result : FAILURE" >> "$LOG_TEST_FILENAME" |
| 51 | fi |
| 52 | # Always print the script output to show the warnings |
| 53 | echo >> "$LOG_TEST_FILENAME" |
| 54 | cat "$LOG_FILE" >> "$LOG_TEST_FILENAME" |
| 55 | echo >> "$LOG_TEST_FILENAME" |
| 56 | |
| 57 | rm -f "$LOG_FILE" |
| 58 | |
| 59 | exit "$EXIT_VALUE" |