diff --git a/Jenkinsfile b/Jenkinsfile index 555504de46..df06c6a096 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,6 +4,12 @@ pipeline { } stages { + stage('Check formatting') { + steps { + echo 'Checking formatting...' + sh 'bash -c "tools/check_format.sh 2>&1 >(tee tools/check_format.txt)"' + } + } stage('Copy ROM') { steps { echo 'Setting up ROM...' @@ -68,6 +74,9 @@ pipeline { } } post { + failure { + sh 'cat tools/check_format.txt tools/warnings_count/warnings_setup_new.txt tools/warnings_count/warnings_disasm_new.txt tools/warnings_count/warnings_build_new.txt' + } always { cleanWs() } diff --git a/format.sh b/format.sh index ed830a5025..89a0906ad1 100755 --- a/format.sh +++ b/format.sh @@ -1,15 +1,22 @@ #!/usr/bin/env bash +FORMAT_VER="11" FORMAT_OPTS="-i -style=file" TIDY_OPTS="-p . --fix --fix-errors" COMPILER_OPTS="-fno-builtin -std=gnu90 -Iinclude -Isrc -D_LANGUAGE_C -DNON_MATCHING" shopt -s globstar +if [ -z `command -v clang-format-${FORMAT_VER}` ] +then + echo "clang-format-${FORMAT_VER} not found. Exiting." + exit 1 +fi + if (( $# > 0 )); then echo "Formatting file(s) $*" echo "Running clang-format..." - clang-format-11 ${FORMAT_OPTS} "$@" + clang-format-${FORMAT_VER} ${FORMAT_OPTS} "$@" echo "Running clang-tidy..." clang-tidy ${TIDY_OPTS} "$@" -- ${COMPILER_OPTS} &> /dev/null echo "Adding missing final new lines..." @@ -20,7 +27,7 @@ fi echo "Formatting C files. This will take a bit" echo "Running clang-format..." -clang-format-11 ${FORMAT_OPTS} src/**/*.c +clang-format-${FORMAT_VER} ${FORMAT_OPTS} src/**/*.c echo "Running clang-tidy..." clang-tidy ${TIDY_OPTS} src/**/*.c -- ${COMPILER_OPTS} &> /dev/null echo "Adding missing final new lines..." diff --git a/tools/check_format.sh b/tools/check_format.sh new file mode 100755 index 0000000000..d8119e7434 --- /dev/null +++ b/tools/check_format.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +STATUSOLD=`git status --porcelain` +./format.sh +if [ $? -ne 0 ] +then + echo "Formatter failed. Exiting." + exit -1 +fi +STATUSNEW=`git status --porcelain` + +if [ "${STATUSOLD}" != "${STATUSNEW}" ]; +then + echo "" + echo "Misformatted files found. Run ./format.sh and verify codegen is not impacted." + echo "" + diff --unified=0 --label "Old git status" <(echo "${STATUSOLD}") --label "New git status" <(echo "${STATUSNEW}") + echo "" + echo "Exiting." + exit 1 +fi + +exit 0