From 25afa196f6829c909cba0949e400d339b74f8980 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Wed, 19 May 2021 22:14:20 -0400 Subject: [PATCH] Make Jenkins check if a PR will add new warnings (#150) * warning count * update warnings * Update warnings * Use `tee` * Suggestions of zbanks * I hope this will fix it --- Jenkinsfile | 17 ++++++++- Makefile | 3 +- tools/Makefile | 2 +- tools/warnings_count/.gitignore | 3 ++ tools/warnings_count/check_new_warnings.sh | 14 +++++++ tools/warnings_count/compare_warnings.py | 35 +++++++++++++++++ .../warnings_count/update_current_warnings.sh | 11 ++++++ .../warnings_count/warnings_build_current.txt | 2 + .../warnings_count/warnings_setup_current.txt | 38 +++++++++++++++++++ 9 files changed, 122 insertions(+), 3 deletions(-) create mode 100644 tools/warnings_count/.gitignore create mode 100755 tools/warnings_count/check_new_warnings.sh create mode 100755 tools/warnings_count/compare_warnings.py create mode 100755 tools/warnings_count/update_current_warnings.sh create mode 100644 tools/warnings_count/warnings_build_current.txt create mode 100644 tools/warnings_count/warnings_setup_current.txt diff --git a/Jenkinsfile b/Jenkinsfile index e8c8862271..60fca320f3 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -10,9 +10,24 @@ pipeline { sh 'cp /usr/local/etc/roms/mm.us.rev1.z64 baserom.mm.us.rev1.z64' } } + stage('Setup') { + steps { + sh 'bash -c "make -j setup 2> >(tee tools/warnings_count/warnings_setup_new.txt)"' + } + } + 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' + } + } stage('Build') { steps { - sh 'make -j init' + sh 'bash -c "make -j all 2> >(tee tools/warnings_count/warnings_build_new.txt)"' + } + } + 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' } } stage('Report Progress') { diff --git a/Makefile b/Makefile index 64707e34a4..3bf8b9e3f9 100644 --- a/Makefile +++ b/Makefile @@ -208,7 +208,8 @@ assetclean: $(RM) -rf build/assets distclean: assetclean clean - $(RM) -rf baserom/ asm/ distclean/ + $(RM) -rf baserom/ asm/ expected/ + $(MAKE) -C tools clean ## Extraction step setup: diff --git a/tools/Makefile b/tools/Makefile index fc3771c751..0ad4a3f51f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -7,7 +7,7 @@ all: $(PROGRAMS) clean: $(RM) $(PROGRAMS) - $(RM) ZAPD/ZAPD.out + $(MAKE) -C ZAPD clean # Need to clean the above line later... mkldscript_SOURCES := mkldscript.c util.c diff --git a/tools/warnings_count/.gitignore b/tools/warnings_count/.gitignore new file mode 100644 index 0000000000..089b231f12 --- /dev/null +++ b/tools/warnings_count/.gitignore @@ -0,0 +1,3 @@ +# Generated warnings counters +warnings_setup_new.txt +warnings_build_new.txt diff --git a/tools/warnings_count/check_new_warnings.sh b/tools/warnings_count/check_new_warnings.sh new file mode 100755 index 0000000000..e5dc07e703 --- /dev/null +++ b/tools/warnings_count/check_new_warnings.sh @@ -0,0 +1,14 @@ +#!/bin/bash +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. + +DIR="$(dirname "$(readlink -f "$0")")" +cd "$DIR/../.." + +make distclean +make -j4 setup 2> tools/warnings_count/warnings_setup_new.txt +make -j4 all 2> tools/warnings_count/warnings_build_new.txt + +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_build_current.txt tools/warnings_count/warnings_build_new.txt diff --git a/tools/warnings_count/compare_warnings.py b/tools/warnings_count/compare_warnings.py new file mode 100755 index 0000000000..3f11423252 --- /dev/null +++ b/tools/warnings_count/compare_warnings.py @@ -0,0 +1,35 @@ +#!/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() diff --git a/tools/warnings_count/update_current_warnings.sh b/tools/warnings_count/update_current_warnings.sh new file mode 100755 index 0000000000..d00c491f46 --- /dev/null +++ b/tools/warnings_count/update_current_warnings.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e + +# This script should only be used when we need to modify the accepted amount of warnings. + +DIR="$(dirname "$(readlink -f "$0")")" +cd "$DIR/../.." + +make distclean +make setup 2> tools/warnings_count/warnings_setup_current.txt +make all 2> tools/warnings_count/warnings_build_current.txt diff --git a/tools/warnings_count/warnings_build_current.txt b/tools/warnings_count/warnings_build_current.txt new file mode 100644 index 0000000000..a5a5bcdb04 --- /dev/null +++ b/tools/warnings_count/warnings_build_current.txt @@ -0,0 +1,2 @@ +cc: Warning: -mips3 should not be used for ucode 32-bit compiles +cc: Warning: -mips3 should not be used for ucode 32-bit compiles diff --git a/tools/warnings_count/warnings_setup_current.txt b/tools/warnings_count/warnings_setup_current.txt new file mode 100644 index 0000000000..e55ca22837 --- /dev/null +++ b/tools/warnings_count/warnings_setup_current.txt @@ -0,0 +1,38 @@ +Submodule 'ZAPD' (https://github.com/zeldaret/ZAPD.git) registered for path 'tools/ZAPD' +Submodule 'tools/asm-differ' (https://github.com/simonlindholm/asm-differ.git) registered for path 'tools/asm-differ' +Submodule 'tools/asm-processor' (https://github.com/simonlindholm/asm-processor.git) registered for path 'tools/asm-processor' +Submodule 'tools/decomp-permuter' (https://github.com/simonlindholm/decomp-permuter) registered for path 'tools/decomp-permuter' +Cloning into '/home/jenkins/workspace/MM_PR-150/tools/ZAPD'... +Cloning into '/home/jenkins/workspace/MM_PR-150/tools/asm-processor'... +Cloning into '/home/jenkins/workspace/MM_PR-150/tools/asm-differ'... +Cloning into '/home/jenkins/workspace/MM_PR-150/tools/decomp-permuter'... +From https://github.com/zeldaret/ZAPD + * branch bbbbb046a54f99dcbc6cbcc765177d8b252546f0 -> FETCH_HEAD +From https://github.com/zeldaret/ZAPD + * branch bbbbb046a54f99dcbc6cbcc765177d8b252546f0 -> FETCH_HEAD +From https://github.com/simonlindholm/asm-differ + * branch 9d79eb9f539e5fa58fe63c62862661c5d9ce0d27 -> FETCH_HEAD +From https://github.com/simonlindholm/asm-processor + * branch f511734d56ebb152c2b0c5aab212a0fea2588513 -> FETCH_HEAD +From https://github.com/simonlindholm/decomp-permuter + * branch cbb41c125464c3cbe799d77fe2d661615f934720 -> FETCH_HEAD +vtxdis.c: In function ‘parse_int’: +vtxdis.c:41:9: warning: ‘strncpy’ specified bound 20 equals destination size [-Wstringop-truncation] + strncpy(outnum, &num[2], 20); + ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ +ZAPD/ZRoom/Commands/SetStartPositionList.cpp: In function ‘void __static_initialization_and_destruction_0(int, int)’: +ZAPD/ZRoom/Commands/SetStartPositionList.cpp:83:1: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without + } + ^ +ZAPD/ZRoom/Commands/SetActorList.cpp: In function ‘void __static_initialization_and_destruction_0(int, int)’: +ZAPD/ZRoom/Commands/SetActorList.cpp:164:1: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without + } + ^ +ZAPD/ZRoom/Commands/SetObjectList.cpp: In function ‘void __static_initialization_and_destruction_0(int, int)’: +ZAPD/ZRoom/Commands/SetObjectList.cpp:76:1: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without + } + ^ +ZAPD/ZRoom/Commands/SetTransitionActorList.cpp: In function ‘void __static_initialization_and_destruction_0(int, int)’: +ZAPD/ZRoom/Commands/SetTransitionActorList.cpp:105:1: note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without + } + ^