mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-06 01:50:38 +00:00
Add a 'clang_format_all.sh' script that checks version and formats files
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
#!/bin/sh
|
||||
|
||||
CLANG_MAJOR=3
|
||||
CLANG_MINOR=8
|
||||
|
||||
CLANG_FORMAT_VERSION=$CLANG_MAJOR.$CLANG_MINOR
|
||||
|
||||
# Locate the clang-format executable. We try:
|
||||
# - the existing value of $CLANG_FORMAT
|
||||
# - the first command line argument to the script
|
||||
# - in order:
|
||||
# clang-format-Maj.Min
|
||||
# clang-format-Maj
|
||||
# clang-format
|
||||
|
||||
# define a function to check the current $CLANG_FORMAT
|
||||
valid_clang_format() {
|
||||
if which $CLANG_FORMAT > /dev/null 2>&1; then
|
||||
if $CLANG_FORMAT --version | grep -q $CLANG_FORMAT_VERSION; then
|
||||
echo "Located $CLANG_FORMAT";
|
||||
return 0;
|
||||
fi
|
||||
fi
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ! valid_clang_format; then
|
||||
# if not valid yet, first try the command line parameter
|
||||
CLANG_FORMAT=$1
|
||||
fi;
|
||||
|
||||
if ! valid_clang_format; then
|
||||
# Next try the full version
|
||||
CLANG_FORMAT=clang-format-$CLANG_MAJOR.$CLANG_MINOR
|
||||
fi;
|
||||
|
||||
if ! valid_clang_format; then
|
||||
# Then -maj just in case
|
||||
CLANG_FORMAT=clang-format-$CLANG_MAJOR
|
||||
fi;
|
||||
|
||||
if ! valid_clang_format; then
|
||||
# Then finally with no version suffix
|
||||
CLANG_FORMAT=clang-format
|
||||
fi;
|
||||
|
||||
# Check if we have a valid $CLANG_FORMAT
|
||||
if ! valid_clang_format; then
|
||||
# If we didn't find one, bail out
|
||||
echo "Couldn't find correct clang-format version, was looking for $CLANG_FORMAT_VERSION"
|
||||
echo "Renderdoc requires a very specific clang-format version to ensure there isn't any"
|
||||
echo "variance between versions that can happen. You can install it as"
|
||||
echo "'clang-format-$CLANG_FORMAT_VERSION' so that it doesn't interfere with any other"
|
||||
echo "versions you might have installed, and this script will find it there"
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# Search through the code that should be formatted, exclude any non-renderdoc code.
|
||||
FILES=$(find qrenderdoc/ renderdoc/ renderdoccmd/ renderdocshim/ -type f -regex '.*\(/3rdparty/\|/official/\|resource.h\).*' -prune -o -regex '.*\.\(c\|cpp\|h\)$' -print)
|
||||
|
||||
$CLANG_FORMAT -i -style=file $FILES
|
||||
@@ -8,17 +8,36 @@ wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
|
||||
sudo apt-get update -qq
|
||||
sudo apt-get install --allow-unauthenticated -y -qq libx11-dev mesa-common-dev libgl1-mesa-dev qt56base qt56svg qt56x11extras libxcb-keysyms1-dev gdb clang-format-3.8 g++-6
|
||||
|
||||
# check last 100 commits are all correctly sized. First line must be no
|
||||
# longer than 72 characters, so it fits in git log and github history
|
||||
if git log --oneline | head -n 100 | cut -d ' ' -f2- | grep -q '.\{73\}'; then
|
||||
echo "***************************************************";
|
||||
echo "*** Some of your commit messages summaries are ***";
|
||||
echo "*** longer than 72 characters. ***";
|
||||
echo "*** Please shorten them so they fit <= 72 chars ***";
|
||||
echo "*** on the first line, with a longer summary in ***";
|
||||
echo "*** the body after a blank line. ***";
|
||||
echo "*** For more information see CONTRIBUTING.md. ***";
|
||||
echo "*** Thanks! ***";
|
||||
echo "*** ***";
|
||||
echo "*** Commit messages: ***";
|
||||
echo;
|
||||
git log --oneline | head -n 100 | cut -d ' ' -f2- | grep '.\{73\}'
|
||||
echo;
|
||||
echo "***************************************************";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
# check formatting matches clang-format-3.8. Since newer versions can have
|
||||
# changes in formatting even without any rule changes, we have to fix on a
|
||||
# single version.
|
||||
|
||||
clang-format-3.8 -i -style=file $(find qrenderdoc/ renderdoc/ renderdoccmd/ renderdocshim/ -type f -regex '.*\(/3rdparty/\|/official/\|resource.h\).*' -prune -o -regex '.*\.\(c\|cpp\|h\)$' -print)
|
||||
. ./scripts/clang_format_all.sh
|
||||
|
||||
git clean -f
|
||||
|
||||
# this swallows the exit code so we won't fail until we print the diff in
|
||||
# the next line, but allows us to print a friendlier message to anyone
|
||||
# looking at the build log
|
||||
# Print any diff here, so the error message below is the last thing
|
||||
git diff
|
||||
|
||||
git diff --quiet || (
|
||||
echo "***************************************************";
|
||||
echo "*** The code is not clean against clang-format ***";
|
||||
@@ -27,6 +46,5 @@ git diff --quiet || (
|
||||
echo "*** the relevant commits. Do not add a commit ***";
|
||||
echo "*** for just formatting fixes. Thanks! ***";
|
||||
echo "***************************************************";
|
||||
exit 1;
|
||||
)
|
||||
|
||||
git diff --exit-code
|
||||
|
||||
Reference in New Issue
Block a user