-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathkani-fmt.sh
executable file
·52 lines (44 loc) · 1.36 KB
/
kani-fmt.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
#
# Runs `rustfmt` in our source crates and tests.
# The arguments given to this script are passed to rustfmt.
set -o errexit
set -o pipefail
set -o nounset
# Run from the repository root folder
ROOT_FOLDER=$(git rev-parse --show-toplevel)
cd ${ROOT_FOLDER}
# Parse arguments to check for --check flag
check_flag=""
for arg in "$@"; do
if [ "$arg" = "--check" ]; then
check_flag="--check"
break
fi
done
# Verify crates.
error=0
# Check all crates. Only fail at the end.
cargo fmt ${check_flag} || error=1
# Check test source files.
TESTS=("tests" "docs/src/tutorial")
# Add ignore patterns for code we don't want to format.
IGNORE=("*/perf/s2n-quic/*")
# Arguments for the find command for excluding the IGNORE paths
IGNORE_ARGS=()
for ignore in "${IGNORE[@]}"; do
IGNORE_ARGS+=(-not -path "$ignore")
done
for suite in "${TESTS[@]}"; do
# Find uses breakline to split between files. This ensures that we can
# handle files with space in their path.
set -f; IFS=$'\n'
files=($(find "${suite}" -name "*.rs" ${IGNORE_ARGS[@]}))
set +f; unset IFS
# Note: We set the configuration file here because some submodules have
# their own configuration file.
rustfmt --config-path rustfmt.toml ${check_flag} "${files[@]}" || error=1
done
exit $error