Skip to content

Commit

Permalink
refactor: update run-clangcldocker.sh (#608)
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig authored Mar 12, 2024
1 parent da04b63 commit 4a97a78
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tools/run-clangcldocker.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#!/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)
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
ROOT_PATH=$SCRIPT_PATH/..
ALL_ADA_FILES=$(cd "$ROOT_PATH" && 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
cd "$ROOT_PATH"; 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
cd "$ROOT_PATH"; 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
if [ -t 0 ];
then DOCKER_ARGS=-it;
fi

docker pull kszonek/clang-format-15

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

0 comments on commit 4a97a78

Please sign in to comment.