blob: 9e8bf33152c4b5e90cb436f32350ef4b2afc586a [file] [log] [blame]
Zachary Leafb6d86302024-10-29 10:29:15 +00001#!/usr/bin/env bash
2#
3# Copyright (c) 2024 Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8echo '----------------------------------------------'
9echo '-- Running Rust formatting and lint checks --'
10echo '----------------------------------------------'
11
12export LOG_TEST_FILENAME=$(pwd)/next-checks.log
13export RUSTUP_HOME=/usr/local/rustup
14
15# For local runs, we require GERRIT_BRANCH to be set to get the merge-base/diff
16# between the checked out commit and the tip of $GERRIT_BRANCH - for running
Tomás González6b547dc2025-07-24 16:10:32 +010017# next tests, usually this will be main
18export GERRIT_BRANCH=${GERRIT_BRANCH:="main"}
Zachary Leafb6d86302024-10-29 10:29:15 +000019
Tomás González35329d02025-08-18 09:37:53 +010020git fetch --unshallow --update-shallow origin
21git fetch --unshallow --update-shallow origin ${GERRIT_BRANCH} ${GERRIT_REFSPEC}
Chris Kay10a38d52025-07-31 16:13:20 +010022
Tomás González35329d02025-08-18 09:37:53 +010023export merge_base=$(git merge-base \
24 $(head -n1 .git/FETCH_HEAD | cut -f1) \
25 $(tail -n1 .git/FETCH_HEAD | cut -f1))
Zachary Leafb6d86302024-10-29 10:29:15 +000026
27# Find the absolute path of the scripts' top directory
28cd "$(dirname "$0")/../.."
29export CI_ROOT=$(pwd)
30cd -
31
Zachary Leafb6d86302024-10-29 10:29:15 +000032echo
33echo "###### Rust checks ######" > "$LOG_TEST_FILENAME"
34echo >> "$LOG_TEST_FILENAME"
35
36echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
Chris Kay10a38d52025-07-31 16:13:20 +010037git log --oneline ${merge_base}..HEAD >> "$LOG_TEST_FILENAME"
Zachary Leafb6d86302024-10-29 10:29:15 +000038echo >> "$LOG_TEST_FILENAME"
39echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
Chris Kay10a38d52025-07-31 16:13:20 +010040git log --oneline -1 ${merge_base} >> "$LOG_TEST_FILENAME"
41
Zachary Leafb6d86302024-10-29 10:29:15 +000042
43echo >> "$LOG_TEST_FILENAME"
44
45ERROR_COUNT=0
46
47# Ensure all the files contain a copyright
48
Tomás González1150fb82025-06-04 10:05:21 +010049"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh . --rusted
Zachary Leafb6d86302024-10-29 10:29:15 +000050
51if [ "$?" != 0 ]; then
52 echo "Copyright test: FAILURE"
53 ((ERROR_COUNT++))
54else
55 echo "Copyright test: PASS"
56fi
57echo
58
59# Check line endings
60
61if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
62 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
63else
64 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
65fi
66
67if [ "$?" != 0 ]; then
68 echo "Line ending test: FAILURE"
69 ((ERROR_COUNT++))
70else
71 echo "Line ending test: PASS"
72fi
73echo
74
75# Check coding style with cargo fmt
76
77"$CI_ROOT"/script/next-checks/next-checks-cargo-fmt.sh .
78
79if [ "$?" != 0 ]; then
80 echo "cargo fmt test: FAILURE"
81 ((ERROR_COUNT++))
82else
83 echo "cargo fmt test: PASS"
84fi
85echo
86
Tomás González2e7e1562025-06-18 14:34:34 +010087# Check documentation with cargo doc
88
89"$CI_ROOT"/script/next-checks/next-checks-cargo-doc.sh .
90
91if [ "$?" != 0 ]; then
92 echo "cargo doc test: FAILURE"
93 ((ERROR_COUNT++))
94else
95 echo "cargo doc test: PASS"
96fi
97echo
98
Zachary Leafb6d86302024-10-29 10:29:15 +000099# Check lints with clippy
100
101"$CI_ROOT"/script/next-checks/next-checks-clippy.sh .
102
103if [ "$?" != 0 ]; then
104 echo "Rust clippy: FAILURE"
105 ((ERROR_COUNT++))
106else
107 echo "Rust clippy: PASS"
108fi
109echo
110
111if [ "$ERROR_COUNT" != 0 ]; then
112 echo "Some static checks have failed."
113 exit 1
114fi
115
116exit 0