Skip to content

Commit

Permalink
Error on mismatching formatter.
Browse files Browse the repository at this point in the history
  • Loading branch information
1uc committed Nov 4, 2024
1 parent cca821e commit 018103c
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bin/format.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#!/usr/bin/env bash
set -euo pipefail

clang_format_version="19.1.3"

script_dir="$(dirname "${BASH_SOURCE[0]}")"
venv_dir="$script_dir/../.clang-format-venv"

if [ ! -d "$venv_dir" ]; then
python3 -m venv "$venv_dir"
source "$venv_dir/bin/activate"
pip install clang-format==19.1.3
pip install clang-format=="$clang_format_version"
deactivate
fi

source "$venv_dir/bin/activate"

# Check if the installed version matches the expected version
installed_version="$(pip show clang-format | grep Version | cut -d ' ' -f 2)"

if [ "$installed_version" != "$clang_format_version" ]; then
echo "Error: clang-format version mismatch. Expected $clang_format_version, got $installed_version"
echo "Please remove the virtual environment and run the script again:"
echo " rm -r \"$venv_dir\" && \"$0\""
exit 1
fi

clang-format --version
for i in $(git ls-files | grep ".[ch]pp$"); do
clang-format -i "$i" > /dev/null 2>&1
Expand Down

0 comments on commit 018103c

Please sign in to comment.