-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redesign CI format check/update scripts according to review
- Loading branch information
theohax
committed
Sep 29, 2021
1 parent
c9236bb
commit e4d8f71
Showing
15 changed files
with
306 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################################### | ||
|
||
source "$(dirname "$BASH_SOURCE")/impl/common.sh" | ||
source "$(dirname "$BASH_SOURCE")/impl/clang-format.sh" | ||
|
||
################################################################################################### | ||
|
||
does_clang_format_exist | ||
if [[ $? == 0 ]]; then | ||
clang_format_check | ||
result=$? | ||
|
||
if [[ $result == 2 ]]; then | ||
exit $result | ||
fi | ||
|
||
if [[ $result == 1 ]]; then | ||
echo "Source code formatting differs from expected - please run ci/clang-format-do.sh" | ||
exit 1 | ||
fi | ||
|
||
echo "clang-format check passed" | ||
fi | ||
|
||
################################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################################### | ||
|
||
source "$(dirname "$BASH_SOURCE")/impl/common.sh" | ||
source "$(dirname "$BASH_SOURCE")/impl/clang-format.sh" | ||
|
||
################################################################################################### | ||
|
||
does_clang_format_exist | ||
if [[ $? == 0 ]]; then | ||
clang_format_do | ||
fi | ||
|
||
################################################################################################### |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################################### | ||
|
||
source "$(dirname "$BASH_SOURCE")/impl/common.sh" | ||
source "$(dirname "$BASH_SOURCE")/impl/cmake-format.sh" | ||
|
||
################################################################################################### | ||
|
||
does_cmake_format_exist | ||
if [[ $? == 0 ]]; then | ||
cmake_format_check | ||
result=$? | ||
|
||
if [[ $result == 2 ]]; then | ||
exit $result | ||
fi | ||
|
||
if [[ $result == 1 ]]; then | ||
echo "CMake formatting differs from expected - please run ci/cmake-format-do.sh" | ||
exit 1 | ||
fi | ||
|
||
echo "cmake-format check passed" | ||
fi | ||
|
||
################################################################################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################################### | ||
|
||
source "$(dirname "$BASH_SOURCE")/impl/common.sh" | ||
source "$(dirname "$BASH_SOURCE")/impl/cmake-format.sh" | ||
|
||
################################################################################################### | ||
|
||
does_cmake_format_exist | ||
if [[ $? == 0 ]]; then | ||
cmake_format_do | ||
fi | ||
|
||
################################################################################################### |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
#!/usr/bin/env bash | ||
|
||
################################################################################################### | ||
|
||
CLANG_FORMAT="" | ||
CLANG_FORMAT_VERSION="12" | ||
|
||
################################################################################################### | ||
|
||
does_clang_format_exist() | ||
{ | ||
local attempts=("clang-format" "clang-format-$CLANG_FORMAT_VERSION") | ||
for itr in ${attempts[@]}; do | ||
version=$(_is_clang_format_usable $itr $CLANG_FORMAT_VERSION) | ||
if [[ $? == 1 ]]; then | ||
continue | ||
fi | ||
|
||
if [[ $? == 0 ]]; then | ||
CLANG_FORMAT=$itr | ||
break | ||
fi | ||
|
||
echo "Detected '$itr' with version '$version' " \ | ||
"(different than '$CLANG_FORMAT_VERSION'), skipping it." | ||
done | ||
|
||
if [[ -z $CLANG_FORMAT ]]; then | ||
echo "No 'clang-format' of version '$CLANG_FORMAT_VERSION' could be detected in your " \ | ||
"PATH. Try 'sudo apt-get install clang-format-$CLANG_FORMAT_VERSION' or, if macOS, " \ | ||
"'brew install clang-format'. Or up/down grade, if installed differently." | ||
return 1 | ||
fi | ||
|
||
echo "Using '$CLANG_FORMAT' version '$CLANG_FORMAT_VERSION'" | ||
return 0 | ||
} | ||
|
||
################################################################################################### | ||
|
||
clang_format_do() | ||
{ | ||
_clang_format_perform "do" | ||
} | ||
|
||
################################################################################################### | ||
|
||
clang_format_check() | ||
{ | ||
_clang_format_perform "check" | ||
} | ||
|
||
################################################################################################### | ||
|
||
_is_clang_format_usable() | ||
{ | ||
if [[ $(builtin type -p $1) ]]; then | ||
local output=$($1 --version) | ||
if [[ $output =~ ^(.)*$2(.)*$ ]]; then | ||
return 0 | ||
fi | ||
|
||
echo $output | ||
return 1 | ||
fi | ||
|
||
return 2 | ||
} | ||
|
||
################################################################################################### | ||
|
||
_clang_format_perform() | ||
{ | ||
if [[ -z "$CLANG_FORMAT" ]]; then | ||
echo "Logic error: '_lang_format_perform' called, but 'CLANG_FORMAT' " \ | ||
"is empty. Have you called 'does_clang_format_exist'?" | ||
return 2 | ||
fi | ||
|
||
find "$ROOTPATH/nano" \( -iname "*.h" \ | ||
-o \ | ||
-iname "*.hpp" \ | ||
-o \ | ||
-iname "*.cpp" \ | ||
\) \ | ||
-print0 | | ||
while read -d $'\0' file | ||
do | ||
if [[ $1 == "do" ]]; then | ||
"$CLANG_FORMAT" -i "$file" | ||
elif [[ $1 == "check" ]]; then | ||
"$CLANG_FORMAT" -style=file -Werror --dry-run "$file" | ||
if [[ $? != 0 ]]; then | ||
return 1 | ||
fi | ||
else | ||
echo "Logic error: '_clang_format_perform' called " \ | ||
"with neither 'do' nor 'check' as argument, but '$1'" | ||
return 2 | ||
fi | ||
done | ||
} | ||
|
||
################################################################################################### |
Oops, something went wrong.