blob: 39c9d28cc26d20cccc8d06fa22a27e1872667f8c [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
20if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
Tomás González6b547dc2025-07-24 16:10:32 +010021 # git operations e.g. ${get_merge_base} rely on access to main branch,
Zachary Leafb6d86302024-10-29 10:29:15 +000022 # we need to access via SSH for that to work currently
23 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}
27 git fetch origin
28fi
29
30# Find the absolute path of the scripts' top directory
31cd "$(dirname "$0")/../.."
32export CI_ROOT=$(pwd)
33cd -
34
35. $CI_ROOT/script/static-checks/common.sh
36
37echo
38echo "###### Rust checks ######" > "$LOG_TEST_FILENAME"
39echo >> "$LOG_TEST_FILENAME"
40
41echo "Patch series being checked:" >> "$LOG_TEST_FILENAME"
42git log --oneline $(get_merge_base)..HEAD >> "$LOG_TEST_FILENAME"
43echo >> "$LOG_TEST_FILENAME"
44echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME"
45git log --oneline -1 $(get_merge_base) >> "$LOG_TEST_FILENAME"
46
47echo >> "$LOG_TEST_FILENAME"
48
49ERROR_COUNT=0
50
51# Ensure all the files contain a copyright
52
Tomás González1150fb82025-06-04 10:05:21 +010053"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh . --rusted
Zachary Leafb6d86302024-10-29 10:29:15 +000054
55if [ "$?" != 0 ]; then
56 echo "Copyright test: FAILURE"
57 ((ERROR_COUNT++))
58else
59 echo "Copyright test: PASS"
60fi
61echo
62
63# Check line endings
64
65if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
66 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch
67else
68 "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh
69fi
70
71if [ "$?" != 0 ]; then
72 echo "Line ending test: FAILURE"
73 ((ERROR_COUNT++))
74else
75 echo "Line ending test: PASS"
76fi
77echo
78
79# Check coding style with cargo fmt
80
81"$CI_ROOT"/script/next-checks/next-checks-cargo-fmt.sh .
82
83if [ "$?" != 0 ]; then
84 echo "cargo fmt test: FAILURE"
85 ((ERROR_COUNT++))
86else
87 echo "cargo fmt test: PASS"
88fi
89echo
90
Tomás González2e7e1562025-06-18 14:34:34 +010091# Check documentation with cargo doc
92
93"$CI_ROOT"/script/next-checks/next-checks-cargo-doc.sh .
94
95if [ "$?" != 0 ]; then
96 echo "cargo doc test: FAILURE"
97 ((ERROR_COUNT++))
98else
99 echo "cargo doc test: PASS"
100fi
101echo
102
Zachary Leafb6d86302024-10-29 10:29:15 +0000103# Check lints with clippy
104
105"$CI_ROOT"/script/next-checks/next-checks-clippy.sh .
106
107if [ "$?" != 0 ]; then
108 echo "Rust clippy: FAILURE"
109 ((ERROR_COUNT++))
110else
111 echo "Rust clippy: PASS"
112fi
113echo
114
115if [ "$ERROR_COUNT" != 0 ]; then
116 echo "Some static checks have failed."
117 exit 1
118fi
119
120exit 0