-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgit-compile-check
executable file
·232 lines (209 loc) · 6.45 KB
/
git-compile-check
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/bin/bash
#
# See $desc, below, for program description
#
# Copyright (c) 2013 Red Hat, Inc.
#
# Author(s):
# Jeff Cody <[email protected]>
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; under version 2 of the license
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, see <http://www.gnu.org/licenses/gpl-2.0.html>.
#
set -C -u -e
set -o pipefail
desc="
$0 iterates through a git commit range, and performs the
following on each commit:
- git checkout
- make clean
- configure
- make
It will also optionally perform a git-reset and git-clean between
checkouts, if requested via the '-f' option.
The script will exit and report on first error on any of the above steps,
(except no error checking is performed on 'make clean')
NOTE: While executing, the script will checkout out each commit
in the range in the current git tree. On exit, the HEAD
at the time the script was called is checked out"
# default range is the last commit
def_range="HEAD^!"
def_config_opt="--target-list=x86_64-softmmu"
def_noconf_opt=false
# you may want to have make perform multiple jobs, e.g. -j4
# this is ommitted as the default in case the project makefile
# is not safe for parallel make processes
def_make_opt=""
def_log="output-$$.log"
def_logdir=""
force_clean='n'
logfile=$def_log
range=`git config compile-check.range || true`
noconf_opt=`git config compile-check.noconfopt || true`
config_opt=`git config compile-check.configopt || true`
make_opt=`git config compile-check.makeopt || true`
logdir=`git config compile-check.logdir || true`
if [[ -z "$range" ]]
then
range=$def_range
git config compile-check.range $range || true
fi
if [[ -z "$config_opt" ]]
then
config_opt=$def_config_opt
git config compile-check.configopt $config_opt || true
fi
if [[ -z "$noconf_opt" ]]
then
noconf_opt=$def_noconf_opt
git config compile-check.noconfopt $noconf_opt || true
fi
if [[ -z "$make_opt" ]]
then
make_opt=$def_make_opt
git config compile-check.makeopt $make_opt || true
fi
if [[ -z "$logdir" ]]
then
logdir=$def_logdir
git config compile-check.logdir $logdir || true
fi
usage() {
echo ""
echo "$0 [OPTIONS]"
echo "$desc"
echo ""
echo "OPTIONS:"
echo " -r git range
optional; default is '$range'
"
echo " -c configure options
optional; default is '$config_opt'
"
echo " -n skip the configure step
optional; default is '$noconf_opt'
"
echo " -m make options
optional; default is '$make_opt'
"
echo " -d log dir
optional; default is '$logdir'
"
echo " -l log filename
optional; default is output-PROCID, where PROCID is the bash process id
note: you may specify a full path for the log filename here, and exclude the
-d option.
"
echo " -f force a git reset and clean
this will cause a 'git reset --hard; git clean -fdx' to be run between checkouts.
!! WARNING: This may cause data loss in your git tree.
READ the git-clean and git-reset man pages and make
sure you understand the implications of
'git clean -fdx' and 'git reset --hard' before using !!
If you specify this option, make sure the logfile falls outside of the tree.
"
echo " -h help"
}
while getopts ":r:c:m:l:d:hfn" opt
do
case $opt in
r) range=$OPTARG
;;
c) config_opt=$OPTARG
;;
n) noconf_opt=true
;;
m) make_opt=$OPTARG
;;
d) logdir=$OPTARG
;;
l) logfile=$OPTARG
;;
f) force_clean='y'
;;
h) usage
exit
;;
\?) echo "Unknown option: -$OPTARG" >&2
usage
exit 1
;;
esac
done
# append a '/' to logdir if $logdir was specified without one
[[ -n "$logdir" ]] && [[ ${logdir:${#logdir}-1} != "/" ]] && logdir="${logdir}/"
logfile="${logdir}${logfile}"
head=`git rev-parse --abbrev-ref=strict HEAD`
if [ HEAD = "$head" ]
then
# we're at a detached head, get hash
head=`git rev-parse HEAD`
fi
total=`git rev-list "$range" |wc -l`
echo "log output: $logfile"
rm -f "$logfile"
date > "$logfile"
echo "git compile check for $range." >> "$logfile"
if ! $noconf_opt; then
echo "* configure options='$config_opt'" >> "$logfile"
config_invoc="./configure $config_opt"
else
config_invoc="echo skipping configure"
fi
echo "* make options='$make_opt'" >> "$logfile"
echo "Performing a test compile on $total patches" | tee -a "$logfile"
echo "-------------------------------------------------------------" >> "$logfile"
echo "" | tee -a "$logfile"
clean_repo() {
if [[ $force_clean == 'y' ]]
then
git reset --hard >> "$logfile" 2>&1 || true
git clean -fdx -e "$logfile" >> "$logfile" 2>&1 || true
fi
}
# we want to cleanup and return the git tree back to the previous head
trap cleanup EXIT
cleanup() {
echo ""
echo -n "Cleaning up..."
clean_repo
git checkout $head > /dev/null 2>&1
echo "done."
}
cnt=1
# don't pipe the git job into read, to avoid subshells
while read hash
do
txt=`git log --pretty=tformat:"%h: %s" $hash^!`
echo "${cnt}/${total}: compiling: $txt" | tee -a "$logfile"
let cnt=$cnt+1;
echo "####################" >> "$logfile"
clean_repo
make clean > /dev/null 2>&1 || true
git checkout $hash >> "$logfile" 2>&1 && \
eval $config_invoc >> "$logfile" 2>&1 && \
make $make_opt >> "$logfile" 2>&1 ||
(
S=$?
# don't complain for SIGINT, SIGTERM, SIGQUIT
if [ $S -ne 130 ] && [ $S -ne 131 ] && [ $S -ne 143 ]
then
echo "" | tee -a "$logfile"
echo "ERROR: commit $hash failed to build!" | tee -a "$logfile"
git show --stat $hash | tee -a "$logfile"
fi
exit 1
)
done < <(git log $range --pretty=tformat:"%H" --reverse)
echo "
All patches in $range compiled successfully!" | tee -a "$logfile"
exit 0