blob: 89df4566010f6be1f2851e66aef52ad5fc3d54de [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
17# next tests, usually this will be tfa-next
18export GERRIT_BRANCH=${GERRIT_BRANCH:="tfa-next"}
19
20if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then
21 # git operations e.g. ${get_merge_base} rely on access to tfa-next branch,
22 # 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}"
24 REPO_SSH_URL="ssh://${CI_BOT_USERNAME}@review.trustedfirmware.org:29418/TF-A/trusted-firmware-a"
25 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
53"$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh .
54
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
91# Check lints with clippy
92
93"$CI_ROOT"/script/next-checks/next-checks-clippy.sh .
94
95if [ "$?" != 0 ]; then
96 echo "Rust clippy: FAILURE"
97 ((ERROR_COUNT++))
98else
99 echo "Rust clippy: PASS"
100fi
101echo
102
103if [ "$ERROR_COUNT" != 0 ]; then
104 echo "Some static checks have failed."
105 exit 1
106fi
107
108exit 0