mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-30 04:06:33 +08:00
filtering files for code check seperately to enable fast use of git pre-commit hook to check code style
ask user to install pre-commit hook when code style is checked
This commit is contained in:
+1
-1
@@ -61,7 +61,7 @@ env:
|
|||||||
script:
|
script:
|
||||||
- ccache -M 1GB; ccache -z
|
- ccache -M 1GB; ccache -z
|
||||||
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
|
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then
|
||||||
docker run --rm -v `pwd`:`pwd`:rw -v $HOME/.ccache:$HOME/.ccache:rw -e CCACHE_DIR=$HOME/.ccache -e GIT_SUBMODULES_ARE_EVIL=1 -w=`pwd` --user=$UID -it ${DOCKER_REPO} /bin/bash -c "make check_qgc_firmware VECTORCONTROL=1";
|
docker run --rm -v `pwd`:`pwd`:rw -v $HOME/.ccache:$HOME/.ccache:rw -e CCACHE_DIR=$HOME/.ccache -e CI=true -e GIT_SUBMODULES_ARE_EVIL=1 -w=`pwd` --user=$UID -it ${DOCKER_REPO} /bin/bash -c "make check_qgc_firmware VECTORCONTROL=1";
|
||||||
elif [ "${TRAVIS_OS_NAME}" = "osx" ]; then
|
elif [ "${TRAVIS_OS_NAME}" = "osx" ]; then
|
||||||
make tests;
|
make tests;
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -283,12 +283,10 @@ quick_check: check_px4fmu-v2_default check_px4fmu-v4_default check_posix_sitl_de
|
|||||||
|
|
||||||
check_format:
|
check_format:
|
||||||
$(call colorecho,"Checking formatting with astyle")
|
$(call colorecho,"Checking formatting with astyle")
|
||||||
@./Tools/fix_code_style.sh
|
|
||||||
@./Tools/check_code_style_all.sh
|
@./Tools/check_code_style_all.sh
|
||||||
|
|
||||||
format:
|
format:
|
||||||
$(call colorecho,"Formatting with astyle")
|
$(call colorecho,"Formatting with astyle")
|
||||||
@./Tools/fix_code_style.sh
|
|
||||||
@./Tools/check_code_style_all.sh --fix
|
@./Tools/check_code_style_all.sh --fix
|
||||||
|
|
||||||
check_%:
|
check_%:
|
||||||
|
|||||||
+10
-16
@@ -1,29 +1,23 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
file=$1
|
FILE=$1
|
||||||
|
|
||||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||||
|
|
||||||
if [ -f "$file" ];
|
if [ -f "$FILE" ]; then
|
||||||
then
|
${DIR}/fix_code_style.sh --dry-run $FILE | grep --quiet Formatted
|
||||||
${DIR}/fix_code_style.sh --dry-run $file | grep --quiet Formatted
|
if [[ $? -eq 0 ]]; then
|
||||||
if [[ $? -eq 0 ]]
|
${DIR}/fix_code_style.sh --quiet < $FILE > $FILE.pretty
|
||||||
then
|
|
||||||
${DIR}/fix_code_style.sh --quiet < $file > $file.pretty
|
|
||||||
|
|
||||||
echo
|
echo
|
||||||
git --no-pager diff --no-index --minimal --histogram --color=always $file $file.pretty
|
git --no-pager diff --no-index --minimal --histogram --color=always $FILE $FILE.pretty
|
||||||
|
rm -f $FILE.pretty
|
||||||
echo
|
echo
|
||||||
|
|
||||||
rm -f $file.pretty
|
if [[ $PX4_ASTYLE_FIX -eq 1 ]]; then
|
||||||
|
${DIR}/fix_code_style.sh $FILE
|
||||||
if [[ $PX4_ASTYLE_FIX -eq 1 ]]
|
|
||||||
then
|
|
||||||
${DIR}/fix_code_style.sh $file
|
|
||||||
else
|
else
|
||||||
echo $file 'bad formatting, please run "./Tools/fix_code_style.sh' $file'"'
|
echo $FILE 'bad formatting, please run "make format" or "./Tools/fix_code_style.sh' $FILE'"'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,55 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
ASTYLE_VER_REQUIRED="Artistic Style Version 2.05.1"
|
||||||
|
astyle_ver() {
|
||||||
|
echo "PX4 requires ${ASTYLE_VER_REQUIRED}"
|
||||||
|
echo "You can get the correct version here: https://github.com/PX4/astyle/releases/tag/2.05.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if astyle is installed
|
||||||
|
condition=$(which astyle 2>/dev/null | grep -v "not found" | wc -l)
|
||||||
|
if [ $condition -eq 0 ]; then
|
||||||
|
echo "astyle is not installed"
|
||||||
|
astyle_ver
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
ASTYLE_VER=`astyle --version`
|
||||||
|
|
||||||
|
if [ "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED" ]; then
|
||||||
|
echo "Error: you're using ${ASTYLE_VER}"
|
||||||
|
astyle_ver
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
CI="${CI:-false}"
|
||||||
|
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
||||||
|
|
||||||
if [[ "$@" == "--fix" ]]
|
if [[ "$@" == "--fix" ]]
|
||||||
then
|
then
|
||||||
export PX4_ASTYLE_FIX=1
|
export PX4_ASTYLE_FIX=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
||||||
|
|
||||||
find src \
|
# install git pre-commit hook
|
||||||
-path src/lib/DriverFramework -prune -o \
|
HOOK_FILE="$DIR/../.git/hooks/pre-commit"
|
||||||
-path src/lib/ecl -prune -o \
|
if [ ! -f $HOOK_FILE ] && [ "$CI" != "true" ]; then
|
||||||
-path src/lib/external_lgpl -prune -o \
|
echo ""
|
||||||
-path src/lib/mathlib -prune -o \
|
echo -e "\033[31mNinja tip: add a git pre-commit hook to automatically check code style\033[0m"
|
||||||
-path src/lib/matrix -prune -o \
|
echo -e "Would you like to install one now? (\033[94mcp ./Tools/pre-commit .git/hooks/pre-commit\033[0m): [y/\033[1mN\033[0m]"
|
||||||
-path src/modules/attitude_estimator_ekf -prune -o \
|
|
||||||
-path src/modules/commander -prune -o \
|
|
||||||
-path src/examples/ekf_att_pos_estimator -prune -o \
|
|
||||||
-path src/examples/attitude_estimator_ekf -prune -o \
|
|
||||||
-path src/modules/navigator -prune -o \
|
|
||||||
-path src/modules/sdlog2 -prune -o \
|
|
||||||
-path src/modules/uavcan -prune -o \
|
|
||||||
-path src/modules/uavcan/libuavcan -prune -o \
|
|
||||||
-type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) \
|
|
||||||
-not -name '*generated.h' \
|
|
||||||
-not -name '*uthash.h' \
|
|
||||||
-not -name '*utstring.h' \
|
|
||||||
-not -name '*utlist.h' \
|
|
||||||
-not -name '*utarray.h' \
|
|
||||||
-print0 | xargs -0 -n 1 -P 8 -I % ${DIR}/check_code_style.sh %
|
|
||||||
|
|
||||||
|
read user_cmd
|
||||||
|
if [ "$user_cmd" == "y" ]; then
|
||||||
|
echo -e "copying ./Tools/pre-commit -> .git/hooks/pre-commit"
|
||||||
|
cp $DIR/pre-commit $HOOK_FILE
|
||||||
|
echo -e "\033[94mGreat, hook installed!\033[0m (checking style now)"
|
||||||
|
else
|
||||||
|
echo -e "\033[94mOk, I will remind you again later!\033[0m (checking style now)"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
${DIR}/files_to_check_code_style.sh | xargs -n 1 -P 8 -I % ${DIR}/check_code_style.sh %
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "Format checks passed"
|
echo "Format checks passed"
|
||||||
|
|||||||
Executable
+28
@@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -eu
|
||||||
|
|
||||||
|
PATTERN="-e ."
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]
|
||||||
|
then
|
||||||
|
PATTERN="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec find src \
|
||||||
|
-path src/examples/attitude_estimator_ekf -prune -o \
|
||||||
|
-path src/examples/ekf_att_pos_estimator -prune -o \
|
||||||
|
-path src/lib/DriverFramework -prune -o \
|
||||||
|
-path src/lib/ecl -prune -o \
|
||||||
|
-path src/lib/external_lgpl -prune -o \
|
||||||
|
-path src/lib/mathlib -prune -o \
|
||||||
|
-path src/lib/matrix -prune -o \
|
||||||
|
-path src/modules/attitude_estimator_ekf -prune -o \
|
||||||
|
-path src/modules/commander -prune -o \
|
||||||
|
-path src/modules/mavlink -prune -o \
|
||||||
|
-path src/modules/navigator -prune -o \
|
||||||
|
-path src/modules/sdlog2 -prune -o \
|
||||||
|
-path src/modules/systemlib/uthash -prune -o \
|
||||||
|
-path src/modules/uavcan -prune -o \
|
||||||
|
-path src/modules/uavcan/libuavcan -prune -o \
|
||||||
|
-type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) | grep $PATTERN
|
||||||
|
|
||||||
@@ -1,14 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
ASTYLE_VER=`astyle --version`
|
|
||||||
ASTYLE_VER_REQUIRED="Artistic Style Version 2.05.1"
|
|
||||||
|
|
||||||
if [ "$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED" ]; then
|
|
||||||
echo "Error: you're using ${ASTYLE_VER}, but PX4 requires ${ASTYLE_VER_REQUIRED}"
|
|
||||||
echo "You can get the correct version here: https://github.com/PX4/astyle/releases/tag/2.05.1"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $# -eq 0 ]] ; then
|
if [[ $# -eq 0 ]] ; then
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
+54
-16
@@ -1,26 +1,64 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# An example hook script to verify what is about to be committed.
|
||||||
|
# Called by "git commit" with no arguments. The hook should
|
||||||
|
# exit with non-zero status after issuing an appropriate message if
|
||||||
|
# it wants to stop the commit.
|
||||||
|
#
|
||||||
|
# To enable this hook, rename this file to "pre-commit".
|
||||||
|
|
||||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||||
then
|
then
|
||||||
against=HEAD
|
against=HEAD
|
||||||
else
|
else
|
||||||
# Initial commit: diff against an empty tree object
|
# Initial commit: diff against an empty tree object
|
||||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# If you want to allow non-ascii filenames set this variable to true.
|
||||||
|
allownonascii=$(git config hooks.allownonascii)
|
||||||
|
|
||||||
# Redirect output to stderr.
|
# Redirect output to stderr.
|
||||||
exec 1>&2
|
exec 1>&2
|
||||||
|
|
||||||
CHANGED_FILES=`git diff --cached --name-only --diff-filter=ACM $against | grep '\.c\|\.cpp\|\.h\|\.hpp'`
|
# Cross platform projects tend to avoid non-ascii filenames; prevent
|
||||||
FAILED=0
|
# them from being added to the repository. We exploit the fact that the
|
||||||
if [ ! -z "$CHANGED_FILES" -a "$CHANGED_FILES" != " " ]; then
|
# printable range starts at the space character and ends with tilde.
|
||||||
for FILE in $CHANGED_FILES; do
|
if [ "$allownonascii" != "true" ] &&
|
||||||
./Tools/fix_code_style.sh --quiet < $FILE > $FILE.pretty
|
# Note that the use of brackets around a tr range is ok here, (it's
|
||||||
diff -u $FILE $FILE.pretty || FAILED=1
|
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||||
rm -f $FILE.pretty
|
# the square bracket bytes happen to fall in the designated range.
|
||||||
if [ $FAILED -ne 0 ]; then
|
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||||
echo "There are code formatting errors. Please fix them by running ./Tools/fix_code_style.sh $FILE"
|
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||||
exit $FAILED
|
then
|
||||||
fi
|
echo "Error: Attempt to add a non-ascii file name."
|
||||||
done
|
echo
|
||||||
|
echo "This can cause problems if you want to work"
|
||||||
|
echo "with people on other platforms."
|
||||||
|
echo
|
||||||
|
echo "To be portable it is advisable to rename the file ..."
|
||||||
|
echo
|
||||||
|
echo "If you know what you are doing you can disable this"
|
||||||
|
echo "check using:"
|
||||||
|
echo
|
||||||
|
echo " git config hooks.allownonascii true"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
exit 0
|
|
||||||
|
# If there are whitespace errors, print the offending file names and fail.
|
||||||
|
git diff-index --check --cached $against --
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check for code style, only in changed files
|
||||||
|
for i in `git diff --cached --name-only --diff-filter=ACM`
|
||||||
|
do
|
||||||
|
./Tools/files_to_check_code_style.sh $i | xargs -n 1 -P 8 -I % ./Tools/check_code_style.sh %
|
||||||
|
if [ $? -ne 0 ]
|
||||||
|
then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ dependencies:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
override:
|
override:
|
||||||
- docker run --rm -v `pwd`:`pwd`:rw -w=`pwd` --user=$UID -it px4io/px4-dev-nuttx-gcc4.9 /bin/bash -c "make quick_check"
|
- docker run --rm -v `pwd`:`pwd`:rw -e CI=true -w=`pwd` --user=$UID -it px4io/px4-dev-nuttx-gcc4.9 /bin/bash -c "make quick_check"
|
||||||
|
|
||||||
general:
|
general:
|
||||||
artifacts:
|
artifacts:
|
||||||
|
|||||||
Reference in New Issue
Block a user