mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-21 06:53:34 +08:00
astyle scripting move to Tools/astyle
This commit is contained in:
committed by
Lorenz Meier
parent
a02caff1bc
commit
9f15c572a3
@@ -0,0 +1,18 @@
|
||||
indent=force-tab=8
|
||||
style=linux
|
||||
indent-preprocessor
|
||||
indent-cases
|
||||
break-blocks=all
|
||||
pad-oper
|
||||
pad-header
|
||||
unpad-paren
|
||||
keep-one-line-blocks
|
||||
keep-one-line-statements
|
||||
align-pointer=name
|
||||
align-reference=name
|
||||
-n #--suffix=none
|
||||
ignore-exclude-errors-x
|
||||
lineend=linux
|
||||
exclude=EASTL
|
||||
add-brackets
|
||||
max-code-length=120
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
FILE=$1
|
||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
|
||||
if [ -f "$FILE" ]; then
|
||||
${DIR}/fix_code_style.sh --dry-run $FILE | grep --quiet Formatted
|
||||
if [[ $? -eq 0 ]]; then
|
||||
${DIR}/fix_code_style.sh --quiet < $FILE > $FILE.pretty
|
||||
|
||||
echo
|
||||
git --no-pager diff --no-index --minimal --histogram --color=always $FILE $FILE.pretty
|
||||
rm -f $FILE.pretty
|
||||
echo
|
||||
|
||||
if [[ $PX4_ASTYLE_FIX -eq 1 ]]; then
|
||||
${DIR}/fix_code_style.sh $FILE
|
||||
else
|
||||
echo $FILE 'bad formatting, please run "make format" or "./Tools/astyle/fix_code_style.sh' $FILE'"'
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
set -eu
|
||||
|
||||
# Check for the latest astyle version
|
||||
ASTYLE_VER_REQUIRED_1="Artistic Style Version 2.06"
|
||||
ASTYLE_VER_REQUIRED_2="Artistic Style Version 3.0"
|
||||
ASTYLE_VER_REQUIRED_3="Artistic Style Version 3.0.1"
|
||||
|
||||
astyle_ver() {
|
||||
echo "PX4 requires at least ${ASTYLE_VER_REQUIRED_1}"
|
||||
echo "You can get the correct version here: https://sourceforge.net/projects/astyle/files/astyle/astyle%202.06/"
|
||||
}
|
||||
|
||||
# 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_1" -a \
|
||||
"$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_2" -a \
|
||||
"$ASTYLE_VER" != "$ASTYLE_VER_REQUIRED_3" ];
|
||||
then
|
||||
echo "Error: you're using ${ASTYLE_VER}"
|
||||
echo "but should be using ${ASTYLE_VER_REQUIRED_1}, ${ASTYLE_VER_REQUIRED_2}, or ${ASTYLE_VER_REQUIRED_3} instead"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
CI="${CI:-false}"
|
||||
DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
||||
|
||||
if [[ "$@" == "--fix" ]]
|
||||
then
|
||||
export PX4_ASTYLE_FIX=1
|
||||
fi
|
||||
|
||||
|
||||
# install git pre-commit hook
|
||||
HOOK_FILE="$DIR/../../.git/hooks/pre-commit"
|
||||
if [ ! -f $HOOK_FILE ] && [ "$CI" != "true" ]; then
|
||||
echo ""
|
||||
echo -e "\033[31mNinja tip: add a git pre-commit hook to automatically check code style\033[0m"
|
||||
echo -e "Would you like to install one now? (\033[94mcp ./Tools/astyle/pre-commit .git/hooks/pre-commit\033[0m): [y/\033[1mN\033[0m]"
|
||||
|
||||
read user_cmd
|
||||
if [ "$user_cmd" == "y" ]; then
|
||||
echo -e "copying ./Tools/astyle/pre-commit -> .git/hooks/pre-commit"
|
||||
mkdir -p $DIR/../.git/hooks
|
||||
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
|
||||
echo "Format checks passed"
|
||||
exit 0
|
||||
fi
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
#!/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/matrix -prune -o \
|
||||
-path src/lib/micro-CDR -prune -o \
|
||||
-path src/modules/micrortps_bridge/micrortps_agent -prune -o \
|
||||
-path src/modules/commander -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 \
|
||||
-path src/modules/uavcanesc -o \
|
||||
-path src/modules/uavcannode -o \
|
||||
-type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.hpp" \) | grep $PATTERN
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $# -eq 0 ]] ; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
astyle \
|
||||
--options=$DIR/astylerc \
|
||||
--preserve-date \
|
||||
$*
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
#!/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
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
# Initial commit: diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
# If you want to allow non-ascii filenames set this variable to true.
|
||||
allownonascii=$(git config hooks.allownonascii)
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
# Cross platform projects tend to avoid non-ascii filenames; prevent
|
||||
# them from being added to the repository. We exploit the fact that the
|
||||
# printable range starts at the space character and ends with tilde.
|
||||
if [ "$allownonascii" != "true" ] &&
|
||||
# Note that the use of brackets around a tr range is ok here, (it's
|
||||
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
||||
# the square bracket bytes happen to fall in the designated range.
|
||||
test $(git diff --cached --name-only --diff-filter=A -z $against |
|
||||
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
|
||||
then
|
||||
echo "Error: Attempt to add a non-ascii file name."
|
||||
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
|
||||
|
||||
# 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/astyle/files_to_check_code_style.sh $i | xargs -n 1 -P 8 -I % ./Tools/astyle/check_code_style.sh %
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
Reference in New Issue
Block a user