File indexing completed on 2024-05-26 04:21:06

0001 #!/bin/bash
0002 
0003 # SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier, <caulier dot gilles at gmail dot com>
0004 #
0005 # Run Coverity Scan static analyzer on whole digiKam source code.
0006 # https://scan.coverity.com/
0007 #
0008 # Before to run this script you must:
0009 #
0010 # - Install Coverity Scan to /opt/ from https://scan.coverity.com/download?tab=cxx
0011 # - Export binary path /opt/_coverity_version_/bin to PATH variable
0012 # - Export $DKCoverityToken Shell variable with token of digiKam project given by Coverity SCAN web interface.
0013 #
0014 # Example in .bashrc:
0015 #
0016 # export DKCoverityToken=xxxxxxx
0017 # export PATH=$PATH:/opt/cov-analysis-linux64-2020.09/bin
0018 #
0019 # SPDX-License-Identifier: BSD-3-Clause
0020 #
0021 
0022 # Halt and catch errors
0023 set -eE
0024 trap 'PREVIOUS_COMMAND=$THIS_COMMAND; THIS_COMMAND=$BASH_COMMAND' DEBUG
0025 trap 'echo "FAILED COMMAND: $PREVIOUS_COMMAND"' ERR
0026 
0027 ORIG_WD="`pwd`"
0028 
0029 # Check run-time dependencies
0030 
0031 if ! which cov-build ; then
0032 
0033     echo "Coverity SCAN Toolkit is not installed!"
0034     echo "See https://scan.coverity.com/download?tab=cxx for details."
0035     exit -1
0036 
0037 fi
0038 
0039 # Check if Coverity token is set.
0040 
0041 if [ ! compgen -e -X "!$DKCoverityToken" ] ; then
0042 
0043     echo "Coverity SCAN token variable is not set!"
0044     exit -1
0045 
0046 fi
0047 
0048 echo "Check Coverity SCAN Toolkit passed..."
0049 
0050 cd $ORIG_WD/../..
0051 
0052 # Manage build sub-dir
0053 
0054 if [ -d "build" ]; then
0055 
0056     rm -rfv ./build
0057 
0058 fi
0059 
0060 if [[ "$OSTYPE" == "linux-gnu" ]]; then
0061 
0062     ./bootstrap.linux
0063 
0064 elif [[ "$OSTYPE" == "darwin"* ]]; then
0065 
0066     ./bootstrap.macports
0067 
0068 else
0069 
0070     echo "Unsupported platform..."
0071     exit -1
0072 
0073 fi
0074 
0075 # Get active git branches to create report description string
0076 ./gits branch | sed -e "s/*/#/g" | sed -e "s/On:/#On:/g" | grep "#" | sed -e "s/#On:/On:/g" | sed -e "s/#/BRANCH:/g" > ./build/git_branches.txt
0077 desc=$(<build/git_branches.txt)
0078 
0079 cd $ORIG_WD/../../build
0080 
0081 CPU_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
0082 echo "CPU cores detected to compile : $CPU_CORES."
0083 
0084 cov-build --dir cov-int --tmpdir ~/tmp make -j$CPU_CORES
0085 tar czvf myproject.tgz cov-int
0086 
0087 cd $ORIG_WD/../../build
0088 
0089 echo "-- SCAN Import description --"
0090 echo $desc
0091 echo "Analysis archive to upload:"
0092 file myproject.tgz
0093 du -H myproject.tgz
0094 echo "-----------------------------"
0095 
0096 echo "Coverity Scan tarball 'myproject.tgz' uploading in progress..."
0097 
0098 # To be sure that resolve domain is in cache
0099 nslookup scan.coverity.com
0100 
0101 # To measure uploading time
0102 SECONDS=0
0103 
0104 curl https://scan.coverity.com/builds?project=digiKam \
0105      --progress-bar \
0106      --verbose \
0107      --form token=$DKCoverityToken \
0108      --form email=$digikam-devel@kde.org \
0109      --form file=@myproject.tgz \
0110      --form version=git \
0111      --form description="$desc"
0112 
0113 echo "Done. Coverity Scan tarball 'myproject.tgz' is uploaded."
0114 echo "That took approximately $SECONDS seconds to upload."
0115 echo "File will be post processed for analyse. A mail notification will be send to digikam-devel@kde.org."