blob: 4cb0d439e7020ffc666370936c5890d460550285 [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
Chris Kay10a38d52025-07-31 16:13:20 +010020
Zachary Leafb6d86302024-10-29 10:29:15 +000021if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
Chris Kay10a38d52025-07-31 16:13:20 +010022 # git operations rely on access to main branch, we need to access via SSH for that to work currently
Zachary Leafb6d86302024-10-29 10:29:15 +000023 SSH_PARAMS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o PubkeyAcceptedKeyTypes=+ssh-rsa -p 29418 -i ${CI_BOT_KEY}"
Tomás González6b547dc2025-07-24 16:10:32 +010024 REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@review.trustedfirmware.org:29418/RF-A/rusted-firmware-a"
Zachary Leafb6d86302024-10-29 10:29:15 +000025 export GIT_SSH_COMMAND="ssh ${SSH_PARAMS}"
26 git remote set-url origin ${REPO_SSH_URL}
Chris Kay10a38d52025-07-31 16:13:20 +010027 git fetch --unshallow --update-shallow origin
28 git fetch --unshallow --update-shallow origin ${GERRIT_BRANCH} ${GERRIT_REFSPEC}
29
30 export merge_base=$(git merge-base \
31 $(head -n1 .git/FETCH_HEAD | cut -f1) \
32 $(tail -n1 .git/FETCH_HEAD | cut -f1))
Zachary Leafb6d86302024-10-29 10:29:15 +000033fi
34
35# Find the absolute path of the scripts' top directory
36cd "$(dirname "$0")/../.."
37export CI_ROOT=$(pwd)
38cd -
39
Zachary Leafb6d86302024-10-29 10:29:15 +000040echo
41echo "###### Rust checks ######" > "$LOG_TEST_FILENAME"
42echo >> "$LOG_TEST_FILENAME"
43
44echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
Chris Kay10a38d52025-07-31 16:13:20 +010045git log --oneline ${merge_base}..HEAD >> "$LOG_TEST_FILENAME"
Zachary Leafb6d86302024-10-29 10:29:15 +000046echo >> "$LOG_TEST_FILENAME"
47echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
Chris Kay10a38d52025-07-31 16:13:20 +010048git log --oneline -1 ${merge_base} >> "$LOG_TEST_FILENAME"
49
Zachary Leafb6d86302024-10-29 10:29:15 +000050
51echo >> "$LOG_TEST_FILENAME"
52
53ERROR_COUNT=0
54
55# Ensure all the files contain a copyright
56
Tomás González1150fb82025-06-04 10:05:21 +010057"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh . --rusted
Zachary Leafb6d86302024-10-29 10:29:15 +000058
59if [ "$?" != 0 ]; then
60 echo "Copyright test: FAILURE"
61 ((ERROR_COUNT++))
62else
63 echo "Copyright test: PASS"
64fi
65echo
66
67# Check line endings
68
69if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
70 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
71else
72 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
73fi
74
75if [ "$?" != 0 ]; then
76 echo "Line ending test: FAILURE"
77 ((ERROR_COUNT++))
78else
79 echo "Line ending test: PASS"
80fi
81echo
82
83# Check coding style with cargo fmt
84
85"$CI_ROOT"/script/next-checks/next-checks-cargo-fmt.sh .
86
87if [ "$?" != 0 ]; then
88 echo "cargo fmt test: FAILURE"
89 ((ERROR_COUNT++))
90else
91 echo "cargo fmt test: PASS"
92fi
93echo
94
Tomás González2e7e1562025-06-18 14:34:34 +010095# Check documentation with cargo doc
96
97"$CI_ROOT"/script/next-checks/next-checks-cargo-doc.sh .
98
99if [ "$?" != 0 ]; then
100 echo "cargo doc test: FAILURE"
101 ((ERROR_COUNT++))
102else
103 echo "cargo doc test: PASS"
104fi
105echo
106
Zachary Leafb6d86302024-10-29 10:29:15 +0000107# Check lints with clippy
108
109"$CI_ROOT"/script/next-checks/next-checks-clippy.sh .
110
111if [ "$?" != 0 ]; then
112 echo "Rust clippy: FAILURE"
113 ((ERROR_COUNT++))
114else
115 echo "Rust clippy: PASS"
116fi
117echo
118
119if [ "$ERROR_COUNT" != 0 ]; then
120 echo "Some static checks have failed."
121 exit 1
122fi
123
124exit 0