File indexing completed on 2024-05-19 04:19:13

0001 #!/bin/bash
0002 
0003 # SPDX-FileCopyrightText: 2013-2024 by Gilles Caulier, <caulier dot gilles at gmail dot com>
0004 #
0005 # SPDX-License-Identifier: BSD-3-Clause
0006 #
0007 
0008 ########################################################################
0009 # checks if branch has something pending
0010 function parseGitDirty()
0011 {
0012     git diff --quiet --ignore-submodules HEAD 2>/dev/null; [ $? -eq 1 ] && echo "M"
0013 }
0014 
0015 ########################################################################
0016 # gets the current git branch
0017 function parseGitBranch()
0018 {
0019     git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
0020 }
0021 
0022 ########################################################################
0023 # get last commit hash prepended with @ (i.e. @8a323d0)
0024 function parseGitHash()
0025 {
0026     git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/-rev-\1/"
0027 }
0028 
0029 ########################################################################
0030 # Update www.digikam.org static analyze report section.
0031 # arg1: static analyzer name (clang, cppcheck, krazy, ...).
0032 # arg2: static analyzer report directory with html contents.
0033 # arg3: static analyzer report title.
0034 # arg4: git branch name.
0035 #
0036 function updateReportToWebsite()
0037 {
0038     WEBSITE_DIR="`pwd`/site"
0039 
0040     rm -fr $WEBSITE_DIR
0041 
0042     git clone git@invent.kde.org:websites/digikam-org $WEBSITE_DIR
0043 
0044     cd $WEBSITE_DIR
0045 
0046     git checkout -b dev remotes/origin/dev
0047 
0048     git rm -r $WEBSITE_DIR/static/reports/$1/$4/* || true
0049     mkdir -p $WEBSITE_DIR/static/reports/$1/$4
0050     cp -r $2/* $WEBSITE_DIR/static/reports/$1/$4/
0051 
0052     # Add new report contents in dev branch
0053 
0054     git add $WEBSITE_DIR/static/reports/$1/$4/*
0055     git commit . -m"update $1 static analyzer report $3."
0056     git push
0057 
0058     # update master branch
0059 
0060     git checkout master
0061     git merge dev -m"Update $1 static analyzer report $3.
0062 See https://www.digikam.org/reports/$1/$4 for details.
0063 CCMAIL: digikam-bugs-null@kde.org"
0064     git push
0065 
0066     echo "$1 Report $3 published to https://www.digikam.org/reports/$1/$4"
0067     echo "Web site will be synchronized in few minutes..."
0068 }
0069 
0070 ########################################################################
0071 # Extract Krazy configuration about unwanted directory to parse with static analyzer
0072 function krazySkipConfig()
0073 {
0074     KRAZY_FILE="`pwd`/../../.krazy"
0075     KRAZY_FILTERS=$(sed -n '/SKIP/p' ${KRAZY_FILE} | sed -e 's/SKIP //g' | sed -e 's/|/\n/g' | sed 's/^.\(.*\).$/\1/')
0076     echo "Directories to ignore from Krazy configuration: $KRAZY_FILTERS"
0077 }
0078 
0079 ########################################################################
0080 # Check CPU core available (Linux or MacOS)
0081 function checksCPUCores()
0082 {
0083     CPU_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
0084 
0085     if [[ $CPU_CORES -gt 1 ]]; then
0086         CPU_CORES=$((CPU_CORES-1))
0087     fi
0088 
0089     echo "CPU Cores to use : $CPU_CORES"
0090 }