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 | |
| 12 | TEST_CASE="Coding style on current patch" |
| 13 | |
| 14 | echo "# Check coding style on the last patch" |
| 15 | |
| 16 | git show --summary |
| 17 | |
| 18 | LOG_FILE=$(mktemp -t coding-style-check.XXXX) |
| 19 | |
| 20 | # Make the patch against the specified remote branch |
| 21 | if [ -n "$CODING_STYLE_BASE_BRANCH" ]; then |
| 22 | BASE_COMMIT="BASE_COMMIT=$CODING_STYLE_BASE_BRANCH" |
| 23 | fi |
| 24 | |
| 25 | chmod +x $CI_ROOT/script/static-checks/checkpatch.pl |
| 26 | |
| 27 | CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \ |
| 28 | make checkpatch &> "$LOG_FILE" |
| 29 | RES=$? |
| 30 | |
| 31 | if [[ "$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=$? |
| 35 | else |
| 36 | RES=0 |
| 37 | fi |
| 38 | |
| 39 | if [[ "$RES" == 0 ]]; then |
| 40 | EXIT_VALUE=1 |
| 41 | else |
| 42 | EXIT_VALUE=0 |
| 43 | fi |
| 44 | |
| 45 | echo >> "$LOG_TEST_FILENAME" |
| 46 | echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME" |
| 47 | echo >> "$LOG_TEST_FILENAME" |
| 48 | if [[ "$EXIT_VALUE" == 0 ]]; then |
| 49 | echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME" |
| 50 | else |
| 51 | echo "Result : FAILURE" >> "$LOG_TEST_FILENAME" |
| 52 | fi |
| 53 | # Always print the script output to show the warnings |
| 54 | echo >> "$LOG_TEST_FILENAME" |
| 55 | cat "$LOG_FILE" >> "$LOG_TEST_FILENAME" |
| 56 | echo >> "$LOG_TEST_FILENAME" |
| 57 | |
| 58 | rm -f "$LOG_FILE" |
| 59 | |
| 60 | exit "$EXIT_VALUE" |