Minos Galanakis | befc836 | 2021-06-29 14:41:04 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | #------------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2018-2021, Arm Limited and Contributors. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | #------------------------------------------------------------------------------- |
| 8 | |
| 9 | # Capture the path the script is at |
| 10 | CHECKPATCH_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" |
| 11 | |
| 12 | . "$CHECKPATCH_PATH/../utils.sh" |
| 13 | TFM_PATH="$(fix_win_path $(get_full_path ./))" |
| 14 | |
| 15 | # Set the output file to common output directory |
| 16 | OUTPUT_FILE_PATH="$TFM_PATH/checks_reports/checkpatch_report.log" |
| 17 | |
| 18 | # Set the chechpatch executable |
| 19 | CHECKPATCH_APP="$CHECKPATCH_PATH/checkpatch.pl" |
| 20 | |
| 21 | |
| 22 | # Parse the configuration file |
| 23 | CHECKPATCH_CONFG="$(grep -o '^[^#]*' $CHECKPATCH_PATH/checkpatch.conf)" |
| 24 | |
| 25 | # Directories which are ignored either because they contain external code |
| 26 | # or documentation/ 3rd party tools |
| 27 | |
| 28 | # Please keep it in sync with the excluded directories the CI uses |
| 29 | # https://git.trustedfirmware.org/next/ci/tf-m-ci-scripts.git/tree/run-checkpatch.sh?h=refs/heads/master |
| 30 | SKIP_PATHS='./build-\*:./platform/\*:*/tz_\*:./lib/\*:./platform/ext/\*:./bl2/ext/\*:./docs/\*:./tools/\*' |
| 31 | |
| 32 | |
| 33 | # Find the intersection of the files changed in the commit, with the union |
| 34 | # of the files in the project, exclding everything in the SKIP_PATHS |
| 35 | |
| 36 | # Please keep it in sync with the excluded directories the CI uses |
| 37 | # https://git.trustedfirmware.org/next/ci/tf-m-ci-scripts.git/tree/run-checkpatch.sh?h=refs/heads/master |
| 38 | FIND_CMD="find $TFM_PATH -name '*.[ch]' -a -not \( -path "${SKIP_PATHS//:/ -o -path }" \)" |
| 39 | CARE_LIST=$(eval $FIND_CMD | grep "$(git diff HEAD~1 --name-only)" -) |
| 40 | |
| 41 | # Check that script executed from root of git repository |
| 42 | if [ "$(git rev-parse --show-toplevel)/" != $TFM_PATH ] |
| 43 | then |
| 44 | echo "[SCF checkpatch] Please execute script from root of TF-M repository." |
| 45 | exit 1 |
| 46 | fi |
| 47 | |
| 48 | # Only run checkpatch if there are files to check |
| 49 | if [ -z "$CARE_LIST" ]; then |
| 50 | echo "[SCF checkpatch] Could not find any files of interest in this commit" |
| 51 | exit 0 |
| 52 | fi |
| 53 | |
| 54 | # Run Checkpatch |
| 55 | git diff HEAD~1 -- $CARE_LIST | $CHECKPATCH_APP $CHECKPATCH_CONFG - | tee -a "$OUTPUT_FILE_PATH" |
| 56 | |
| 57 | # Evaluate the result |
| 58 | if [ ${PIPESTATUS[1]} -eq 0 ]; then |
| 59 | echo "[SCF checkpatch: PASS] No new issues have been introduced" |
| 60 | exit 0 |
| 61 | else |
| 62 | echo "[SCF checkpatch: WARNING] Raised some Warnings/Errors" |
| 63 | echo "[SCF checkpatch] Output report located at: \"$OUTPUT_FILE_PATH\"" |
| 64 | exit 1 |
| 65 | fi |