blob: 12f7ce3994321635951421f5fd5ffe1161f9fb3f [file] [log] [blame]
Minos Galanakisbefc8362021-06-29 14:41:04 +01001#!/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
10CHECKPATCH_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
11
12. "$CHECKPATCH_PATH/../utils.sh"
13TFM_PATH="$(fix_win_path $(get_full_path ./))"
14
15# Set the output file to common output directory
16OUTPUT_FILE_PATH="$TFM_PATH/checks_reports/checkpatch_report.log"
17
18# Set the chechpatch executable
19CHECKPATCH_APP="$CHECKPATCH_PATH/checkpatch.pl"
20
21
22# Parse the configuration file
23CHECKPATCH_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
30SKIP_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
38FIND_CMD="find $TFM_PATH -name '*.[ch]' -a -not \( -path "${SKIP_PATHS//:/ -o -path }" \)"
39CARE_LIST=$(eval $FIND_CMD | grep "$(git diff HEAD~1 --name-only)" -)
40
41# Check that script executed from root of git repository
42if [ "$(git rev-parse --show-toplevel)/" != $TFM_PATH ]
43then
44 echo "[SCF checkpatch] Please execute script from root of TF-M repository."
45 exit 1
46fi
47
48# Only run checkpatch if there are files to check
49if [ -z "$CARE_LIST" ]; then
50 echo "[SCF checkpatch] Could not find any files of interest in this commit"
51 exit 0
52fi
53
54# Run Checkpatch
55git diff HEAD~1 -- $CARE_LIST | $CHECKPATCH_APP $CHECKPATCH_CONFG - | tee -a "$OUTPUT_FILE_PATH"
56
57# Evaluate the result
58if [ ${PIPESTATUS[1]} -eq 0 ]; then
59 echo "[SCF checkpatch: PASS] No new issues have been introduced"
60 exit 0
61else
62 echo "[SCF checkpatch: WARNING] Raised some Warnings/Errors"
63 echo "[SCF checkpatch] Output report located at: \"$OUTPUT_FILE_PATH\""
64 exit 1
65fi