blob: 90f6cb47767c08f5078dc57ad450b832d822a9eb [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 Sokolovskye311dae2024-06-19 13:34:24 +030012this_dir="$(readlink -f "$(dirname "$0")")"
13. $this_dir/common.sh
14
15
16TEST_CASE="Coding style on current patch"
Fathi Boudra422bf772019-12-02 11:10:16 +020017
Paul Sokolovsky09e1a6e2024-06-17 18:18:09 +030018echo "# $TEST_CASE"
Fathi Boudra422bf772019-12-02 11:10:16 +020019
Paul Sokolovsky09e1a6e2024-06-17 18:18:09 +030020BASE_COMMIT=origin/$TF_GERRIT_BRANCH
21COMMON_COMMIT=$(git merge-base HEAD $BASE_COMMIT)
22
Fathi Boudra422bf772019-12-02 11:10:16 +020023LOG_FILE=$(mktemp -t coding-style-check.XXXX)
24
Fathi Boudra422bf772019-12-02 11:10:16 +020025chmod +x $CI_ROOT/script/static-checks/checkpatch.pl
26
27CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \
Paul Sokolovskye311dae2024-06-19 13:34:24 +030028 make checkpatch BASE_COMMIT=$(get_merge_base) &> "$LOG_FILE"
Fathi Boudra422bf772019-12-02 11:10:16 +020029RES=$?
30
31if [[ "$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=$?
35else
36 RES=0
37fi
38
39if [[ "$RES" == 0 ]]; then
40 EXIT_VALUE=1
41else
42 EXIT_VALUE=0
43fi
44
45echo >> "$LOG_TEST_FILENAME"
46echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
47echo >> "$LOG_TEST_FILENAME"
Paul Sokolovskyf12d7fa2024-06-17 19:27:12 +030048
49git log --oneline $COMMON_COMMIT..HEAD >> "$LOG_TEST_FILENAME"
50echo >> "$LOG_TEST_FILENAME"
51
Fathi Boudra422bf772019-12-02 11:10:16 +020052if [[ "$EXIT_VALUE" == 0 ]]; then
53 echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
54else
55 echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
56fi
57# Always print the script output to show the warnings
58echo >> "$LOG_TEST_FILENAME"
59cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
60echo >> "$LOG_TEST_FILENAME"
61
62rm -f "$LOG_FILE"
63
64exit "$EXIT_VALUE"