summaryrefslogtreecommitdiff
path: root/tools/warnings_count/check_new_warnings.sh
blob: 71801601be6e899ec04194d44d1afff314036c11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env 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.

# 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/../.."

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.
    -f    Run full build process
    -j N  use N jobs (does not support plain -j because you shouldn't use it anyway)
"
}

jobs=1
full=
run="make clean
    make rom"



while getopts "hfj:" opt
do
    case $opt in
    h)  show_help
        exit 0
        ;;
    f)  full="true"
        run="make distclean
    make setup
    make assets
    make disasm
    make rom
    make compress"
        ;;
    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
    $run
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
}

if [[ $full ]]; then
    make distclean
    make_warnings setup setup
    make_warnings assets assets
    make_warnings disasm disasm
    make_warnings rom build
    make_warnings compress compress
else
    make clean
    make_warnings rom build
fi


if [[ $full ]]; then
    $COMPARE_WARNINGS setup
    $COMPARE_WARNINGS assets
    $COMPARE_WARNINGS disasm
    $COMPARE_WARNINGS build
    $COMPARE_WARNINGS compress
else
    $COMPARE_WARNINGS build
fi