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 Clang static analyzer on whole digiKam source code. 0006 # https://clang-analyzer.llvm.org/ 0007 # Dependencies : clang static analyzer version >= 3.9.0. 0008 # 0009 # If '--nowebupdate' is passed as argument, static analyzer results are just created locally. 0010 # 0011 # SPDX-License-Identifier: BSD-3-Clause 0012 # 0013 0014 # Halt and catch errors 0015 set -eE 0016 trap 'PREVIOUS_COMMAND=$THIS_COMMAND; THIS_COMMAND=$BASH_COMMAND' DEBUG 0017 trap 'echo "FAILED COMMAND: $PREVIOUS_COMMAND"' ERR 0018 0019 . ./common.sh 0020 0021 checksCPUCores 0022 0023 ORIG_WD="`pwd`" 0024 REPORT_DIR="${ORIG_WD}/report.scan" 0025 WEBSITE_DIR="${ORIG_WD}/site" 0026 0027 # Get active git branches to create report description string 0028 TITLE="digiKam-$(parseGitBranch)$(parseGitHash)" 0029 echo "Clang Scan Static Analyzer task name: $TITLE" 0030 0031 # Clean up and prepare to scan. 0032 0033 rm -fr $REPORT_DIR 0034 rm -fr $WEBSITE_DIR 0035 0036 cd ../.. 0037 0038 rm -fr build.scan 0039 mkdir -p build.scan 0040 cd build.scan 0041 0042 scan-build cmake -G "Unix Makefiles" . \ 0043 -DCMAKE_BUILD_TYPE=debug \ 0044 -DBUILD_TESTING=ON \ 0045 -DDIGIKAMSC_CHECKOUT_PO=OFF \ 0046 -DDIGIKAMSC_CHECKOUT_DOC=OFF \ 0047 -DDIGIKAMSC_COMPILE_PO=OFF \ 0048 -DDIGIKAMSC_COMPILE_DOC=OFF \ 0049 -DENABLE_KFILEMETADATASUPPORT=ON \ 0050 -DENABLE_AKONADICONTACTSUPPORT=ON \ 0051 -DENABLE_MYSQLSUPPORT=ON \ 0052 -DENABLE_INTERNALMYSQL=ON \ 0053 -DENABLE_MEDIAPLAYER=ON \ 0054 -DENABLE_QTMULTIMEDIA=ON \ 0055 -DENABLE_DBUS=ON \ 0056 -DENABLE_APPSTYLES=ON \ 0057 -DENABLE_QWEBENGINE=ON \ 0058 -Wno-dev \ 0059 .. 0060 0061 scan-build -o $REPORT_DIR \ 0062 -no-failure-reports \ 0063 --keep-empty \ 0064 --html-title $TITLE \ 0065 -v \ 0066 -k \ 0067 make -j$CPU_CORES 0068 0069 cd $ORIG_WD 0070 0071 SCANBUILD_DIR=$(find ${REPORT_DIR} -maxdepth 1 -not -empty -not -name `basename ${REPORT_DIR}`) 0072 echo "Clang Report $TITLE to publish is located to $SCANBUILD_DIR" 0073 0074 # Remove unwanted lines in report accordingly with Krazy configuration. 0075 # Note: Clang do not have an option to ignore directories to scan at compilation time. 0076 # Se this entry in Clang bugzilla: https://bugs.llvm.org/show_bug.cgi?id=22594 0077 krazySkipConfig 0078 0079 for DROP_ITEM in $KRAZY_FILTERS ; do 0080 echo -e "--- drop $DROP_ITEM from index.html with statistics adjustments" 0081 0082 # List all report types including current pattern to drop. 0083 REPORT_ENTRIES=( $(grep $DROP_ITEM $SCANBUILD_DIR/index.html) ) || true 0084 0085 # STAT_ENTRIES array contains the multi-entries list of statistic types to remove. 0086 STAT_ENTRIES=() # clear array 0087 0088 for RITEM in "${REPORT_ENTRIES[@]}" ; do 0089 if [[ $RITEM = *bt_* ]]; then 0090 STAT_ENTRIES[${#STAT_ENTRIES[*]}]=$(echo $RITEM | awk -F "\"" '{print $2}') 0091 fi 0092 done 0093 0094 # to update total statistic with current pattern to drop 0095 TOTAL_COUNT=0 0096 0097 # update report statistics values. 0098 for SITEM in "${STAT_ENTRIES[@]}" ; do 0099 ORG_STAT_LINE=$(grep "ToggleDisplay(this," $SCANBUILD_DIR/index.html | grep "${SITEM}") 0100 STAT_VAL=$(echo $ORG_STAT_LINE | grep -o -P '(?<=class=\"Q\">).*(?=<\/td><td>)') 0101 ORG_STR="class=\"Q\">$STAT_VAL<\/td><td>" 0102 STAT_VAL=$((STAT_VAL-1)) 0103 0104 if (( $STAT_VAL == 0 )); then 0105 # if counter is zero, the line can be removed from HTML report. 0106 sed -i '/$ORG_STAT_LINE/d' $SCANBUILD_DIR/index.html 0107 else 0108 NEW_STR="class=\"Q\">$STAT_VAL<\/td><td>" 0109 NEW_STAT_LINE=${ORG_STAT_LINE/$ORG_STR/$NEW_STR} 0110 sed -i "s|$ORG_STAT_LINE|$NEW_STAT_LINE|" $SCANBUILD_DIR/index.html 0111 fi 0112 0113 TOTAL_COUNT=$((TOTAL_COUNT+1)) 0114 done 0115 0116 # decrease total statistics with current TOTAL_COUNT 0117 0118 TOTAL_ORG_STAT_LINE=$(grep "CopyCheckedStateToCheckButtons(this)" $SCANBUILD_DIR/index.html | grep "AllBugsCheck") 0119 TOTAL_STAT_VAL=$(echo $TOTAL_ORG_STAT_LINE | grep -o -P '(?<=class=\"Q\">).*(?=<\/td><td>)') 0120 TOTAL_ORG_STR="class=\"Q\">$TOTAL_STAT_VAL<\/td><td>" 0121 TOTAL_STAT_VAL=$((TOTAL_STAT_VAL-TOTAL_COUNT)) 0122 TOTAL_NEW_STR="class=\"Q\">$TOTAL_STAT_VAL<\/td><td>" 0123 TOTAL_NEW_STAT_LINE=${TOTAL_ORG_STAT_LINE/$TOTAL_ORG_STR/$TOTAL_NEW_STR} 0124 sed -i "s|$TOTAL_ORG_STAT_LINE|$TOTAL_NEW_STAT_LINE|" $SCANBUILD_DIR/index.html 0125 0126 # Remove the report HTML files including current pattern to drop. 0127 0128 # URL_ENTRIES array contains the external report html file name to remove. 0129 URL_ENTRIES=() # clear array 0130 0131 for RITEM in "${REPORT_ENTRIES[@]}" ; do 0132 if [[ $RITEM = *report-* ]]; then 0133 URL_ENTRIES[${#URL_ENTRIES[*]}]=$(echo $RITEM | awk -F "\"" '{print $2}' | awk -F "#" '{print $1}') 0134 fi 0135 done 0136 0137 for UITEM in "${URL_ENTRIES[@]}" ; do 0138 rm -f $SCANBUILD_DIR/$UITEM 0139 0140 # Remove the lines from index.html including current pattern to drop. 0141 grep -v "$UITEM" $SCANBUILD_DIR/index.html > $SCANBUILD_DIR/temp && mv $SCANBUILD_DIR/temp $SCANBUILD_DIR/index.html 0142 done 0143 0144 done 0145 0146 if [[ $1 != "--nowebupdate" ]] ; then 0147 0148 # update www.digikam.org report section. 0149 updateReportToWebsite "clang" $SCANBUILD_DIR $TITLE $(parseGitBranch) 0150 0151 fi 0152 0153 cd $ORIG_DIR