Improve check new warnings (#308)

* Change check_new_warnings to output stderr to console too

* Colour warnings and functions in check_new_warnings

* Remove unneeded prototype in EnDai

* Add multithreading options, colour to output, help

* Give Jenkins a script again

* Test

* Remove tput warnings, hopefully

* Try -T dumb

* Undo test warning
This commit is contained in:
EllipticEllipsis 2021-09-29 23:42:24 +01:00 committed by GitHub
parent 5c06a6b240
commit ef875bc221
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 142 additions and 47 deletions

6
Jenkinsfile vendored
View File

@ -17,7 +17,7 @@ pipeline {
}
stage('Check setup warnings') {
steps {
sh 'python3 tools/warnings_count/compare_warnings.py tools/warnings_count/warnings_setup_current.txt tools/warnings_count/warnings_setup_new.txt'
sh 'bash -c "./tools/warnings_count/compare_warnings.sh setup"'
}
}
stage('Disasm') {
@ -27,7 +27,7 @@ pipeline {
}
stage('Check disasm warnings') {
steps {
sh 'python3 tools/warnings_count/compare_warnings.py tools/warnings_count/warnings_disasm_current.txt tools/warnings_count/warnings_disasm_new.txt'
sh 'bash -c "./tools/warnings_count/compare_warnings.sh disasm"'
}
}
stage('Build') {
@ -37,7 +37,7 @@ pipeline {
}
stage('Check build warnings') {
steps {
sh 'python3 tools/warnings_count/compare_warnings.py tools/warnings_count/warnings_build_current.txt tools/warnings_count/warnings_build_new.txt'
sh 'bash -c "./tools/warnings_count/compare_warnings.sh build"'
}
}
stage('Report Progress') {

View File

@ -79,7 +79,7 @@ endif
# Check code syntax with host compiler
CHECK_WARNINGS := -Wall -Wextra -Wno-format-security -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-variable -Wno-missing-braces -Wno-int-conversion -Wno-unused-but-set-variable -Wno-unused-label
CC_CHECK := gcc -fno-builtin -fsyntax-only -funsigned-char -std=gnu90 -D _LANGUAGE_C -D NON_MATCHING $(IINC) -include stdarg.h $(CHECK_WARNINGS)
CC_CHECK := gcc -fno-builtin -fsyntax-only -funsigned-char -fdiagnostics-color -std=gnu90 -D _LANGUAGE_C -D NON_MATCHING $(IINC) -include stdarg.h $(CHECK_WARNINGS)
CPP := cpp
ELF2ROM := tools/buildtools/elf2rom

View File

@ -16,7 +16,6 @@ void EnDai_Update(Actor* thisx, GlobalContext* globalCtx);
void EnDai_Draw(Actor* thisx, GlobalContext* globalCtx);
void func_80B3F00C(EnDai* this, GlobalContext* globalCtx);
void func_80B3EEDC(EnDai* this, GlobalContext* globalCtx);
void func_80B3EF90(EnDai* this, GlobalContext* globalCtx);
extern AnimationHeader D_060107B0;

View File

@ -3,14 +3,103 @@ set -e
# This script can be used when you want to test locally the amount of warnings produced by your changes before doing a PR.
# Terminal colour codes
# when $TERM is empty (non-interactive shell), then expand tput with '-T xterm-256color'
[[ ${TERM}=="" ]] && TPUTTERM='-T dumb' \
|| TPUTTERM=''
declare -r BOLD=`tput ${TPUTTERM} bold`
declare -r RED=`tput ${TPUTTERM} setaf 1`
declare -r PURPLE=`tput ${TPUTTERM} setaf 5`
declare -r WHITE=`tput ${TPUTTERM} setaf 7`
declare -r BLINK=`tput ${TPUTTERM} blink`
declare -r RST=`tput ${TPUTTERM} sgr0`
DIR="$(dirname "$(readlink -f "$0")")"
cd "$DIR/../.."
make distclean
make setup 2> tools/warnings_count/warnings_setup_new.txt
make disasm 2> tools/warnings_count/warnings_disasm_new.txt
make all 2> tools/warnings_count/warnings_build_new.txt
COMPARE_WARNINGS="$DIR/compare_warnings.sh"
usage () {
echo "Usage: $0 [-h] [-j jobs]"
}
show_help () {
usage
echo "
Check for new warnings created.
Optional arguments:
-h Display this message and exit.
-j N use N jobs (does not support plain -j because you shouldn't use it anyway)
"
}
jobs=1
while getopts "hj:" opt
do
case $opt in
h) show_help
exit 0
;;
j) j_option_arg="$OPTARG"
if [[ ! "${j_option_arg}" =~ ^[0-9]*$ ]]
then
echo "Error: Option '-j' expects numeric argument, you gave: ${j_option_arg}"
exit 1
fi
jobs="$j_option_arg"
;;
?) usage
exit 2
;;
esac
done
shift $(($OPTIND - 1))
# Confirm run with -j jobs
echo "This will run
make distclean
make setup
make disasm
make all
using $jobs threads. This may take some time."
read -r -p "Is this okay? [Y/n]" response
response=${response,,} # tolower
if !([[ $response =~ ^(yes|y| ) ]] || [[ -z $response ]]); then
exit 0
fi
remove_ansi_codes () {
perl -pe '
s/\e\[[\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e]//g;
s/\e[PX^_].*?\e\\//g;
s/\e\][^\a]*(?:\a|\e\\)//g;
s/\e[\[\]A-Z\\^_@]//g;' $1
}
make_warnings () {
make $1 -j$jobs 2> >(tee tools/warnings_count/warnings_temp.txt) \
&& remove_ansi_codes tools/warnings_count/warnings_temp.txt > tools/warnings_count/warnings_$2_new.txt \
&& rm tools/warnings_count/warnings_temp.txt
}
make distclean
make_warnings setup setup
make_warnings disasm disasm
make_warnings all build
echo "
$(tput ${TPUTTERM} setaf 3)(lots of make output ${TPUTTERM} here...)
$RST"
$COMPARE_WARNINGS setup
$COMPARE_WARNINGS disasm
$COMPARE_WARNINGS build
python3 tools/warnings_count/compare_warnings.py tools/warnings_count/warnings_setup_current.txt tools/warnings_count/warnings_setup_new.txt
python3 tools/warnings_count/compare_warnings.py tools/warnings_count/warnings_disasm_current.txt tools/warnings_count/warnings_disasm_new.txt
python3 tools/warnings_count/compare_warnings.py tools/warnings_count/warnings_build_current.txt tools/warnings_count/warnings_build_new.txt

View File

@ -1,35 +0,0 @@
#!/usr/bin/env python3
import argparse
def countFileLines(filename: str) -> int:
with open(filename) as f:
return len(f.readlines())
def main():
parser = argparse.ArgumentParser()
parser.add_argument('currentwarnings', help="Name of file which contains the current warnings of the repo.")
parser.add_argument('newwarnings', help="Name of file which contains the *new* warnings of the repo.")
args = parser.parse_args()
currentLines = countFileLines(args.currentwarnings)
newLines = countFileLines(args.newwarnings)
if newLines > currentLines:
print()
print("There are more warnings now. Go fix them!")
print("\tCurrent warnings: " + str(currentLines))
print("\tNew warnings: " + str(newLines))
print()
print("If these warnings are needed to produce a matching build, run `tools/warnings_count/update_current_warnings.sh` and commit the updated files in `tools/warnings_count/`.")
print()
with open(args.newwarnings) as f:
print("Warnings:\n\n" + f.read())
print()
exit(-1)
print("There are no new warnings. Good Job!")
if __name__ == "__main__":
main()

View File

@ -0,0 +1,42 @@
#!/bin/bash
# Terminal colour codes
# when $TERM is empty (non-interactive shell), then expand tput with '-T xterm-256color'
[[ ${TERM}=="" ]] && TPUTTERM='-T dumb' \
|| TPUTTERM=''
declare -r BOLD=`tput ${TPUTTERM} bold`
declare -r RED=`tput ${TPUTTERM} setaf 1`
declare -r PURPLE=`tput ${TPUTTERM} setaf 5`
declare -r WHITE=`tput ${TPUTTERM} setaf 7`
declare -r BLINK=`tput ${TPUTTERM} blink`
declare -r RST=`tput ${TPUTTERM} sgr0`
read CURRENT_LINES CURRENT <<< $(wc -l "tools/warnings_count/warnings_$1_current.txt")
read NEW_LINES NEW <<< $(wc -l "tools/warnings_count/warnings_$1_new.txt")
if [ $NEW_LINES -le $CURRENT_LINES ]
then
echo "${BOLD}No new warnings added in $1, well done.${RST}
"
exit 0
else
CURRENT_NUM=$(grep -i 'warning' $CURRENT | wc -l)
NEW_NUM=$(grep -i 'warning' $NEW | wc -l)
EXTRA_NUM=$(( $NEW_NUM - $CURRENT_NUM ))
echo "${BOLD}${RED}There are $EXTRA_NUM new warnings in $1, please fix them!${RST}
${BOLD}Current warnings:${RST}"
cat $CURRENT
echo "${BOLD}
Total current warnings: $CURRENT_NUM
New warnings:${RST}"
cat "$NEW"
echo "${BOLD}
Total new warnings: $NEW_NUM ${RED}
Total extra warnings: $EXTRA_NUM ${RST}
${BOLD}
If these warnings are needed to produce a matching build, run 'tools/warnings_count/update_current_warnings.sh' and commit the updated files in 'tools/warnings_count/'.${RST}"
exit 1
fi