[pygobject] gitlab-ci: Add Windows coverage support. See #168



commit 2d812a6bc4d0952997a3ed3c63c4b09d8c95c103
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Fri Feb 23 11:02:03 2018 +0100

    gitlab-ci: Add Windows coverage support. See #168
    
    Use coverage.py and cygwin lcov to generate coverage files.
    In the report generation step fixup the Windows paths in the coverage
    files to match the Linux/Docker ones.

 .gitlab-ci.yml                | 42 +++++++++++++++++++++++++++---------------
 .gitlab-ci/coverage-docker.sh |  3 +++
 .gitlab-ci/fixup-cov-paths.py | 35 +++++++++++++++++++++++++++++++++++
 .gitlab-ci/test-docker.sh     |  5 +++++
 .gitlab-ci/test-msys2.sh      | 33 +++++++++++++++++++++++++++++++--
 5 files changed, 101 insertions(+), 17 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 4f02af61..d6915e46 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -17,11 +17,19 @@ cache:
     paths:
       - coverage/
   script:
-   - mkdir -p _ccache
-   - export CCACHE_BASEDIR=${PWD}
-   - export CCACHE_DIR=${PWD}/_ccache
    - bash -x ./.gitlab-ci/test-docker.sh
 
+.mingw-defaults: &mingw-defaults
+  stage: build_and_test
+  tags:
+    - win32
+  artifacts:
+    paths:
+      - coverage/
+  script:
+    - C:\msys64\usr\bin\pacman --noconfirm -Syyuu
+    - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh"
+
 coverage:
   stage: coverage
   artifacts:
@@ -33,28 +41,32 @@ coverage:
     - bash -x ./.gitlab-ci/coverage-docker.sh
 
 python2-mingw32:
-  stage: build_and_test
-  tags:
-    - win32
   variables:
     PYTHON: "python2"
     MSYSTEM: "MINGW32"
     CHERE_INVOKING: "yes"
-  script:
-    - C:\msys64\usr\bin\pacman --noconfirm -Syyuu --ask 20
-    - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh"
+  <<: *mingw-defaults
+
+python2-mingw64:
+  variables:
+    PYTHON: "python2"
+    MSYSTEM: "MINGW64"
+    CHERE_INVOKING: "yes"
+  <<: *mingw-defaults
 
 python3-mingw32:
-  stage: build_and_test
-  tags:
-    - win32
   variables:
     PYTHON: "python3"
     MSYSTEM: "MINGW32"
     CHERE_INVOKING: "yes"
-  script:
-    - C:\msys64\usr\bin\pacman --noconfirm -Syyuu --ask 20
-    - C:\msys64\usr\bin\bash -lc "bash -x ./.gitlab-ci/test-msys2.sh"
+  <<: *mingw-defaults
+
+python3-mingw64:
+  variables:
+    PYTHON: "python3"
+    MSYSTEM: "MINGW64"
+    CHERE_INVOKING: "yes"
+  <<: *mingw-defaults
 
 python2.7:
   variables:
diff --git a/.gitlab-ci/coverage-docker.sh b/.gitlab-ci/coverage-docker.sh
index 6e74a797..0f1a0e9a 100755
--- a/.gitlab-ci/coverage-docker.sh
+++ b/.gitlab-ci/coverage-docker.sh
@@ -4,6 +4,9 @@ set -e
 
 python -m pip install coverage
 
+# Make the Windows paths match our current layout
+python ./.gitlab-ci/fixup-cov-paths.py coverage/.coverage* coverage/*.lcov
+
 python -m coverage combine coverage
 python -m coverage html -d coverage/report-python
 genhtml --ignore-errors=source --rc lcov_branch_coverage=1 \
diff --git a/.gitlab-ci/fixup-cov-paths.py b/.gitlab-ci/fixup-cov-paths.py
new file mode 100644
index 00000000..a6f43e44
--- /dev/null
+++ b/.gitlab-ci/fixup-cov-paths.py
@@ -0,0 +1,35 @@
+from __future__ import print_function
+
+import sys
+import os
+import io
+
+
+def main(argv):
+    # Fix paths in coverage files to match our current source layout
+    # so that coverage report generators can find the source.
+    # Mostly needed for Windows.
+    paths = argv[1:]
+
+    for path in paths:
+        print("cov-fixup:", path)
+        text = io.open(path, "r", encoding="utf-8").read()
+        text = text.replace("\\\\", "/")
+        end = text.index("/gi/")
+        try:
+            # coverage.py
+            start = text[:end].rindex("\"") + 1
+        except ValueError:
+            # lcov
+            start = text[:end].rindex(":") + 1
+        old_root = text[start:end]
+        new_root = 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-docker.sh b/.gitlab-ci/test-docker.sh
index 97d4805a..6d09b22d 100755
--- a/.gitlab-ci/test-docker.sh
+++ b/.gitlab-ci/test-docker.sh
@@ -4,6 +4,11 @@ set -e
 
 python --version
 
+# ccache setup
+mkdir -p _ccache
+export CCACHE_BASEDIR="$(pwd)"
+export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
+
 python -m pip install git+https://github.com/pygobject/pycairo.git
 python -m pip install flake8 pytest pytest-faulthandler coverage
 
diff --git a/.gitlab-ci/test-msys2.sh b/.gitlab-ci/test-msys2.sh
index 84c1c12c..9b44a8ff 100755
--- a/.gitlab-ci/test-msys2.sh
+++ b/.gitlab-ci/test-msys2.sh
@@ -2,6 +2,10 @@
 
 set -e
 
+# skip the fontconfig cache, it's slooowww
+export MSYS2_FC_CACHE_SKIP=1
+export PANGOCAIRO_BACKEND=win32
+
 export PATH="/c/msys64/$MSYSTEM/bin:$PATH"
 if [[ "$MSYSTEM" == "MINGW32" ]]; then
     export MSYS2_ARCH="i686"
@@ -14,15 +18,40 @@ pacman --noconfirm -Suy
 pacman --noconfirm -S --needed \
     base-devel \
     mingw-w64-$MSYS2_ARCH-toolchain \
+    mingw-w64-$MSYS2_ARCH-ccache \
     mingw-w64-$MSYS2_ARCH-$PYTHON-cairo \
     mingw-w64-$MSYS2_ARCH-$PYTHON \
     mingw-w64-$MSYS2_ARCH-$PYTHON-pip \
     mingw-w64-$MSYS2_ARCH-$PYTHON-pytest \
+    mingw-w64-$MSYS2_ARCH-$PYTHON-coverage \
     mingw-w64-$MSYS2_ARCH-gobject-introspection \
     mingw-w64-$MSYS2_ARCH-libffi \
     mingw-w64-$MSYS2_ARCH-glib2 \
     mingw-w64-$MSYS2_ARCH-gtk3 \
     git \
-    autoconf-archive
+    perl
+
+# ccache setup
+export PATH="$MSYSTEM/lib/ccache/bin:$PATH"
+mkdir -p _ccache
+export CCACHE_BASEDIR="$(pwd)"
+export CCACHE_DIR="${CCACHE_BASEDIR}/_ccache"
+
+# coverage setup
+export CFLAGS="-coverage -ftest-coverage -fprofile-arcs"
+PYVER=$($PYTHON -c "import sys; sys.stdout.write(''.join(map(str, sys.version_info[:3])))")
+COV_DIR="$(pwd)/coverage"
+COV_KEY="${MSYSTEM}.${PYVER}"
+mkdir -p "${COV_DIR}"
+export COVERAGE_FILE="${COV_DIR}/.coverage.${COV_KEY}"
+
+$PYTHON setup.py build_tests
+MSYSTEM= $PYTHON -m coverage run tests/runtests.py
+
+curl -O -J -L "https://github.com/linux-test-project/lcov/releases/download/v1.13/lcov-1.13.tar.gz";
+tar -xvzf lcov-1.13.tar.gz
 
-$PYTHON setup.py test
+./lcov-1.13/bin/lcov \
+    --rc lcov_branch_coverage=1 --no-external \
+    --directory . --capture --output-file \
+    "${COV_DIR}/${COV_KEY}.lcov"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]