Hopefully prevent misformatted files from ever entering master again. (#356)

* Added tools/check_format.sh.

* Exit nonzero from format.sh if clang-format-11 not installed.

* Replace which with command -v.

* Fail check_format.sh if format.sh fails.

* Improve Jenkinsfile.

* Take exit 0 out of else in check_format.sh.

* Format flg_set.c to test new Jenkins environment.

* Fix formatter failed logic in check_format.sh.

* Format all misformatted files in master.

* Remove Summarize Problems stage from Jenkins.
I didn't realize Jenkins would not a run a subsequent stage if a
previous stage errored. This defeats the purpose of summarizing all
problems at the end, since this will only happen if there *are* no
problems.

* Use Post->Failure block to print all logs instead.

* Remove spurious semicolon in arms_hook.
This commit is contained in:
rylieb 2021-10-24 11:06:46 -06:00 committed by GitHub
parent ef53ba8261
commit 57a9fb7b34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 2 deletions

9
Jenkinsfile vendored
View File

@ -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()
}

View File

@ -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..."

23
tools/check_format.sh Executable file
View File

@ -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