Skip to content

Commit

Permalink
Use docker so that you can clang-format using version 15 everywhere y…
Browse files Browse the repository at this point in the history
…ou are. (#585)

* Use docker so that you can clang-format using version 15 everywhere you are.

* cleaning/simplifying

* setting version to 15

* silencing command not found

* changing repo
  • Loading branch information
lemire authored Feb 16, 2024
1 parent 0c001a5 commit 201dd98
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Empty file added clang-format-ignore.txt
Empty file.
24 changes: 24 additions & 0 deletions tools/run-clangcldocker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
set -e
COMMAND=$*
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
MAINSOURCE=$SCRIPTPATH/..
ALL_ADA_FILES=$(cd $MAINSOURCE && git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|cc\|cpp\|hh\)\$" | grep -vFf clang-format-ignore.txt)

if clang-format-15 --version 2>/dev/null | grep -qF 'version 15.'; then
cd $MAINSOURCE; clang-format-15 --style=file --verbose -i "$@" $ALL_ADA_FILES
exit 0
elif clang-format --version 2>/dev/null | grep -qF 'version 15.'; then
cd $MAINSOURCE; clang-format --style=file --verbose -i "$@" $ALL_ADA_FILES
exit 0
fi
echo "Trying to use docker"
command -v docker >/dev/null 2>&1 || { echo >&2 "Please install docker. E.g., go to https://www.docker.com/products/docker-desktop Type 'docker' to diagnose the problem."; exit 1; }
docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; }

if [ -t 0 ]; then DOCKER_ARGS=-it; fi
docker pull kszonek/clang-format-15

docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" kszonek/clang-format-15 --style=file --verbose -i "$@" $ALL_ADA_FILES


0 comments on commit 201dd98

Please sign in to comment.