29
29
30
30
# Command line options:
31
31
# --dry-run : run the tools, but don't actually do the upload
32
+ # --docker : create and work inside a docker container
32
33
# --update-tools-only : update the cached copy of the tools, but don't run them
33
34
# --tokenfile : file to read Coverity token from
34
35
# --version ver : specify version being analyzed (default: ask git)
35
36
# --description desc : specify description of this version (default: ask git)
36
37
# --srcdir : QEMU source tree to analyze (default: current working dir)
37
38
# --results-tarball : path to copy the results tarball to (default: don't
38
39
# copy it anywhere, just upload it)
40
+ # --src-tarball : tarball to untar into src dir (default: none); this
41
+ # is intended mainly for internal use by the Docker support
39
42
#
40
43
# User-specifiable environment variables:
41
44
# COVERITY_TOKEN -- Coverity token
@@ -125,6 +128,7 @@ update_coverity_tools () {
125
128
# Check user-provided environment variables and arguments
126
129
DRYRUN=no
127
130
UPDATE_ONLY=no
131
+ DOCKER=no
128
132
129
133
while [ " $# " -ge 1 ]; do
130
134
case " $1 " in
@@ -181,6 +185,19 @@ while [ "$#" -ge 1 ]; do
181
185
RESULTSTARBALL=" $1 "
182
186
shift
183
187
;;
188
+ --src-tarball)
189
+ shift
190
+ if [ $# -eq 0 ]; then
191
+ echo " --src-tarball needs an argument"
192
+ exit 1
193
+ fi
194
+ SRCTARBALL=" $1 "
195
+ shift
196
+ ;;
197
+ --docker)
198
+ DOCKER=yes
199
+ shift
200
+ ;;
184
201
* )
185
202
echo " Unexpected argument '$1 '"
186
203
exit 1
@@ -212,6 +229,10 @@ PROJTOKEN="$COVERITY_TOKEN"
212
229
PROJNAME=QEMU
213
230
TARBALL=cov-int.tar.xz
214
231
232
+ if [ " $UPDATE_ONLY " = yes ] && [ " $DOCKER " = yes ]; then
233
+ echo " Combining --docker and --update-only is not supported"
234
+ exit 1
235
+ fi
215
236
216
237
if [ " $UPDATE_ONLY " = yes ]; then
217
238
# Just do the tools update; we don't need to check whether
@@ -221,8 +242,17 @@ if [ "$UPDATE_ONLY" = yes ]; then
221
242
exit 0
222
243
fi
223
244
245
+ if [ ! -e " $SRCDIR " ]; then
246
+ mkdir " $SRCDIR "
247
+ fi
248
+
224
249
cd " $SRCDIR "
225
250
251
+ if [ ! -z " $SRCTARBALL " ]; then
252
+ echo " Untarring source tarball into $SRCDIR ..."
253
+ tar xvf " $SRCTARBALL "
254
+ fi
255
+
226
256
echo " Checking this is a QEMU source tree..."
227
257
if ! [ -e " $SRCDIR /VERSION" ]; then
228
258
echo " Not in a QEMU source tree?"
@@ -242,6 +272,66 @@ if [ -z "$COVERITY_EMAIL" ]; then
242
272
COVERITY_EMAIL=" $( git config user.email) "
243
273
fi
244
274
275
+ # Run ourselves inside docker if that's what the user wants
276
+ if [ " $DOCKER " = yes ]; then
277
+ # build docker container including the coverity-scan tools
278
+ # Put the Coverity token into a temporary file that only
279
+ # we have read access to, and then pass it to docker build
280
+ # using --secret. This requires at least Docker 18.09.
281
+ # Mostly what we are trying to do here is ensure we don't leak
282
+ # the token into the Docker image.
283
+ umask 077
284
+ SECRETDIR=$( mktemp -d)
285
+ if [ -z " $SECRETDIR " ]; then
286
+ echo " Failed to create temporary directory"
287
+ exit 1
288
+ fi
289
+ trap ' rm -rf "$SECRETDIR"' INT TERM EXIT
290
+ echo " Created temporary directory $SECRETDIR "
291
+ SECRET=" $SECRETDIR /token"
292
+ echo " $COVERITY_TOKEN " > " $SECRET "
293
+ echo " Building docker container..."
294
+ # TODO: This re-downloads the tools every time, rather than
295
+ # caching and reusing the image produced with the downloaded tools.
296
+ # Not sure why.
297
+ # TODO: how do you get 'docker build' to print the output of the
298
+ # commands it is running to its stdout? This would be useful for debug.
299
+ DOCKER_BUILDKIT=1 docker build -t coverity-scanner \
300
+ --secret id=coverity.token,src=" $SECRET " \
301
+ -f scripts/coverity-scan/coverity-scan.docker \
302
+ scripts/coverity-scan
303
+ echo " Archiving sources to be analyzed..."
304
+ ./scripts/archive-source.sh " $SECRETDIR /qemu-sources.tgz"
305
+ if [ " $DRYRUN " = yes ]; then
306
+ DRYRUNARG=--dry-run
307
+ fi
308
+ echo " Running scanner..."
309
+ # If we need to capture the output tarball, get the inner run to
310
+ # save it to the secrets directory so we can copy it out before the
311
+ # directory is cleaned up.
312
+ if [ ! -z " $RESULTSTARBALL " ]; then
313
+ RTARGS=" --results-tarball /work/cov-int.tar.xz"
314
+ else
315
+ RTARGS=" "
316
+ fi
317
+ # Arrange for this docker run to get access to the sources with -v.
318
+ # We pass through all the configuration from the outer script to the inner.
319
+ export COVERITY_EMAIL COVERITY_BUILD_CMD
320
+ docker run -it --env COVERITY_EMAIL --env COVERITY_BUILD_CMD \
321
+ -v " $SECRETDIR :/work" coverity-scanner \
322
+ ./run-coverity-scan --version " $VERSION " \
323
+ --description " $DESCRIPTION " $DRYRUNARG --tokenfile /work/token \
324
+ --srcdir /qemu --src-tarball /work/qemu-sources.tgz $RTARGS
325
+ if [ ! -z " $RESULTSTARBALL " ]; then
326
+ echo " Copying results tarball to $RESULTSTARBALL ..."
327
+ cp " $SECRETDIR /cov-int.tar.xz" " $RESULTSTARBALL "
328
+ fi
329
+ echo " Docker work complete."
330
+ exit 0
331
+ fi
332
+
333
+ # Otherwise, continue with the full build and upload process.
334
+
245
335
check_upload_permissions
246
336
247
337
update_coverity_tools
0 commit comments