Skip to content

Commit 7575543

Browse files
committed
bin/check-warn.sh: isolate main process from arg parse
Isolate the main processing from the argument parsing so it's clear where we are exiting from. Signed-off-by: Randolph Sapp <[email protected]>
1 parent ef3d9c5 commit 7575543

File tree

1 file changed

+68
-66
lines changed

1 file changed

+68
-66
lines changed

bin/check-warn.sh

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,73 @@ restore_branch()
3434
[ -z "$_cbr" ] || git checkout "$_cbr"
3535
}
3636

37-
### main() ###
37+
main()
38+
{
39+
if [[ "$(head -1 Makefile 2> /dev/null)" != "# Makefile for Sphinx"* ]]
40+
then
41+
echo "Error: Not in the top directory"
42+
exit 3
43+
fi
44+
45+
# do nothing if current workspace is not clean
46+
if [ -n "$(git status --porcelain --untracked-files=no)" ]
47+
then
48+
echo "Error: Current workspace has uncommitted changes"
49+
exit 4
50+
fi
51+
52+
# do nothing if target ${_new} doesn't exist,
53+
# don't wait for it fails after ${_old} was built
54+
if ! git cat-file -t "${_new}" > /dev/null 2>&1; then
55+
echo "${_new} not found"
56+
exit 5
57+
fi
58+
59+
# convert 'HEAD' to its commit ID
60+
if [ "$_new" = "HEAD" ]; then
61+
_new=$(git rev-parse HEAD)
62+
fi
63+
if [ "$_old" = "HEAD" ]; then
64+
_old=$(git rev-parse HEAD)
65+
fi
66+
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
83+
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
88+
89+
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
103+
}
38104

39105
while [ "$#" -gt 0 ]; do
40106
case $1 in
@@ -53,68 +119,4 @@ if [ -z "$_old" ] || [ -z "$_new" ]; then
53119
fi
54120
[ -n "$_os" ] || _os=linux
55121

56-
if [[ "$(head -1 Makefile 2> /dev/null)" != "# Makefile for Sphinx"* ]]
57-
then
58-
echo "Error: Not in the top directory"
59-
exit 3
60-
fi
61-
62-
# do nothing if current workspace is not clean
63-
if [ -n "$(git status --porcelain --untracked-files=no)" ]
64-
then
65-
echo "Error: Current workspace has uncommitted changes"
66-
exit 4
67-
fi
68-
69-
# do nothing if target ${_new} doesn't exist,
70-
# don't wait for it fails after ${_old} was built
71-
if ! git cat-file -t "${_new}" > /dev/null 2>&1; then
72-
echo "${_new} not found"
73-
exit 5
74-
fi
75-
76-
# convert 'HEAD' to its commit ID
77-
if [ "$_new" = "HEAD" ]; then
78-
_new=$(git rev-parse HEAD)
79-
fi
80-
if [ "$_old" = "HEAD" ]; then
81-
_old=$(git rev-parse HEAD)
82-
fi
83-
84-
# get current branch name or commit ID
85-
_cbr=$(git branch | sed -n '/\* /s///p')
86-
if [[ "$_cbr" == "(HEAD detached"* ]]; then
87-
_cbr=$(git rev-parse HEAD)
88-
fi
89-
90-
git checkout "${_old}" || exit 10
91-
92-
mkdir -p build
93-
94-
make DEVFAMILY="${_dev}" OS="${_os}" clean
95-
make DEVFAMILY="${_dev}" OS="${_os}" config > build/_a.log 2>&1 || exit 12
96-
make DEVFAMILY="${_dev}" OS="${_os}" >> build/_a.log 2>&1 || exit 13
97-
grep "WARNING:" build/_a.log > build/_a-warn.log
98-
99-
git checkout "${_new}" || exit 20
100-
101-
make DEVFAMILY="${_dev}" OS="${_os}" clean
102-
make DEVFAMILY="${_dev}" OS="${_os}" config > build/_b.log 2>&1 || exit 22
103-
make DEVFAMILY="${_dev}" OS="${_os}" >> build/_b.log 2>&1 || exit 23
104-
grep "WARNING:" build/_b.log > build/_b-warn.log
105-
106-
restore_branch
107-
108-
diff --changed-group-format="%>" --unchanged-group-format="" \
109-
build/_a-warn.log build/_b-warn.log > build/_new-warn.log
110-
111-
_num=$(wc -l build/_new-warn.log)
112-
113-
echo
114-
echo "Found $_num new build WARNING(s)."
115-
echo
116-
117-
if [ "$_num" != "0" ]; then
118-
cat build/_new-warn.log
119-
fi
120-
122+
main

0 commit comments

Comments
 (0)