]>
Commit | Line | Data |
---|---|---|
22a2d3d5 UG |
1 | #!/bin/bash -e |
2 | ||
3 | if test -z "$COVERITY_TOKEN" | |
4 | then | |
5 | echo "Need to set a coverity token" | |
6 | exit 1 | |
7 | fi | |
8 | ||
9 | case $(uname -m) in | |
10 | i?86) | |
11 | BITS=32;; | |
12 | amd64|x86_64) | |
13 | BITS=64;; | |
14 | *) | |
15 | echo "Unsupported arch '$(uname -m)'" | |
16 | exit 1;; | |
17 | esac | |
18 | ||
19 | SCAN_TOOL=https://scan.coverity.com/download/cxx/linux${BITS} | |
20 | SOURCE_DIR=$(realpath "$(dirname "${BASH_SOURCE[0]}")"/..) | |
21 | BUILD_DIR=${SOURCE_DIR}/coverity-build | |
22 | TOOL_DIR=${BUILD_DIR}/coverity-tools | |
23 | ||
24 | # Install coverity tools | |
25 | if ! test -d "$TOOL_DIR" | |
26 | then | |
27 | mkdir -p "$TOOL_DIR" | |
28 | curl --silent --show-error --location --data "project=libgit2&token=$COVERITY_TOKEN" "$SCAN_TOOL" | | |
29 | tar -xzC "$TOOL_DIR" | |
30 | ln -s "$(find "$TOOL_DIR" -type d -name 'cov-analysis*')" "$TOOL_DIR"/cov-analysis | |
31 | fi | |
32 | ||
33 | cp "${SOURCE_DIR}/script/user_nodefs.h" "$TOOL_DIR"/cov-analysis/config/ | |
34 | ||
35 | # Build libgit2 with Coverity | |
36 | mkdir -p "$BUILD_DIR" | |
37 | cd "$BUILD_DIR" | |
38 | cmake "$SOURCE_DIR" | |
39 | COVERITY_UNSUPPORTED=1 \ | |
40 | "$TOOL_DIR/cov-analysis/bin/cov-build" --dir cov-int \ | |
41 | cmake --build . | |
42 | ||
43 | # Upload results | |
44 | tar -czf libgit2.tgz cov-int | |
45 | REVISION=$(cd ${SOURCE_DIR} && git rev-parse --short HEAD) | |
46 | HTML="$(curl \ | |
47 | --silent --show-error \ | |
48 | --write-out "\n%{http_code}" \ | |
49 | --form token="$COVERITY_TOKEN" \ | |
50 | --form email=libgit2@gmail.com \ | |
51 | --form file=@libgit2.tgz \ | |
52 | --form version="$REVISION" \ | |
53 | --form description="libgit2 build" \ | |
54 | https://scan.coverity.com/builds?project=libgit2)" | |
55 | ||
56 | # Status code is the last line | |
57 | STATUS_CODE="$(echo "$HTML" | tail -n1)" | |
58 | if test "${STATUS_CODE}" != 200 && test "${STATUS_CODE}" != 201 | |
59 | then | |
60 | echo "Received error code ${STATUS_CODE} from Coverity" | |
61 | exit 1 | |
62 | fi |