Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing compatibility issues #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions clang-format-all → clang-format-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ FMT=""
# that the version number be part of the command. We prefer clang-format if
# that's present, otherwise we work backwards from highest version to lowest
# version.
for clangfmt in clang-format{,-{4,3}.{9,8,7,6,5,4,3,2,1,0}}; do
if which "$clangfmt" &>/dev/null; then
for clangfmt in clang-format{,-{18..15}}; do
if command -v "$clangfmt" &>/dev/null; then
echo Formating with "$clangfmt"
FMT="$clangfmt"
break
fi
Expand All @@ -54,21 +55,21 @@ for dir in "$@"; do
done

# Find a dominating file, starting from a given directory and going up.
find-dominating-file() {
find_dominating_file() {
if [ -r "$1"/"$2" ]; then
return 0
fi
if [ "$1" = "/" ]; then
return 1
fi
find-dominating-file "$(realpath "$1"/..)" "$2"
find_dominating_file "$(realpath "$1"/..)" "$2"
return $?
}

# Run clang-format -i on all of the things
for dir in "$@"; do
pushd "${dir}" &>/dev/null
if ! find-dominating-file . .clang-format; then
pushd "${dir}" &>/dev/null || exit
if ! find_dominating_file . .clang-format; then
echo "Failed to find dominating .clang-format starting at $PWD"
continue
fi
Expand All @@ -80,5 +81,5 @@ for dir in "$@"; do
-o -name '*.hh' \
-o -name '*.hpp' \) \
-exec "${FMT}" -i '{}' \;
popd &>/dev/null
done
popd &>/dev/null || exit
done