diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ef78ce5f3..194a14590 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,6 +2,8 @@ image: registry.gitlab.gnome.org/gnome/glib/master:v1 stages: - build + - coverage + - deploy cache: paths: @@ -9,18 +11,23 @@ cache: fedora-meson-x86_64: stage: build + variables: + CFLAGS: "-coverage -ftest-coverage -fprofile-arcs" script: - meson --prefix /usr --libdir /usr/lib64 --buildtype debug --werror -Dsystemtap=true -Ddtrace=true _build . - cd _build - ninja - meson test + - cd .. + - mkdir -p _coverage + - lcov --rc lcov_branch_coverage=1 --directory . --capture --no-external --output-file "_coverage/${CI_JOB_NAME}.lcov" except: - tags artifacts: - when: on_failure name: "glib-_${CI_COMMIT_REF_NAME}" paths: - "${CI_PROJECT_DIR}/_build/meson-logs" + - "${CI_PROJECT_DIR}/_coverage" msys2-mingw32: stage: build @@ -32,6 +39,27 @@ msys2-mingw32: script: - C:\msys64\usr\bin\pacman --noconfirm -Syyuu --ask 20 - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh" + artifacts: + paths: + - _coverage/ + +coverage: + stage: coverage + artifacts: + paths: + - _coverage/ + script: + - bash -x ./.gitlab-ci/coverage-docker.sh + +pages: + stage: deploy + script: + - mv _coverage/ public/ + artifacts: + paths: + - public + only: + - master dist-job: stage: build diff --git a/.gitlab-ci/Dockerfile b/.gitlab-ci/Dockerfile index 1089d0cdf..dab235166 100644 --- a/.gitlab-ci/Dockerfile +++ b/.gitlab-ci/Dockerfile @@ -3,6 +3,7 @@ FROM fedora:27 RUN dnf -y install \ desktop-file-utils \ elfutils-libelf-devel \ + findutils \ gcc \ gcc-c++ \ gettext \ @@ -11,6 +12,7 @@ RUN dnf -y install \ glibc-headers \ gtk-doc \ itstool \ + lcov \ libattr-devel \ libffi-devel \ libmount-devel \ diff --git a/.gitlab-ci/coverage-docker.sh b/.gitlab-ci/coverage-docker.sh new file mode 100755 index 000000000..49118d606 --- /dev/null +++ b/.gitlab-ci/coverage-docker.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +set -e + +# Fixup Windows paths +python3 ./.gitlab-ci/fixup-cov-paths.py _coverage/*.lcov + +# Remove coverage from generated code in the build directory +for path in _coverage/*.lcov; do + lcov --rc lcov_branch_coverage=1 -r "${path}" '*/_build/*' -o "$(pwd)/${path}" +done + +genhtml \ + --ignore-errors=source \ + --rc lcov_branch_coverage=1 \ + _coverage/*.lcov \ + -o _coverage/coverage + +cd _coverage +rm -f *.lcov + +cat >index.html < + + + + +EOL diff --git a/.gitlab-ci/fixup-cov-paths.py b/.gitlab-ci/fixup-cov-paths.py new file mode 100644 index 000000000..d614b60e6 --- /dev/null +++ b/.gitlab-ci/fixup-cov-paths.py @@ -0,0 +1,29 @@ +import sys +import os +import io + + +def main(argv): + # Fix paths in lcov files generated on a Windows host so they match our + # current source layout. + paths = argv[1:] + + for path in paths: + print("cov-fixup:", path) + text = io.open(path, "r", encoding="utf-8").read() + text = text.replace("\\\\", "/") + glib_dir = "/glib/" + end = text.index(glib_dir) + start = text[:end].rindex(":") + 1 + old_root = text[start:end] + assert os.path.basename(os.getcwd()) == "glib" + new_root = os.path.dirname(os.getcwd()) + if old_root != new_root: + print("replacing %r with %r" % (old_root, new_root)) + text = text.replace(old_root, new_root) + with io.open(path, "w", encoding="utf-8") as h: + h.write(text) + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh index 4b09b0210..a3b0ef906 100755 --- a/.gitlab-ci/test-msys2.sh +++ b/.gitlab-ci/test-msys2.sh @@ -28,6 +28,7 @@ export CCACHE_BASEDIR="$(pwd)" export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache" pip3 install --upgrade --user meson export PATH="$HOME/.local/bin:$PATH" +export CFLAGS="-coverage -ftest-coverage -fprofile-arcs" meson --werror --buildtype debug _build cd _build @@ -35,3 +36,16 @@ ninja # FIXME: fix the test suite meson test || true + +cd .. +curl -O -J -L "https://github.com/linux-test-project/lcov/releases/download/v1.13/lcov-1.13.tar.gz" +echo "44972c878482cc06a05fe78eaa3645cbfcbad6634615c3309858b207965d8a23 lcov-1.13.tar.gz" | sha256sum -c +tar -xvzf lcov-1.13.tar.gz + +mkdir -p _coverage +./lcov-1.13/bin/lcov \ + --rc lcov_branch_coverage=1 \ + --directory . \ + --capture \ + --no-external \ + --output-file "_coverage/${CI_JOB_NAME}.lcov"