mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-29 03:36:40 +00:00
Improve clang-format checking script
This commit is contained in:
parent
cd7fe60134
commit
afa1b0077d
2 changed files with 14 additions and 14 deletions
|
@ -127,6 +127,8 @@ Clang_Format:
|
||||||
key: Ubuntu_Clang_Format.ubuntu_22.04.v1
|
key: Ubuntu_Clang_Format.ubuntu_22.04.v1
|
||||||
paths:
|
paths:
|
||||||
- apt-cache/
|
- apt-cache/
|
||||||
|
variables:
|
||||||
|
CLANG_FORMAT: clang-format-14
|
||||||
before_script:
|
before_script:
|
||||||
- CI/install_debian_deps.sh openmw-clang-format
|
- CI/install_debian_deps.sh openmw-clang-format
|
||||||
script:
|
script:
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
CLANG_FORMAT="clang-format-14"
|
CLANG_FORMAT="${CLANG_FORMAT:-clang-format}"
|
||||||
HAS_DIFFS=0
|
HAS_DIFFS=0
|
||||||
|
|
||||||
|
check_format_file() {
|
||||||
|
local item=$1
|
||||||
|
"$CLANG_FORMAT" --dry-run -Werror "$item" &>/dev/null
|
||||||
|
if [[ $? = 1 ]]; then
|
||||||
|
"${CLANG_FORMAT}" "${item}" | git diff --color=always --no-index "${item}" -
|
||||||
|
HAS_DIFFS=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
check_format() {
|
check_format() {
|
||||||
local path=$1
|
local path=$1
|
||||||
for item in $(find $path -type f -name "*");
|
for item in $(find "$path" -type f -name "*");
|
||||||
do
|
do
|
||||||
if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then
|
if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then
|
||||||
echo "Checking code formatting on $item"
|
check_format_file "$item" &
|
||||||
$CLANG_FORMAT --dry-run -Werror "$item"
|
|
||||||
if [[ $? = 1 ]]; then
|
|
||||||
local tempfile=$(mktemp)
|
|
||||||
# Avoid having different modes in the diff.
|
|
||||||
chmod --reference="$item" "$tempfile"
|
|
||||||
# Generate diff
|
|
||||||
$CLANG_FORMAT "$item" > "$tempfile"
|
|
||||||
git diff --color=always --no-index $item $tempfile
|
|
||||||
rm -f "$tempfile"
|
|
||||||
HAS_DIFFS=1
|
|
||||||
fi
|
|
||||||
fi;
|
fi;
|
||||||
done;
|
done;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue