blob: 9447c444f2817c04316323994655fb8da1e6ee16 [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
Fathi Boudra422bf772019-12-02 11:10:16 +020019LOG_FILE=$(mktemp -t coding-style-check.XXXX)
20
Fathi Boudra422bf772019-12-02 11:10:16 +020021chmod +x $CI_ROOT/script/static-checks/checkpatch.pl
22
23CHECKPATCH=$CI_ROOT/script/static-checks/checkpatch.pl \
Paul Sokolovsky09e1a6e2024-06-17 18:18:09 +030024 make checkpatch BASE_COMMIT=origin/$TF_GERRIT_BRANCH &> "$LOG_FILE"
Fathi Boudra422bf772019-12-02 11:10:16 +020025RES=$?
26
27if [[ "$RES" == 0 ]]; then
28 # Ignore warnings, only mark the test as failed if there are errors.
29 grep --quiet "total: [^0][0-9]* errors" "$LOG_FILE"
30 RES=$?
31else
32 RES=0
33fi
34
35if [[ "$RES" == 0 ]]; then
36 EXIT_VALUE=1
37else
38 EXIT_VALUE=0
39fi
40
41echo >> "$LOG_TEST_FILENAME"
42echo "****** $TEST_CASE ******" >> "$LOG_TEST_FILENAME"
43echo >> "$LOG_TEST_FILENAME"
Paul Sokolovskyf12d7fa2024-06-17 19:27:12 +030044
45git log --oneline $COMMON_COMMIT..HEAD >> "$LOG_TEST_FILENAME"
46echo >> "$LOG_TEST_FILENAME"
47
Fathi Boudra422bf772019-12-02 11:10:16 +020048if [[ "$EXIT_VALUE" == 0 ]]; then
49 echo "Result : SUCCESS" >> "$LOG_TEST_FILENAME"
50else
51 echo "Result : FAILURE" >> "$LOG_TEST_FILENAME"
52fi
53# Always print the script output to show the warnings
54echo >> "$LOG_TEST_FILENAME"
55cat "$LOG_FILE" >> "$LOG_TEST_FILENAME"
56echo >> "$LOG_TEST_FILENAME"
57
58rm -f "$LOG_FILE"
59
60exit "$EXIT_VALUE"