Skip to content

Commit efbd788

Browse files
StaticRocketcshilwant
authored andcommitted
Pull request #1812: Check warn redux
Merge in PROCESSOR-SDK/processor-sdk-doc from ~A0499604/processor-sdk-doc:check-warn-redux to master * commit '698f62468af84292495d05351fe3840c1082cfd8': bin/check-warn.sh: add a merge argument bin/check-warn.sh: use tee, capture stderr bin/check-warn.sh: use full git syntax bin/check-warn.sh: compartmentalize and deduplicate bin/check-warn.sh: isolate main process from arg parse bin/check-warn.sh: remove trailing whitespace bin/check-warn.sh: prefer test conditionals bin/check-warn.sh: remove check for swtoolsdev bin/check-warn.sh: eliminate useless cat bin/check-warn.sh: double quote all args bin/check-warn.sh: move help string to global
2 parents f664d0a + 698f624 commit efbd788

File tree

1 file changed

+118
-79
lines changed

1 file changed

+118
-79
lines changed

bin/check-warn.sh

Lines changed: 118 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,148 @@
11
#!/bin/bash
22
### PSDK-doc check new build WARNINGs
33

4+
HELP_STRING="
5+
Build and check if git branch or commit <NEW> generates any new build WARNING(s)
6+
based on git branch or commit <OLD>.
7+
8+
check-warn.sh [OPTIONS]
9+
10+
BUILD OPTIONS:
11+
-d, --device DEV build for device-family DEV
12+
-o, --os OS build for os OS, default: linux
13+
14+
DIFF OPTIONS:
15+
-a OLD git branch or commit ID OLD as the base, 'HEAD' is
16+
acceptable
17+
-b NEW git branch or commit ID NEW for checking WARNING(s), 'HEAD'
18+
is acceptable
19+
-m, --merge automatically pick the merge-base for the given commits
20+
21+
OTHER OPTIONS:
22+
-h, --help this message
23+
"
24+
425
trap restore_branch 1 2 3 6 15
526

627
usage()
728
{
8-
echo "Build and check if git branch or commit <NEW> generates" \
9-
"any new build WARNING(s) based on git branch or commit <OLD>."
10-
echo
11-
echo "check-warn.sh <-d | --device DEV> [-o | --os OS] <-a OLD> <-b NEW> [-h | --help]"
12-
echo
13-
echo -e "\t-d | --device DEV: build for device-family DEV"
14-
echo -e "\t-o | --os OS: build for os OS, default: linux"
15-
echo -e "\t-a OLD: git branch or commit ID OLD as the base, 'HEAD' is acceptable"
16-
echo -e "\t-b NEW: git branch or commit ID NEW for checking WARNING(s), 'HEAD' is acceptable"
17-
echo -e "\t-h | --help: this message"
18-
echo
19-
exit $1
29+
echo "${HELP_STRING}"
30+
exit "$1"
2031
}
2132

22-
restore_branch()
33+
save_branch()
2334
{
24-
[[ -z "$_cbr" ]] || git checkout $_cbr
35+
# get current branch name or commit ID
36+
_cbr=$(git branch | sed -n '/\* /s///p')
37+
if [[ "$_cbr" == "(HEAD detached"* ]]; then
38+
_cbr=$(git rev-parse HEAD)
39+
fi
2540
}
2641

27-
### main() ###
42+
restore_branch()
43+
{
44+
[ -z "$_cbr" ] || git checkout "$_cbr"
45+
}
2846

29-
while [ $# -gt 0 ]; do
30-
case $1 in
31-
-h | --help) usage 0;;
32-
-d | --device) shift; _dev=$1; shift;;
33-
-o | --os) shift; _os=$1; shift;;
34-
-a) shift; _old=$1; shift;;
35-
-b) shift; _new=$1; shift;;
36-
*) shift;;
37-
esac
38-
done
47+
summary()
48+
{
49+
local _num
3950

40-
[[ -n "$_dev" ]] || usage 1
41-
[[ -n "$_old" && -n "$_new" ]] || usage 2
42-
[[ -n "$_os" ]] || _os=linux
51+
rm -f build/_new-warn.log
52+
diff --changed-group-format="%>" --unchanged-group-format="" \
53+
build/_a.log build/_b.log > build/_new-warn.log
4354

44-
if [[ "$(head -1 Makefile 2> /dev/null)" != "# Makefile for Sphinx"* ]]
45-
then
46-
echo "Error: Not in the top directory"
47-
exit 3
48-
fi
55+
_num=$(wc -l build/_new-warn.log)
4956

50-
# do nothing if current workspace is not clean
51-
if [[ -n "$(git status --porcelain --untracked-files=no | grep -v swtoolsdev)" ]]
52-
then
53-
echo "Error: Current workspace has uncommitted changes"
54-
exit 4
55-
fi
56-
57-
# do nothing if target ${_new} doesn't exist,
58-
# don't wait for it fails after ${_old} was built
59-
if ! git cat-file -t ${_new} > /dev/null 2>&1; then
60-
echo "${_new} not found"
61-
exit 5
62-
fi
57+
echo
58+
echo "Found $_num new build WARNING(s)."
59+
echo
6360

64-
# convert 'HEAD' to its commit ID
65-
if [[ "$_new" == "HEAD" ]]; then
66-
_new=$(git rev-parse HEAD)
67-
fi
68-
if [[ "$_old" == "HEAD" ]]; then
69-
_old=$(git rev-parse HEAD)
70-
fi
71-
61+
if [ "$_num" != "0" ]; then
62+
cat build/_new-warn.log
63+
fi
64+
}
7265

73-
# get current branch name or commit ID
74-
_cbr=$(git branch | sed -n '/\* /s///p')
75-
if [[ $_cbr == "(HEAD detached"* ]]; then
76-
_cbr=$(git rev-parse HEAD)
77-
fi
66+
generate_log()
67+
{
68+
local git_hash log_name log_path
7869

79-
git checkout ${_old} || exit 10
70+
git_hash=$1
71+
log_name=$2
8072

81-
mkdir -p build
73+
log_path="build/${log_name}.log"
8274

83-
make DEVFAMILY=${_dev} OS=${_os} clean
84-
make DEVFAMILY=${_dev} OS=${_os} config > build/_a.log 2>&1 || exit 12
85-
make DEVFAMILY=${_dev} OS=${_os} >> build/_a.log 2>&1 || exit 13
86-
grep "WARNING:" build/_a.log > build/_a-warn.log
75+
git checkout "${git_hash}" || exit 10
8776

88-
git checkout ${_new} || exit 20
77+
mkdir -p build
8978

90-
make DEVFAMILY=${_dev} OS=${_os} clean
91-
make DEVFAMILY=${_dev} OS=${_os} config > build/_b.log 2>&1 || exit 22
92-
make DEVFAMILY=${_dev} OS=${_os} >> build/_b.log 2>&1 || exit 23
93-
grep "WARNING:" build/_b.log > build/_b-warn.log
79+
rm -f "${log_path}"
80+
make DEVFAMILY="${_dev}" OS="${_os}" clean
81+
make DEVFAMILY="${_dev}" OS="${_os}" config 2> >(tee -a "${log_path}" >&2) || exit 12
82+
make DEVFAMILY="${_dev}" OS="${_os}" 2> >(tee -a "${log_path}" >&2) || exit 13
83+
}
9484

95-
restore_branch
85+
rev-parse()
86+
{
87+
local rev
88+
if ! rev=$(git rev-parse "$1"); then
89+
printf '%s\n' 'Unable to parse given revisions:'
90+
printf ' %s\n' "$1"
91+
exit 2
92+
fi
93+
echo "$rev"
94+
}
9695

97-
diff --changed-group-format="%>" --unchanged-group-format="" \
98-
build/_a-warn.log build/_b-warn.log > build/_new-warn.log
96+
main()
97+
{
98+
if [[ "$(head -1 Makefile 2> /dev/null)" != "# Makefile for Sphinx"* ]]
99+
then
100+
echo "Error: Not in the top directory"
101+
exit 3
102+
fi
103+
104+
# do nothing if current workspace is not clean
105+
if [ -n "$(git status --porcelain --untracked-files=no)" ]
106+
then
107+
echo "Error: Current workspace has uncommitted changes"
108+
exit 4
109+
fi
110+
111+
save_branch
112+
113+
_old=$(rev-parse "${_old}")
114+
_new=$(rev-parse "${_new}")
115+
116+
if [ -n "${_merge}" ] && ! _old=$(git merge-base "${_old}" "${_new}")
117+
then
118+
echo "Error: Unable to find merge-base for the given commits"
119+
exit 5
120+
fi
121+
122+
generate_log "${_old}" "_a"
123+
generate_log "${_new}" "_b"
124+
125+
restore_branch
126+
summary
127+
}
99128

100-
_num=$(cat build/_new-warn.log | wc -l)
129+
while [ "$#" -gt 0 ]; do
130+
case $1 in
131+
-h | --help) usage 0;;
132+
-d | --device) shift; _dev=$1; shift;;
133+
-o | --os) shift; _os=$1; shift;;
134+
-a) shift; _old=$1; shift;;
135+
-b) shift; _new=$1; shift;;
136+
-m | --merge) shift; _merge=1;;
137+
*) shift;;
138+
esac
139+
done
101140

102-
echo
103-
echo "Found $_num new build WARNING(s)."
104-
echo
141+
[ -n "$_dev" ] || usage 1
142+
[ -n "$_os" ] || _os=linux
105143

106-
if [[ $_num != "0" ]]; then
107-
cat build/_new-warn.log
144+
if [ -z "${_new}" ] || [ -z "${_old}" ]; then
145+
usage 2
108146
fi
109147

148+
main

0 commit comments

Comments
 (0)