Skip to content

Commit 57594ad

Browse files
committed
bin/check-warn.sh: compartmentalize and deduplicate
Move common sections into functions and use local to limit scope of certain variables. Signed-off-by: Randolph Sapp <[email protected]>
1 parent 7575543 commit 57594ad

File tree

1 file changed

+55
-34
lines changed

1 file changed

+55
-34
lines changed

bin/check-warn.sh

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,60 @@ usage()
2929
exit "$1"
3030
}
3131

32+
save_branch()
33+
{
34+
# get current branch name or commit ID
35+
_cbr=$(git branch | sed -n '/\* /s///p')
36+
if [[ "$_cbr" == "(HEAD detached"* ]]; then
37+
_cbr=$(git rev-parse HEAD)
38+
fi
39+
}
40+
3241
restore_branch()
3342
{
3443
[ -z "$_cbr" ] || git checkout "$_cbr"
3544
}
3645

46+
summary()
47+
{
48+
local _num
49+
50+
rm -f build/_new-warn.log
51+
diff --changed-group-format="%>" --unchanged-group-format="" \
52+
build/_a-warn.log build/_b-warn.log > build/_new-warn.log
53+
54+
_num=$(wc -l build/_new-warn.log)
55+
56+
echo
57+
echo "Found $_num new build WARNING(s)."
58+
echo
59+
60+
if [ "$_num" != "0" ]; then
61+
cat build/_new-warn.log
62+
fi
63+
}
64+
65+
generate_log()
66+
{
67+
local git_hash log_name log_path warning_log_path
68+
69+
git_hash=$1
70+
log_name=$2
71+
72+
log_path="build/${log_name}.log"
73+
warning_log_path="build/${log_name}-warn.log"
74+
75+
git checkout "${git_hash}" || exit 10
76+
77+
mkdir -p build
78+
79+
rm -f "${log_path}" "${warning_log_path}"
80+
make DEVFAMILY="${_dev}" OS="${_os}" clean
81+
make DEVFAMILY="${_dev}" OS="${_os}" config >> "${log_path}" 2>&1 || exit 12
82+
make DEVFAMILY="${_dev}" OS="${_os}" >> "${log_path}" 2>&1 || exit 13
83+
grep "WARNING:" "${log_path}" > "${warning_log_path}"
84+
}
85+
3786
main()
3887
{
3988
if [[ "$(head -1 Makefile 2> /dev/null)" != "# Makefile for Sphinx"* ]]
@@ -64,42 +113,13 @@ main()
64113
_old=$(git rev-parse HEAD)
65114
fi
66115

67-
# get current branch name or commit ID
68-
_cbr=$(git branch | sed -n '/\* /s///p')
69-
if [[ "$_cbr" == "(HEAD detached"* ]]; then
70-
_cbr=$(git rev-parse HEAD)
71-
fi
72-
73-
git checkout "${_old}" || exit 10
74-
75-
mkdir -p build
76-
77-
make DEVFAMILY="${_dev}" OS="${_os}" clean
78-
make DEVFAMILY="${_dev}" OS="${_os}" config > build/_a.log 2>&1 || exit 12
79-
make DEVFAMILY="${_dev}" OS="${_os}" >> build/_a.log 2>&1 || exit 13
80-
grep "WARNING:" build/_a.log > build/_a-warn.log
81-
82-
git checkout "${_new}" || exit 20
116+
save_branch
83117

84-
make DEVFAMILY="${_dev}" OS="${_os}" clean
85-
make DEVFAMILY="${_dev}" OS="${_os}" config > build/_b.log 2>&1 || exit 22
86-
make DEVFAMILY="${_dev}" OS="${_os}" >> build/_b.log 2>&1 || exit 23
87-
grep "WARNING:" build/_b.log > build/_b-warn.log
118+
generate_log "${_old}" "_a"
119+
generate_log "${_new}" "_b"
88120

89121
restore_branch
90-
91-
diff --changed-group-format="%>" --unchanged-group-format="" \
92-
build/_a-warn.log build/_b-warn.log > build/_new-warn.log
93-
94-
_num=$(wc -l build/_new-warn.log)
95-
96-
echo
97-
echo "Found $_num new build WARNING(s)."
98-
echo
99-
100-
if [ "$_num" != "0" ]; then
101-
cat build/_new-warn.log
102-
fi
122+
summary
103123
}
104124

105125
while [ "$#" -gt 0 ]; do
@@ -114,9 +134,10 @@ while [ "$#" -gt 0 ]; do
114134
done
115135

116136
[ -n "$_dev" ] || usage 1
137+
[ -n "$_os" ] || _os=linux
138+
117139
if [ -z "$_old" ] || [ -z "$_new" ]; then
118140
usage 2
119141
fi
120-
[ -n "$_os" ] || _os=linux
121142

122143
main

0 commit comments

Comments
 (0)