Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect compiler version from gcc output if not specified. #686

Merged
merged 9 commits into from
Oct 30, 2022
14 changes: 7 additions & 7 deletions .github/workflows/deploy.yml
Expand Up @@ -16,34 +16,34 @@ jobs:
continue-on-error: ${{ startsWith(github.event.ref,'refs/heads/') }}

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: fetch all tags # need annotated tags for release checklist
run: |
git fetch --force --tags --depth=1
- name: For a dry run, don't verify tags and documentation
if: ${{ ! startsWith(github.event.ref, 'refs/tags/') }}
run: |
echo EXTRA_CHECKLIST_ARGS="--no-verify-tags --no-verify-docs-next-version" >> $GITHUB_ENV
echo "EXTRA_CHECKLIST_ARGS=--no-verify-tags --no-verify-docs-next-version" >> $GITHUB_ENV
- name: Run release_checklist
run: |
admin/release_checklist $EXTRA_CHECKLIST_ARGS 5.2

deploy:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
needs: release-check

env:
PYTHON_VERSION: "3.8"
CC: "gcc-8"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
nox --non-interactive --session build_wheel
- name: Upload distribution
if: ${{ success() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: dist
path: dist/**
Expand Down
37 changes: 17 additions & 20 deletions .github/workflows/test.yml
Expand Up @@ -11,15 +11,15 @@ on:
jobs:

milestone-check:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

continue-on-error: true

env:
PR_MILESTONE: "${{ github.event.pull_request.milestone.number }}"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Check if PR is assigned to a milestone
if: ${{ github.event_name == 'pull_request' }}
run: |
Expand All @@ -30,14 +30,14 @@ jobs:
exit 0

changelog-check:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04

env:
PR_BODY: "${{ github.event.pull_request.body }}"
CHANGELOG_ISSUE: ":issue:`${{ github.event.pull_request.number }}`"

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Check if PR is mentioned in changelog
if: ${{ always() }}
run: |
Expand Down Expand Up @@ -93,15 +93,12 @@ jobs:
include:

# Test additional compilers with Linux.
# Note that Clang-10 and Clang-13 is handled via Docker.
- os: ubuntu-18.04
gcc: gcc-5
python-version: '3.8'
- os: ubuntu-18.04
gcc: gcc-6
python-version: '3.8'
# Note that gcc-5, gcc-6, clang-10 and clang-13 is handled via Docker.
- os: ubuntu-20.04
gcc: gcc-9
python-version: '3.9'
- os: ubuntu-22.04
gcc: gcc-11
python-version: '3.10'

# Test minimum and maximum Python version on Windows.
Expand All @@ -113,16 +110,16 @@ jobs:
python-version: '3.10'

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup environment
run: |
# Enable coverage for specific target configurations
case "${{ matrix.os }}/${{ matrix.gcc }}/${{ matrix.python-version }}" in
windows-2019/gcc-8/3.7) USE_COVERAGE=true ;;
ubuntu-18.04/gcc-6/3.8) USE_COVERAGE=true ;;
ubuntu-20.04/gcc-9/3.9) USE_COVERAGE=true ;;
*) USE_COVERAGE=false ;;
esac
echo USE_COVERAGE=$USE_COVERAGE >> $GITHUB_ENV
echo "USE_COVERAGE=$USE_COVERAGE" >> $GITHUB_ENV
shell: bash
- name: Install msys with GCC (Windows)
if: ${{ startsWith(matrix.os,'windows-') }}
Expand All @@ -143,11 +140,11 @@ jobs:
- name: Install ninja
uses: seanmiddleditch/gha-setup-ninja@master
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Cache pip
uses: actions/cache@v2
uses: actions/cache@v3
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
Expand All @@ -166,7 +163,7 @@ jobs:
nox --non-interactive --session "tests_compiler(${{ matrix.gcc }})" -- --archive_differences
- name: Upload pytest test results
if: ${{ failure() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: diffs-${{ matrix.os }}-${{ matrix.gcc }}-${{ matrix.python-version }}
path: gcovr/tests/diff.zip
Expand All @@ -183,7 +180,7 @@ jobs:
make doc

run-docker:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
needs: [milestone-check, changelog-check]

strategy:
Expand All @@ -195,7 +192,7 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install nox
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build Docker
run: |
python3 -m nox --non-interactive --session "docker_qa_build_compiler(${{ matrix.gcc }})"
Expand All @@ -204,7 +201,7 @@ jobs:
python3 -m nox --non-interactive --session "docker_qa_run_compiler(${{ matrix.gcc }})"
- name: Upload pytest test results
if: ${{ failure() }}
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: diffs-docker-${{ matrix.gcc }}
path: gcovr/tests/diff.zip
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Expand Up @@ -24,7 +24,6 @@ New features and notable changes:
Bug fixes and small improvements:

- Fix :option:`--html-tab-size` feature. (:issue:`650`)

- Do not ignore returncode of `gcov`. (:issue:`653`)

Documentation:
Expand All @@ -33,6 +32,7 @@ Internal changes:

- Select the :option:`--html-theme` using CSS classes. (:issue:`650`)
- Change and extend ``cmake`` tests. (:issue:`676`)
- Detect ``gcc`` version for running tests. (:issue:`686`)

5.2 (06 August 2022)
--------------------
Expand Down
15 changes: 8 additions & 7 deletions CONTRIBUTING.rst
Expand Up @@ -144,8 +144,8 @@ How to set up a development environment
---------------------------------------

For working on gcovr, you will need a supported version of Python 3,
GCC version 5, 6 or 8 (other GCC versions are supported by gcovr,
but will cause spurious test failures) or clang version 10, ``make``,
GCC version 5, 6, 8, 9, 10 or 11 (other GCC versions are supported by gcovr,
but will cause spurious test failures) or clang version 10 or 13, ``make``,
``cmake`` and ``ninja``.
Please make sure that the tools are in the system ``PATH``.
On **Windows**, you will need to install a GCC toolchain as the
Expand All @@ -168,11 +168,12 @@ is needed.
- clang-13/clang++-13/llvm-cov

are available everything is OK.
For gcc-6, gcc-8, gcc-9, gcc-10, gcc-11, clang-10 and clang-13 you should use the
option ``CC=...`` see :ref:`run and filter tests <run tests>`.
If this isn't OK you
can set the reference data to use by setting the environment ``CC_REFERENCE=gcc-8``
or you have to create symlinks for the gcc executables with the following steps.
The test suite uses the newest GCC found in the PATH. To use another one you
need to set the environment ``CC=...`` see
:ref:`run and filter tests <run tests>`.
If you only have ``gcc`` in your path the version is detected to select the
correct reference.
You can also create symlinks for the gcc executables with the following steps.
You can check the GCC version with gcc --version. If the output says
version 8, you should also be able to run gcc-8 --version. Your Linux
distribution should have set all of this up already.
Expand Down
4 changes: 2 additions & 2 deletions doc/source/installation.rst
Expand Up @@ -29,9 +29,9 @@ Python:
Operating System:
Linux, Windows, and macOS.

The automated tests run on Ubuntu 18.04 and 20.04 and Windows Server 2019.
The automated tests run on Ubuntu 20.04, 22.04 and Windows Server 2019.

Compiler:
GCC and Clang.

The automated tests run on GCC 5, 6, and 8.
The automated tests run on GCC 5, 6, 8, 9, 10, 11 and clang 10 and 13.
8 changes: 8 additions & 0 deletions gcovr/tests/test_gcovr.py
Expand Up @@ -306,6 +306,14 @@ def pytest_generate_tests(metafunc):
and IS_MACOS,
reason="On MacOS the constructor is called twice",
),
pytest.mark.xfail(
name in ["decisions-neg-delta"] and IS_MACOS,
reason="On MacOS there is no branch for std::vector",
),
pytest.mark.xfail(
name in ["excl-line-branch"] and IS_MACOS,
reason="On MacOS there are different number of branches generated",
),
pytest.mark.xfail(
name == "gcc-abspath"
and (
Expand Down
67 changes: 55 additions & 12 deletions noxfile.py
Expand Up @@ -20,22 +20,24 @@
import glob
import os
import platform
import re
import shutil
import shlex
import subprocess
import sys
import nox


GCC_VERSIONS = [
"gcc-5",
"gcc-6",
"gcc-8",
"gcc-9",
"gcc-10",
"gcc-11",
"clang-10",
"gcc-10",
"gcc-9",
"gcc-8",
"gcc-6",
"gcc-5",
Spacetown marked this conversation as resolved.
Show resolved Hide resolved
"clang-13",
"clang-10",
]
GCC_VERSION2USE = os.path.split(os.environ.get("CC", "gcc-5"))[1]
DEFAULT_TEST_DIRECTORIES = ["doc", "gcovr"]
DEFAULT_LINT_ARGUMENTS = [
"setup.py",
Expand All @@ -49,6 +51,47 @@
nox.options.sessions = ["qa"]


def get_gcc_version_to_use():
# If the user explicitly set CC variable, use that directly without checks.
cc = os.environ.get("CC")
if cc:
return os.path.split(cc)[1]

# Find the first insalled compiler version we suport
for cc in GCC_VERSIONS:
if shutil.which(cc):
return cc

for cc in ["gcc", "clang"]:
output = subprocess.check_output([cc, "--version"]).decode()
# Ignore error code since we want to find a valid executable

# look for a line "gcc WHATEVER VERSION.WHATEVER" in output like:
# gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
# Copyright (C) 2019 Free Software Foundation, Inc.
# This is free software; see the source for copying conditions. There is NO
# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
search_gcc_version = re.search(r"^gcc\b.* ([0-9]+)\.\S+$", output, re.M)

# look for a line "WHATEVER clang version VERSION.WHATEVER" in output like:
# Apple clang version 13.1.6 (clang-1316.0.21.2.5)
# Target: arm64-apple-darwin21.5.0
# Thread model: posix
# InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
search_clang_version = re.search(r"\bclang version ([0-9]+)\.", output, re.M)

if search_gcc_version:
major_version = search_gcc_version.group(1)
return f"gcc-{major_version}"
elif search_clang_version:
major_version = search_clang_version.group(1)
return f"clang-{major_version}"

raise RuntimeError(
"Could not detect a valid compiler, you can defin one by setting the environment CC"
)


def set_environment(session: nox.Session, cc: str, check: bool = True) -> None:
if check and (shutil.which(cc) is None):
session.env["CC_REFERENCE"] = cc
Expand All @@ -64,7 +107,7 @@ def set_environment(session: nox.Session, cc: str, check: bool = True) -> None:
@nox.session(python=False)
def qa(session: nox.Session) -> None:
"""Run the quality tests for the default GCC version."""
session_id = f"qa_compiler({GCC_VERSION2USE})"
session_id = f"qa_compiler({get_gcc_version_to_use()})"
Spacetown marked this conversation as resolved.
Show resolved Hide resolved
session.log(f"Notify session {session_id}")
session.notify(session_id)

Expand Down Expand Up @@ -134,7 +177,7 @@ def doc(session: nox.Session) -> None:
@nox.session(python=False)
def tests(session: nox.Session) -> None:
"""Run the tests with the default GCC version."""
session_id = f"tests_compiler({GCC_VERSION2USE})"
session_id = f"tests_compiler({get_gcc_version_to_use()})"
session.log(f"Notify session {session_id}")
session.notify(session_id)

Expand Down Expand Up @@ -282,7 +325,7 @@ def docker_container_id(session: nox.Session, version: str) -> str:
@nox.session(python=False)
def docker_qa_build(session: nox.Session) -> None:
"""Build the docker container for the default GCC version."""
session_id = f"docker_qa_build({GCC_VERSION2USE})"
session_id = f"docker_qa_build({GCC_VERSIONS[0]})"
session.log(f"Notify session {session_id}")
session.notify(session_id)

Expand Down Expand Up @@ -324,7 +367,7 @@ def docker_qa_build_compiler(session: nox.Session, version: str) -> None:
@nox.session(python=False)
def docker_qa_run(session: nox.Session) -> None:
"""Run the docker container for the default GCC version."""
session_id = f"docker_qa_run_compiler({GCC_VERSION2USE})"
session_id = f"docker_qa_run_compiler({GCC_VERSIONS[0]})"
session.log(f"Notify session {session_id}")
session.notify(session_id)

Expand Down Expand Up @@ -378,7 +421,7 @@ def shell_join(args):
@nox.session(python=False)
def docker_qa(session: nox.Session) -> None:
"""Build and run the docker container for the default GCC version."""
session_id = f"docker_qa_compiler({GCC_VERSION2USE})"
session_id = f"docker_qa_compiler({GCC_VERSIONS[0]})"
session.log(f"Notify session {session_id}")
session.notify(session_id)

Expand Down