blob: 4d7046a816ae83e9ecd89a8a2bc47a7a3d5b30a6 (
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
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
|
#!/usr/bin/env bash
# -*- tab-width : 4; indent-tabs-mode : nil -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
#
# Functions
#
#
# Display an error message and exit
#
die()
{
echo "Error:" "$@" >&2
exit -1;
}
init()
{
if [ "${SOURCE_COMPILE?}${AFTER?}${BEFORE?}" != "TRUE" ] ; then
die "You can only supply one of '-a', '-b' or '-c' simultaneously."
fi
if [ -n "${SRC_DIR?}" ] ; then
if [ ! -d "${SRC_DIR?}" ] ; then
die "Failed to locate source code directory $SRC_DIR."
fi
if [ ! -d "${SRC_DIR?}/.git" ] ; then
die "${SRC_DIR?} is not a git repository."
fi
if [ "${SRC_DIR?}" = "${BUILD_DIR?}" ] ; then
die "Cannot set the source directory to the same value as the build directory."
fi
fi
if [ "${AFTER?}" = "TRUE" ] ; then
if [ -z "${HTML_DIR?}" ] ; then
die "When specifying '-a', you also need to specify '-w'."
fi
if [ -z "${BUILD_DIR?}" ] ; then
die "When specifying '-a', you also need to specify '-C'."
fi
if [ -z "${SRC_DIR?}" ] ; then
die "When specifying '-a', you also need to specify '-s'."
fi
if [ -d "${HTML_DIR?}" ] ; then
mkdir "${HTML_DIR?}" || die "Failed to create html directory ${HTML_DIR?}."
else
rm -rf "${HTML_DIR?}"
mkdir "${HTML_DIR?}" || die "Failed to create html directory ${HTML_DIR?}."
fi
fi
if [ "${BEFORE?}" = "TRUE" -o "${AFTER?}" = "TRUE" ] ; then
if [ -z "${TRACEFILE_DIR?}" ] ; then
die "When specifying '-a' or '-b', you also need to specify '-t'."
fi
if [ ! -d "${TRACEFILE_DIR?}" ] ; then
mkdir "${TRACEFILE_DIR?}" || die "Failed to create tracefile directory ${TRACEFILE_DIR?}."
else
rm -rf "${TRACEFILE_DIR?}"
mkdir "${TRACEFILE_DIR?}" || die "Failed to create tracefile directory ${TRACEFILE_DIR?}."
fi
fi
if [ "${SOURCE_COMPILE?}" = "TRUE" ] ; then
if [ -z "${BUILD_DIR?}" ] ; then
die "When specifying '-c', you also need to specify '-C'."
fi
if [ -z "${SRC_DIR?}" ] ; then
die "When specifying '-c', you also need to specify '-s'."
fi
if [ ! -d "$BUILD_DIR" ] ; then
mkdir "$BUILD_DIR" || die "Failed to create source compile directory $BUILD_DIR."
else
rm -rf "$BUILD_DIR"
mkdir "$BUILD_DIR" || die "Failed to create source compile directory $BUILD_DIR."
fi
fi
}
lcov_cleanup()
{
lcov --zerocounters --directory "${SRC_DIR?}"
}
source_build()
{
cd "${BUILD_DIR?}"
LDFLAGS+='-fprofile-arcs' CFLAGS+='-fprofile-arcs -ftest-coverage' CXXFLAGS+='-fprofile-arcs -ftest-coverage' CPPFLAGS+='-fprofile-arcs -ftest-coverage' \
"${SRC_DIR?}/autogen.sh" --disable-online-update --without-system-libs --without-system-headers \
|| die "autogen.sh failed."
make build-nocheck || die "make build-nocheck failed."
}
lcov_tracefile_baseline()
{
lcov --rc geninfo_auto_base=1 --capture --initial --directory "${BUILD_DIR?}" --output-file "${TRACEFILE_DIR?}/lcov_base.info" \
|| die "Tracefile ${TRACEFILE_DIR?}/lcov_base.info generation failed."
}
lcov_tracefile_tests()
{
lcov --rc geninfo_auto_base=1 --capture --directory "${BUILD_DIR?}" --output-file "${TRACEFILE_DIR?}/lcov_test.info" \
|| die "Tracefile ${TRACEFILE_DIR?}/lcov_test.info generation failed."
}
lcov_tracefile_join()
{
lcov --rc geninfo_auto_base=1 --add-tracefile "${TRACEFILE_DIR?}/lcov_base.info" \
--add-tracefile "${TRACEFILE_DIR?}/lcov_test.info" --output-file "${TRACEFILE_DIR?}/lcov_total.info" \
|| die "Tracefile generation $TRACEFILE_DIR/lcov_total.info failed."
}
lcov_tracefile_cleanup()
{
lcov --rc geninfo_auto_base=1 --remove "${TRACEFILE_DIR?}/lcov_total.info" \
"/usr/include/*" "/usr/lib/*" "${SRC_DIR?}/*/UnpackedTarball/*" "${SRC_DIR?}/workdir/*" \
"${BUILD_DIR?}/workdir/*" "${SRC_DIR?}/instdir/*" "${SRC_DIR?}/external/*" \
-o "${TRACEFILE_DIR?}lcov_filtered.info" \
|| die "tracefile generation ${TRACEFILE_DIR?}/lcov_filtered.info failed."
}
lcov_mkhtml()
{
cd "$SRC_DIR"
COMMIT_SHA1=$(git log --date=iso | head -3 | awk '/^commit/ {print $2}')
COMMIT_DATE=$(git log --date=iso | head -3 | awk '/^Date/ {print $2}')
COMMIT_TIME=$(git log --date=iso | head -3 | awk '/^Date/ {print $3}')
mkdir "${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?}" || die "Failed to create subdirectory in ${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?}"
genhtml --rc geninfo_auto_base=1 --prefix "${SRC_DIR?}" --ignore-errors source "${TRACEFILE_DIR?}/lcov_filtered.info" \
--legend --title "commit ${COMMIT_SHA1?}" \
--output-directory="${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?}" \
|| die "ERROR: Generation of html files in ${HTML_DIR?}/master~${COMMIT_DATE?}_${COMMIT_TIME?} failed."
}
usage()
{
echo >&2 "Usage: lcov-report.sh [-a|-b|-c] -s [DIRECTORY] -C [DIRECTORY] -t [DIRECTORY] -w [DIRECTORY]
-b run lcov commands before your tests
-a run lcov commands after your tests
-c compile libreoffice sources
-C build directory to compile libreoffice sources in
-s source code directory
-t tracefile directory
-w html (www) directory"
exit 1
}
#
# Main
#
SOURCE_COMPILE=
BEFORE=
AFTER=
SRC_DIR=
TRACEFILE_DIR=
HTML_DIR=
BUIILD_DIR=
if [ "$#" = "0" ] ; then
usage
fi
while getopts ":s:t:w:C:abc" opt ; do
case "$opt" in
s)
SRC_DIR="$OPTARG"
;;
t)
TRACEFILE_DIR="$OPTARG"
;;
w)
HTML_DIR="$OPTARG"
;;
c)
SOURCE_COMPILE=TRUE
;;
C)
BUILD_DIR="$OPTARG"
;;
b)
BEFORE=TRUE
;;
a)
AFTER=TRUE
;;
*)
usage
;;
esac
done
echo "foo"
init
if [ "${BEFORE?}" = "TRUE" ] ; then
lcov_cleanup
lcov_tracefile_baseline
fi
if [ "${SOURCE_COMPILE?}" = "TRUE" ] ; then
source_build
fi
if [ "${AFTER?}" = "TRUE" ] ; then
lcov_tracefile_tests
lcov_tracefile_join
lcov_tracefile_cleanup
lcov_mkhtml
fi
|