Loading scripts/check_format.sh +29 −3 Original line number Diff line number Diff line Loading @@ -3,10 +3,11 @@ PROJECT_SRC="$(pwd)/src" PROJECT_INCLUDE="$(pwd)/include" RUN_FORMAT=false CLANG_FORMAT_BIN="" usage_short() { echo " usage: check_format.sh [-h] [-s <PROJECT_SRC>] [-i <PROJECT_INCLUDE>] usage: check_format.sh [-h] [-s <PROJECT_SRC>] [-i <PROJECT_INCLUDE>] [-c <CLANG_FORMAT_BIN>] [--run_format] " } Loading @@ -24,6 +25,9 @@ optional arguments: -i <PROJECT_INCLUDE>, --include <PROJECT_INCLUDE> path to the include/ directory of the project (default: 'pwd/include') -c <CLANG_FORMAT_BIN>, --clang_format_path <CLANG_FORMAT_BIN> path to clang-format binary (default: looks for 'clang-format' or 'clang-format-10') -r, --run_format run clang-formatter before formatting check DISCLAIMER: FILES ARE MODIFIED IN PLACE! " Loading @@ -44,6 +48,15 @@ while [[ $# -gt 0 ]]; do shift # past argument shift # past value ;; -c | --clang_format_path) CLANG_FORMAT_BIN="$(readlink -mn "${2}")" if [[ ! -x $CLANG_FORMAT_BIN ]]; then echo "*** ERR: clang-format path $CLANG_FORMAT_BIN is not an executable! Exiting ..." exit 1 fi shift # past argument shift # past value ;; -r | --run_format) RUN_FORMAT=true shift # past argument Loading @@ -60,6 +73,19 @@ while [[ $# -gt 0 ]]; do done set -- "${POSITIONAL[@]}" # restore positional parameters # check for clang-format executable if it hasn't been set by the user if [[ -z $CLANG_FORMAT_BIN ]]; then CLANG_FORMAT_BIN=$(command -v clang-format) if [[ -z $CLANG_FORMAT_BIN ]]; then CLANG_FORMAT_BIN=$(command -v clang-format-10) # if it still doesn't exist exit if [[ -z $CLANG_FORMAT_BIN ]]; then echo "*** ERR: clang-format not found! Exiting ..." exit 1 fi fi fi FAIL=false echo "* Source directory: $PROJECT_SRC" Loading @@ -81,11 +107,11 @@ else fi echo "------------------------------------------" while IFS= read -r -d '' FILE; do UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <(clang-format -style=file "$FILE") | wc -l) UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <($CLANG_FORMAT_BIN -style=file "$FILE") | wc -l) if ((UNFORMATTED_LINES > 0)); then if [[ "$RUN_FORMAT" == true ]]; then echo "*** Reformatting $UNFORMATTED_LINES lines in '$FILE'" clang-format -i -style=file "$FILE" $CLANG_FORMAT_BIN -i -style=file "$FILE" else echo -n "$FILE " echo "$UNFORMATTED_LINES" Loading Loading
scripts/check_format.sh +29 −3 Original line number Diff line number Diff line Loading @@ -3,10 +3,11 @@ PROJECT_SRC="$(pwd)/src" PROJECT_INCLUDE="$(pwd)/include" RUN_FORMAT=false CLANG_FORMAT_BIN="" usage_short() { echo " usage: check_format.sh [-h] [-s <PROJECT_SRC>] [-i <PROJECT_INCLUDE>] usage: check_format.sh [-h] [-s <PROJECT_SRC>] [-i <PROJECT_INCLUDE>] [-c <CLANG_FORMAT_BIN>] [--run_format] " } Loading @@ -24,6 +25,9 @@ optional arguments: -i <PROJECT_INCLUDE>, --include <PROJECT_INCLUDE> path to the include/ directory of the project (default: 'pwd/include') -c <CLANG_FORMAT_BIN>, --clang_format_path <CLANG_FORMAT_BIN> path to clang-format binary (default: looks for 'clang-format' or 'clang-format-10') -r, --run_format run clang-formatter before formatting check DISCLAIMER: FILES ARE MODIFIED IN PLACE! " Loading @@ -44,6 +48,15 @@ while [[ $# -gt 0 ]]; do shift # past argument shift # past value ;; -c | --clang_format_path) CLANG_FORMAT_BIN="$(readlink -mn "${2}")" if [[ ! -x $CLANG_FORMAT_BIN ]]; then echo "*** ERR: clang-format path $CLANG_FORMAT_BIN is not an executable! Exiting ..." exit 1 fi shift # past argument shift # past value ;; -r | --run_format) RUN_FORMAT=true shift # past argument Loading @@ -60,6 +73,19 @@ while [[ $# -gt 0 ]]; do done set -- "${POSITIONAL[@]}" # restore positional parameters # check for clang-format executable if it hasn't been set by the user if [[ -z $CLANG_FORMAT_BIN ]]; then CLANG_FORMAT_BIN=$(command -v clang-format) if [[ -z $CLANG_FORMAT_BIN ]]; then CLANG_FORMAT_BIN=$(command -v clang-format-10) # if it still doesn't exist exit if [[ -z $CLANG_FORMAT_BIN ]]; then echo "*** ERR: clang-format not found! Exiting ..." exit 1 fi fi fi FAIL=false echo "* Source directory: $PROJECT_SRC" Loading @@ -81,11 +107,11 @@ else fi echo "------------------------------------------" while IFS= read -r -d '' FILE; do UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <(clang-format -style=file "$FILE") | wc -l) UNFORMATTED_LINES=$(diff -u <(cat "$FILE") <($CLANG_FORMAT_BIN -style=file "$FILE") | wc -l) if ((UNFORMATTED_LINES > 0)); then if [[ "$RUN_FORMAT" == true ]]; then echo "*** Reformatting $UNFORMATTED_LINES lines in '$FILE'" clang-format -i -style=file "$FILE" $CLANG_FORMAT_BIN -i -style=file "$FILE" else echo -n "$FILE " echo "$UNFORMATTED_LINES" Loading