Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Mitchell <mmitche@microsoft.com>2015-04-22 19:23:46 +0300
committerMatt Mitchell <mmitche@microsoft.com>2015-04-22 20:21:31 +0300
commit08d86c901a969fb17ec2308710c5f38b0eee51d3 (patch)
tree1f14dd5201b7eaaf6a6cb464929ff7cb35d48c2a /src/coreclr/run-cppcheck.sh
parentd62e63db25c1739d7967f4c1a3c92d8bb84e1c27 (diff)
Initial commit of script to run cppcheck.
This script runs the cppcheck and sloccount tools for static analysis. The lab runs this script with the default arguments Mark script as executable Commit migrated from https://github.com/dotnet/coreclr/commit/34cc0c30f97f886ad5228568066c560367423dce
Diffstat (limited to 'src/coreclr/run-cppcheck.sh')
-rwxr-xr-xsrc/coreclr/run-cppcheck.sh117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/coreclr/run-cppcheck.sh b/src/coreclr/run-cppcheck.sh
new file mode 100755
index 00000000000..6888468bfa4
--- /dev/null
+++ b/src/coreclr/run-cppcheck.sh
@@ -0,0 +1,117 @@
+#!/usr/bin/env bash
+
+# This script automatically runs the basic cppcheck and sloccount tools to generate a static analysis report.
+
+usage()
+{
+ echo "Usage: run-cppcheck.sh [options] [files]"
+ echo "Option: Description"
+ echo " --no-sloccount Don't run sloccount"
+ echo " --no-cppcheck Don't run cppcheck"
+ echo " --cppcheck-out <file> Output file for cppcheck step. Default cppcheck.xml"
+ echo " --sloccount-out <file> Output file for sloccount step. Default sloccount.sc"
+ echo "Files:"
+ echo " files Files to run cppcheck through. Default src/**"
+}
+
+check_dependencies()
+{
+ # Check presence of cppcheck on the path
+ if [ "$RunCppCheck" == true ]
+ then
+ hash cppcheck 2>/dev/null || { echo >&2 "Please install cppcheck before running this script"; exit 1; }
+ fi
+
+ # Check presence of sloccount on the path
+ if [ "$RunSlocCount" == true ]
+ then
+ hash sloccount 2>/dev/null || { echo >&2 "Please install sloccount before running this script"; exit 1; }
+ fi
+}
+
+ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+RunSlocCount=true
+RunCppCheck=true
+Files="$ProjectRoot/src/**"
+FilesFromArgs=""
+CppCheckOutput="cppcheck.xml"
+SloccountOutput="sloccount.sc"
+# Get the number of processors available to the scheduler
+# Other techniques such as `nproc` only get the number of
+# processors available to a single process.
+if [ `uname` = "FreeBSD" ]; then
+NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'`
+else
+NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
+fi
+
+while [[ $# > 0 ]]
+do
+ opt="$1"
+ shift
+ case $opt in
+ -?|-h|--help)
+ usage
+ exit 1
+ ;;
+ --no-sloccount)
+ RunSlocCount=false
+ ;;
+ --no-cppcheck)
+ RunCppCheck=false
+ ;;
+ --cppcheck-out)
+ CppCheckOutput=$1
+ shift
+ ;;
+ --sloccount-out)
+ SloccountOutput=$1
+ shift
+ ;;
+ --*)
+ echo "Unrecognized option: $opt"
+ usage
+ exit 1
+ ;;
+ *)
+ FilesFromArgs="$FilesFromArgs $opt"
+ esac
+done
+
+if [ "$FilesFromArgs" != "" ];
+then
+ Files=$FilesFromArgs
+fi
+
+if [ "$CppCheckOutput" == "" ];
+then
+ echo "Expected: file for cppcheck output"
+ usage
+ exit 1
+fi
+
+if [ "$SloccountOutput" == "" ];
+then
+ echo "Expected: file for sloccount output"
+ usage
+ exit 1
+fi
+
+check_dependencies
+
+if [ "$RunCppCheck" == true ]
+then
+ echo "Running cppcheck for files: $Files"
+ cppcheck --enable=all -j $NumProc --xml --xml-version=2 --force $Files 2> $CppCheckOutput
+ CppCheckOutputs="$CppCheckOutput (cppcheck)"
+fi
+
+if [ "$RunSlocCount" == true ]
+then
+ echo "Running sloccount for files: $Files"
+ sloccount --wide --details $Files > $SloccountOutput
+ SlocCountOutputs="$SloccountOutput (sloccount)"
+fi
+
+echo Check finished. Results can be found in: $CppCheckOutputs $SlocCountOutputs
+exit 0 \ No newline at end of file