Zachary Leaf | b6d8630 | 2024-10-29 10:29:15 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env bash |
| 2 | # |
| 3 | # Copyright (c) 2024 Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | |
| 8 | echo '----------------------------------------------' |
| 9 | echo '-- Running Rust formatting and lint checks --' |
| 10 | echo '----------------------------------------------' |
| 11 | |
| 12 | export LOG_TEST_FILENAME=$(pwd)/next-checks.log |
| 13 | export 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 |
| 18 | export GERRIT_BRANCH=${GERRIT_BRANCH:="tfa-next"} |
| 19 | |
| 20 | if [ "$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 |
| 28 | fi |
| 29 | |
| 30 | # Find the absolute path of the scripts' top directory |
| 31 | cd "$(dirname "$0")/../.." |
| 32 | export CI_ROOT=$(pwd) |
| 33 | cd - |
| 34 | |
| 35 | . $CI_ROOT/script/static-checks/common.sh |
| 36 | |
| 37 | echo |
| 38 | echo "###### Rust checks ######" > "$LOG_TEST_FILENAME" |
| 39 | echo >> "$LOG_TEST_FILENAME" |
| 40 | |
| 41 | echo "Patch series being checked:" >> "$LOG_TEST_FILENAME" |
| 42 | git log --oneline $(get_merge_base)..HEAD >> "$LOG_TEST_FILENAME" |
| 43 | echo >> "$LOG_TEST_FILENAME" |
| 44 | echo "Base branch reference commit:" >> "$LOG_TEST_FILENAME" |
| 45 | git log --oneline -1 $(get_merge_base) >> "$LOG_TEST_FILENAME" |
| 46 | |
| 47 | echo >> "$LOG_TEST_FILENAME" |
| 48 | |
| 49 | ERROR_COUNT=0 |
| 50 | |
| 51 | # Ensure all the files contain a copyright |
| 52 | |
| 53 | "$CI_ROOT"/script/static-checks/static-checks-check-copyright.sh . |
| 54 | |
| 55 | if [ "$?" != 0 ]; then |
| 56 | echo "Copyright test: FAILURE" |
| 57 | ((ERROR_COUNT++)) |
| 58 | else |
| 59 | echo "Copyright test: PASS" |
| 60 | fi |
| 61 | echo |
| 62 | |
| 63 | # Check line endings |
| 64 | |
| 65 | if [ "$IS_CONTINUOUS_INTEGRATION" == 1 ]; then |
| 66 | "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh . patch |
| 67 | else |
| 68 | "$CI_ROOT"/script/static-checks/static-checks-coding-style-line-endings.sh |
| 69 | fi |
| 70 | |
| 71 | if [ "$?" != 0 ]; then |
| 72 | echo "Line ending test: FAILURE" |
| 73 | ((ERROR_COUNT++)) |
| 74 | else |
| 75 | echo "Line ending test: PASS" |
| 76 | fi |
| 77 | echo |
| 78 | |
| 79 | # Check coding style with cargo fmt |
| 80 | |
| 81 | "$CI_ROOT"/script/next-checks/next-checks-cargo-fmt.sh . |
| 82 | |
| 83 | if [ "$?" != 0 ]; then |
| 84 | echo "cargo fmt test: FAILURE" |
| 85 | ((ERROR_COUNT++)) |
| 86 | else |
| 87 | echo "cargo fmt test: PASS" |
| 88 | fi |
| 89 | echo |
| 90 | |
| 91 | # Check lints with clippy |
| 92 | |
| 93 | "$CI_ROOT"/script/next-checks/next-checks-clippy.sh . |
| 94 | |
| 95 | if [ "$?" != 0 ]; then |
| 96 | echo "Rust clippy: FAILURE" |
| 97 | ((ERROR_COUNT++)) |
| 98 | else |
| 99 | echo "Rust clippy: PASS" |
| 100 | fi |
| 101 | echo |
| 102 | |
| 103 | if [ "$ERROR_COUNT" != 0 ]; then |
| 104 | echo "Some static checks have failed." |
| 105 | exit 1 |
| 106 | fi |
| 107 | |
| 108 | exit 0 |