~rcr/rirc

aa98d031c6284a2666d99ff380a394a3492e5984 — Richard Robbins 2 years ago c0e76d7
remove sonarcloud coverage, fix static analysis scripts and builds
11 files changed, 152 insertions(+), 68 deletions(-)

M .builds/alpine.yml
M .builds/debian.yml
M Makefile
M scripts/compile_commands.sh
M scripts/coverage.sh
M scripts/pre-commit.sh
R scripts/{coverity_get.sh => sa_coverity_get.sh}
R scripts/{coverity_run.sh => sa_coverity_run.sh}
A scripts/sa_sonarcloud_get.sh
A scripts/sa_sonarcloud_run.sh
M scripts/sanitizers_test.sh
M .builds/alpine.yml => .builds/alpine.yml +4 -1
@@ 13,9 13,12 @@ tasks:
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      make -j $(nproc) clean check
      make clean
      make all
      make check

triggers:
  - action: email

M .builds/debian.yml => .builds/debian.yml +9 -28
@@ 10,9 10,6 @@ packages:
sources:
  - https://git.sr.ht/~rcr/rirc

environment:
  SONAR_VER: 4.4.0.2170

secrets:
  - 8c2439c9-5f91-4b19-b3c3-33d82f1b861f
  - a58d0951-f57f-44ef-8ef2-25f2f84f0e89


@@ 22,39 19,23 @@ tasks:
      cd rirc
      git submodule init
      git submodule update --recursive
      export MAKEFLAGS='-j $(nproc)'
  - build: |
      cd rirc
      make -j $(nproc) clean check
      make clean
      make all
      make check
  - static-analysis: |
      cd rirc
      branch=$(git name-rev --name-only HEAD)
      [ $branch = "remotes/origin/static_analysis" ] || complete-build
      [ $(git name-rev --name-only HEAD) = "remotes/origin/static_analysis" ] || complete-build
      set +x
      source ~/export_coverity
      source ~/export_sonarscan
      set -x
      # Coverity
      ./scripts/coverity_get.sh coverity
      ./scripts/coverity_run.sh coverity
      # Sonarcloud
      curl -o build-wrapper.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
      curl -o sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_VER-linux.zip
      unzip build-wrapper.zip
      unzip sonar-scanner.zip
      ./scripts/coverage.sh
      echo >> sonar-project.properties "sonar.branch.name=$branch"
      echo >> sonar-project.properties "sonar.cfamily.build-wrapper-output=bw-output"
      echo >> sonar-project.properties "sonar.cfamily.cache.enabled=false"
      echo >> sonar-project.properties "sonar.cfamily.gcov.reportsPath=."
      echo >> sonar-project.properties "sonar.cfamily.threads=1"
      echo >> sonar-project.properties "sonar.coverage.exclusions=test"
      echo >> sonar-project.properties "sonar.host.url=https://sonarcloud.io"
      echo >> sonar-project.properties "sonar.organization=rirc"
      echo >> sonar-project.properties "sonar.projectKey=rirc"
      echo >> sonar-project.properties "sonar.sources=src"
      echo >> sonar-project.properties "sonar.tests=test"
      ./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output make -j $(nproc) clean check
      ./sonar-scanner-$SONAR_VER-linux/bin/sonar-scanner
      ./scripts/sa_coverity_get.sh coverity
      ./scripts/sa_coverity_run.sh coverity
      ./scripts/sa_sonarcloud_get.sh sonarcloud
      ./scripts/sa_sonarcloud_run.sh sonarcloud

triggers:
  - action: email

M Makefile => Makefile +3 -5
@@ 70,7 70,8 @@ $(DIR_B)/%.db.o: $(DIR_S)/%.c config.h | $(DIR_B)
# Testcases
$(DIR_B)/%.t: $(DIR_T)/%.c $(OBJS_G) | $(DIR_B)
	@$(PP) $(CFLAGS_D) -MM -MP -MT $@ -MF $(@:.t=.t.d) $<
	@$(CC) $(CFLAGS_D) $(LDFLAGS) -o $@ $<
	@$(CC) $(CFLAGS_D) -c -o $(@:.t=.t.o) $<
	@$(CC) $(CFLAGS_D) -o $@ $(@:.t=.t.o)
	@$(TEST_EXT) ./$@

# Default config file


@@ 93,11 94,9 @@ $(TLS_LIBS): $(TLS_CONF)
all:
	@$(MAKE) --silent $(TLS_LIBS)
	@$(MAKE) --silent $(BIN_R)
	@$(MAKE) --silent $(BIN_D)

check:
	@$(MAKE) --silent $(TLS_LIBS)
	@$(MAKE) --silent $(BIN_R)
	@$(MAKE) --silent $(BIN_D)
	@$(MAKE) --silent $(OBJS_T)

clean:


@@ 123,5 122,4 @@ uninstall:

.PHONY: all check clean install uninstall

# Save tests for debugging
.PRECIOUS: $(OBJS_T)

M scripts/compile_commands.sh => scripts/compile_commands.sh +2 -2
@@ 2,9 2,9 @@

set -e

rm -f compile_commands.json

export CC=clang
export CC_EXT="-Wno-empty-translation-unit"

rm -f compile_commands.json

bear make clean rirc.debug

M scripts/coverage.sh => scripts/coverage.sh +32 -23
@@ 5,34 5,46 @@ set -e
CDIR="coverage"

export CC=gcc
export CC_EXT="-fprofile-arcs -ftest-coverage"
export CC_EXT="-fprofile-arcs -ftest-coverage -fprofile-abs-path"
export LD_EXT="-fprofile-arcs"

make -e clean test
export MAKEFLAGS="-e -j $(nproc)"

rm -rf $CDIR
mkdir -p $CDIR
rm -rf $CDIR && mkdir -p $CDIR

find . -name "*.gcno" -print0 | xargs -0 -I % mv % $CDIR
find . -name "*.gcda" -print0 | xargs -0 -I % mv % $CDIR
make clean
make check

FILTER=$(cat <<'EOF'
GCNO=$(find bld -name '*.t.gcno')

FILTER=$(cat << 'EOF'
{
	use Cwd;
	@results;
	@result_ds;
	@result_fs;
	if (eof()) {
		$cov = ($lc / $lt) * 100.0;
		printf("~\n");
		printf("~ total %21d/%d %7.2f%%\n", $lc, $lt, $cov);
		print "- Coverage:";
		print "- ", "=" x 40;
		print "- $_", for sort(@result_fs);
		print "- $_", for sort(@result_ds);
		print "- ", "=" x 40;
		printf("- Total %20d/%d  %6.2f%%\n", $lc, $lt, (($lc / $lt) * 100.0));
	} elsif ($p) {
		chomp $file;
		chomp $_;
		$file =~ s/'//g;
		my @s1 = split / /, $file;
		my @s2 = split /:/, $_;
		my @s3 = split / /, $s2[1];
		chop($s3[0]);
		printf("%-30s%4s %7s%%\n", $s1[1], $s3[2], $s3[0]);
		$lt = $lt + $s3[2];
		$lc = $lc + $s3[2] * ($s3[0] / 100.0);
		$file = substr($file, (length(getcwd()) + 6));
		@s1 = split /:/, $_;
		@s2 = split / /, $s1[1];
		$lt = $lt + $s2[2];
		$lc = $lc + $s2[2] * ($s2[0] / 100.0);
		$result = sprintf("%-25s  %4s  %7s", $file, $s2[2], $s2[0]);
		if ($file =~ m|src/.*/.*|) {
			push @result_fs, $result;
		} else {
			push @result_ds, $result;
		}
		$p = 0;
	}
	$p++ if /^File.*src.*c'/;


@@ 41,13 53,10 @@ FILTER=$(cat <<'EOF'
EOF
)

echo "~ Coverage:"

gcov -pr $CDIR/*.gcno | perl -ne "$FILTER" | sort
gcov --preserve-paths $GCNO | perl -lne "$FILTER"

find . -name "*gperf*.gcov" -print0 | xargs -0 -I % rm %
find . -name "*test#*.gcov" -print0 | xargs -0 -I % rm %
mv *.gcov $CDIR

if [ -x "$(command -v gcovr)" ]; then
	gcovr -r . --html --html-details --filter "src.*c$" -o $CDIR/index.html
	gcovr -r . --html --html-details --filter ".*src.*c$" -o $CDIR/index.html
fi

M scripts/pre-commit.sh => scripts/pre-commit.sh +1 -1
@@ 5,7 5,7 @@

echo "Running pre-commit hook..."

RESULTS=$(make test)
RESULTS=$(make check)

if [[ "$RESULTS" == *"failure"* ]];
then

R scripts/coverity_get.sh => scripts/sa_coverity_get.sh +2 -4
@@ 17,11 17,9 @@ COVERITY_TGZ="$1/coverity_tool.tgz"

mkdir "$1"

echo "curl https://scan.coverity.com/download/linux64 ..."

curl -fs --show-error https://scan.coverity.com/download/linux64 -o "$COVERITY_TGZ" --data "token=$COVERITY_TOKEN&project=rcr%2Frirc"
curl -fs --show-error https://scan.coverity.com/download/linux64 -o "$COVERITY_MD5" --data "token=$COVERITY_TOKEN&project=rcr%2Frirc&md5=1"
curl -fs --show-error https://scan.coverity.com/download/linux64 -o "$COVERITY_TGZ" --data "token=$COVERITY_TOKEN&project=rcr%2Frirc"

printf "%s\t$COVERITY_TGZ" "$(cat "$COVERITY_MD5")" | md5sum -c -
printf "%s\t$COVERITY_TGZ" "$(cat "$COVERITY_MD5")" | md5sum --quiet -c -

tar xzf "$COVERITY_TGZ" -C "$1" --strip-components 1

R scripts/coverity_run.sh => scripts/sa_coverity_run.sh +1 -1
@@ 21,7 21,7 @@ COVERITY_TAR="cov-int.tgz"

VERSION=$(git rev-parse --short HEAD)

PATH=$(pwd)/$1/bin:$PATH cov-build --dir "$COVERITY_OUT" make clean rirc rirc.debug test
PATH=$(pwd)/$1/bin:$PATH cov-build --dir "$COVERITY_OUT" make clean all check

tar czf "$COVERITY_TAR" "$COVERITY_OUT"


A scripts/sa_sonarcloud_get.sh => scripts/sa_sonarcloud_get.sh +30 -0
@@ 0,0 1,30 @@
#!/bin/bash

set -e

fail() { >&2 printf "%s\n" "$*"; exit 1; }

if [[ -z $1 ]]; then
	fail "Usage: '$0 dir'"
fi

SONAR_VER="4.5.0.2216"

BUILD_ZIP="$1/build-wrapper.zip"
SONAR_ZIP="$1/sonar-scanner.zip"
SONAR_MD5="$1/sonar-scanner.md5"

BUILD_ZIP_URL="https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip"
SONAR_ZIP_URL="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_VER-linux.zip"
SONAR_MD5_URL="https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_VER-linux.zip.md5"

mkdir "$1"

curl -fs --show-error "$BUILD_ZIP_URL" -o "$BUILD_ZIP"
curl -fs --show-error "$SONAR_ZIP_URL" -o "$SONAR_ZIP"
curl -fs --show-error "$SONAR_MD5_URL" -o "$SONAR_MD5"

printf "%s\t$SONAR_ZIP" "$(cat "$SONAR_MD5")" | md5sum --quiet -c -

unzip -qq "$BUILD_ZIP" -d "$1"
unzip -qq "$SONAR_ZIP" -d "$1"

A scripts/sa_sonarcloud_run.sh => scripts/sa_sonarcloud_run.sh +66 -0
@@ 0,0 1,66 @@
#!/bin/bash

# FIXME: undo the long live branch pattern in 
# https://sonarcloud.io/project/branches?id=rirc

set -e

fail() { >&2 printf "%s\n" "$*"; exit 1; }

if [[ -z $1 ]]; then
	fail "Usage: '$0 dir'"
fi

SONAR_VER="4.5.0.2216"

BUILD_WRAPPER_BIN="$1/build-wrapper-linux-x86/build-wrapper-linux-x86-64"
SONAR_SCANNER_BIN="$1/sonar-scanner-$SONAR_VER-linux/bin/sonar-scanner"

BUILD_WRAPPER_OUT="$1/bw-out"

SONAR_SCANNER_CONF="sonar-project.properties"

if [[ ! -f "$BUILD_WRAPPER_BIN" ]]; then
	fail "missing build-wrapper binary"
fi

if [[ ! -f "$SONAR_SCANNER_BIN" ]]; then
	fail "missing sonar-scanner binary"
fi

# FIXME:
# "the branch or pull request parameter is missing"

# FIXME: just forget about coverage until it works properly with llvm or something
#        ive wasted enough time on this...
#        add test coverage to README or something? or use something else like coveralls?

cat << EOF >> "$SONAR_SCANNER_CONF"
# Server
sonar.host.url = https://sonarcloud.io

# Project
sonar.organization   = rirc
sonar.projectKey     = rirc
sonar.projectName    = rirc
sonar.projectVersion = $(git rev-parse --short HEAD)
sonar.branch.name    = $(git rev-parse --symbolic-full-name HEAD)
sonar.links.homepage = https://rcr.io/rirc/
sonar.links.scm      = https://git.sr.ht/~rcr/rirc/
sonar.links.ci       = https://builds.sr.ht/~rcr/rirc/

# Source
sonar.sources = src,test

# C
sonar.cfamily.build-wrapper-output = $BUILD_WRAPPER_OUT
sonar.cfamily.cache.enabled        = false
sonar.cfamily.threads              = $(nproc)
EOF

make clean

eval "$BUILD_WRAPPER_BIN --out-dir $BUILD_WRAPPER_OUT make all check"
eval "$SONAR_SCANNER_BIN"

rm -f "$SONAR_SCANNER_CONF"

M scripts/sanitizers_test.sh => scripts/sanitizers_test.sh +2 -3
@@ 3,11 3,10 @@
set -e

export CC=clang

export CC_EXT="-fsanitize=address,undefined -fno-omit-frame-pointer"
export LD_EXT="-fsanitize=address,undefined"
export LD_EXT="-fsanitize=address,undefined -fuse-ld=lld"

# for core dumps:
# export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0"

make -e test
make -e clean check