blob: 52bc623463740dbd5e0590bab82213a902c7df04 [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 Sokolovsky09e1a6e2024-06-17 18:18:09 +030012TEST_CASE="Codestyle on the entire patch chain"
Fathi Boudra422bf772019-12-02 11:10:16 +020013
Paul Sokolovsky09e1a6e2024-06-17 18:18:09 +030014echo "# $TEST_CASE"
Fathi Boudra422bf772019-12-02 11:10:16 +020015
Paul Sokolovsky09e1a6e2024-06-17 18:18:09 +030016BASE_COMMIT=origin/$TF_GERRIT_BRANCH
17COMMON_COMMIT=$(git merge-base HEAD $BASE_COMMIT)
18
19git log --oneline $COMMON_COMMIT..HEAD
Fathi Boudra422bf772019-12-02 11:10:16 +020020
21LOG_FILE=$(mktemp -t coding-style-check.XXXX)
22
Fathi Boudra422bf772019-12-02 11:10:16 +020023chmod +x $CI_ROOT/script/static-checks/checkpatch.pl
24
25CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \
Paul Sokolovsky09e1a6e2024-06-17 18:18:09 +030026 make checkpatch BASE_COMMIT=origin/$TF_GERRIT_BRANCH &> "$LOG_FILE"
Fathi Boudra422bf772019-12-02 11:10:16 +020027RES=$?
28
29if [[ "$RES" == 0 ]]; then
30 # Ignore warnings, only mark the test as failed if there are errors.
31 grep --quiet "total: [^0][0-9]* errors" "$LOG_FILE"
32 RES=$?
33else
34 RES=0
35fi
36
37if [[ "$RES" == 0 ]]; then
38 EXIT_VALUE=1
39else
40 EXIT_VALUE=0
41fi
42
43echo >> "$LOG_TEST_FILENAME"
44echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
45echo >> "$LOG_TEST_FILENAME"
46if [[ "$EXIT_VALUE" == 0 ]]; then
47 echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
48else
49 echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
50fi
51# Always print the script output to show the warnings
52echo >> "$LOG_TEST_FILENAME"
53cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
54echo >> "$LOG_TEST_FILENAME"
55
56rm -f "$LOG_FILE"
57
58exit "$EXIT_VALUE"