[Libreoffice-commits] dev-tools.git: scan-build-report/README scan-build-report/scan-build-report.sh
Maarten Hoes (via logerrit)
logerrit at kemper.freedesktop.org
Thu Oct 22 15:10:11 UTC 2020
scan-build-report/README | 24 ++++
scan-build-report/scan-build-report.sh | 169 +++++++++++++++++++++++++++++++++
2 files changed, 193 insertions(+)
New commits:
commit 792d261fd250e23d863c4a9d044b08e173e3bd53
Author: Maarten Hoes <hoes.maarten at gmail.com>
AuthorDate: Thu Oct 15 13:23:39 2020 +0200
Commit: Stephan Bergmann <sbergman at redhat.com>
CommitDate: Thu Oct 22 17:09:52 2020 +0200
Initial commit of a script to automate a scan with 'scan-build' / clang-analyzer.
Change-Id: I6b4f59133c1e19a7cfbbd9a70924af8de03ad70e
Reviewed-on: https://gerrit.libreoffice.org/c/dev-tools/+/104372
Tested-by: Stephan Bergmann <sbergman at redhat.com>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/scan-build-report/README b/scan-build-report/README
new file mode 100644
index 0000000..209e911
--- /dev/null
+++ b/scan-build-report/README
@@ -0,0 +1,24 @@
+
+DESCRIPTION
+This script is for automating the process of running the clang static analyzer on the LibreOffice codebase.
+
+
+USAGE
+The script accepts 2 flags, both of which are mandatory. The first is '-s /dir1/dir2', which should point to the directory that contains the git repository of the LibreOffice codebase. The second is '-o /dir1/dir2', which should point to the directory the reports should be created in. All of the scripts output will be redirected to a logfile, and no output will be displayed to the tty on stdout or stderr.
+
+
+EXAMPLE
+An example of it's usage could be as simple as this :
+
+./scan-build-report.sh -s ~/src/libreoffice/core -o ~/tmp/scan-build-libreoffice/output
+
+which tells the script it should look for the LibreOffice git repo in ~/src/libreoffice/core, and create the reports in ~/tmp/scan-build-libreoffice/output.
+
+
+FILES
+/tmp/scan-build-report.log
+All output by the script will be redirected to a logfils, and no output file be send to stdout or stderr.
+
+
+NOTES
+You need at least clang9 (or newer) to run this script, as the needed '--exclude' option didn't exist before clang9.
diff --git a/scan-build-report/scan-build-report.sh b/scan-build-report/scan-build-report.sh
new file mode 100755
index 0000000..e063408
--- /dev/null
+++ b/scan-build-report/scan-build-report.sh
@@ -0,0 +1,169 @@
+#!/usr/bin/env bash
+# -*- tab-width : 4; indent-tabs-mode : nil -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at https://mozilla.org/MPL/2.0/.
+#
+
+[ "$DEBUG" ] && set -xv
+
+# save stdout and stderr
+exec 3>&1 4>&2 >/tmp/foo.log
+
+# redirect to log file
+exec > /tmp/scan-build-report.log 2>&1
+
+#
+# Functions
+#
+
+
+die()
+{
+ MESSAGE="$*"
+ echo "Error: $MESSAGE" >&2
+ exit 1;
+}
+
+usage()
+{
+ # restore stdout and stderr
+ exec 1>&3 2>&4
+
+ echo >&2 "Usage: scan-build-report -s [SOURCECODE DIRECTORY] -o [OUTPUT DIRECTORY]"
+ echo >&2 "-s source code directory"
+ echo >&2 "-o output directory"
+
+ exit 1
+}
+
+init()
+{
+ # Check if scan-build is available, and in the right version.
+ which scan-build >/dev/null 2>&1 || die "Failed to find 'scan-build'"
+ scan-build --help | grep "\--exclude" >/dev/null 2>&1 || die "'scan-build' version does not seem to support the '--exclude' option. Install a newer version of llvm/clang/scan-build (version 9 or higher)."
+
+ # Verify LO_SRC_DIR is set to something.
+ if [ -z "$LO_SRC_DIR" -o "$LO_SRC_DIR" = "" -o "$LO_SRC_DIR" = "/" ]
+ then
+ die "Sourcecode directory not set correctly."
+ fi
+
+ # Prepare output directory for the report
+ if [ -z "$OUTPUT_DIR" -o "$OUTPUT_DIR" = "" -o "$OUTPUT_DIR" = "/" ]
+ then
+ die "Output directory for reports 'OUTPUT_DIR' not set correctly."
+ fi
+
+ if [ -d "$OUTPUT_DIR" ]
+ then
+ rm -rf "$OUTPUT_DIR" || die "Failed to remove output directory $OUTPUT_DIR"
+ mkdir "$OUTPUT_DIR" || die "Failed to create output directory $OUTPUT_DIR"
+ else
+ mkdir "$OUTPUT_DIR" || die "Failed to create output directory $OUTPUT_DIR"
+ fi
+}
+
+get_lo_src()
+{
+ if [ ! -d "$LO_SRC_DIR" ]
+ then
+ git clone "$LO_GIT_URL" "$LO_SRC_DIR" || die "Failed to git clone $LO_GIT_URL in $LO_SRC_DIR"
+ else
+ if [ ! -d "$LO_SRC_DIR"/.git ]
+ then
+ die "$LO_SRC_DIR is not a git repository"
+ else
+ pushd "$LO_SRC_DIR" >/dev/null || die "Failed to change directory to $LO_SRC_DIR"
+ git pull || die "Failed to update git repository $LO_SRC_DIR"
+ popd > /dev/null || die "Failed to change directory out of $LO_SRC_DIR"
+ fi
+ fi
+}
+
+run_scan_build()
+{
+ pushd "$LO_SRC_DIR" > /dev/null || die "Failed to change directory to $LO_SRC_DIR"
+
+ if [ -f "$LO_SRC_DIR"/Makefile ]
+ then
+ make clean || die "Failed to run make clean in $LO_SRC_DIR"
+ fi
+
+ scan-build --use-cc=clang --use-c++=clang++ ./autogen.sh --disable-ccache --enable-debug --without-system-libs --without-system-headers || die "Failed to run scan-build ./autogen.sh"
+ scan-build --use-cc=clang --use-c++=clang++ --html-title="LibreOffice: SHA1=$COMMIT_SHA1, DATE=$COMMIT_DATE, TIME=$COMMIT_TIME" -o "$OUTPUT_DIR" --exclude "$LO_SRC_DIR"/*/UnpackedTarball/* --exclude "$LO_SRC_DIR"/workdir/* --exclude "$LO_SRC_DIR"/instdir/* --exclude "$LO_SRC_DIR"/external/ make || die "Failed to run scan-build make"
+
+ mv "$OUTPUT_DIR"/* "$REPORT_FIXED_DIR_NAME" || die "Failed to move $OUTPUT_DIR/* to $REPORT_FIXED_DIR_NAME."
+
+ popd > /dev/null || die "Failed to change directory out of $LO_SRC_DIR"
+}
+
+lcov_get_commit()
+{
+ pushd "$LO_SRC_DIR" > /dev/null || die "Failed to change directory to $LO_SRC_DIR"
+
+ COMMIT_SHA1=$(git log --date=iso | head -3 | awk '/^commit/ {print $2}')
+ COMMIT_DATE=$(git log --date=iso | head -3 | awk '/^Date/ {print $2}')
+ COMMIT_TIME=$(git log --date=iso | head -3 | awk '/^Date/ {print $3}')
+
+ popd > /dev/null || die "Failed to change directory out of $LO_SRC_DIR"
+}
+
+
+
+
+
+#
+# Main
+#
+
+
+export PYTHONIOENCODING=UTF-8
+
+export LANG=en_US.UTF-8
+export LC_CTYPE="en_US.UTF-8"
+export LC_NUMERIC="en_US.UTF-8"
+export LC_TIME="en_US.UTF-8"
+export LC_COLLATE="en_US.UTF-8"
+export LC_MONETARY="en_US.UTF-8"
+export LC_MESSAGES="en_US.UTF-8"
+export LC_PAPER="en_US.UTF-8"
+export LC_NAME="en_US.UTF-8"
+export LC_ADDRESS="en_US.UTF-8"
+export LC_TELEPHONE="en_US.UTF-8"
+export LC_MEASUREMENT="en_US.UTF-8"
+export LC_IDENTIFICATION="en_US.UTF-8"
+export LC_ALL="en_US.UTF-8"
+
+
+LO_GIT_URL=https://gerrit.libreoffice.org/core/
+
+if [ "$#" != "4" ]
+then
+ usage
+fi
+
+while getopts ":s:o:" opt
+do
+ case "$opt" in
+ s)
+ LO_SRC_DIR="$OPTARG"
+ ;;
+ o)
+ OUTPUT_DIR="$OPTARG"/output/
+ REPORT_FIXED_DIR_NAME="$OUTPUT_DIR"/scan-build-report/
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+
+init
+get_lo_src
+lcov_get_commit
+run_scan_build
More information about the Libreoffice-commits
mailing list