Search code examples
pythonlinuxubuntugccgcovr

how to update/install gcovr to match my updated compiler gcc


I have ubuntu 18.04 and I had gcc version 7 on there.

I updated gcc to version 8 using alternatives and slaved my gcov version to gcc also to keep them compatible (which worked nicley), but gcovr itself is stuck at version 3.4 and it needs to be ~version 4.x

    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700 \
        --slave /usr/bin/g++ g++ /usr/bin/g++-7                            \
        --slave /usr/bin/gcov gcov /usr/bin/gcov-7
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 \
        --slave /usr/bin/g++ g++ /usr/bin/g++-8                            \
        --slave /usr/bin/gcov gcov /usr/bin/gcov-8

I had a bit of a dig around and I think gcovr i sjust a python script. I have python 2.7 installed and I also have python .36 installed.

I tried installing gcovr with pip:

sudo -H pip install gcovr
Requirement already satisfied: gcovr in /usr/lib/python2.7/dist-packages

This website shows the versions I need: here

Here is the relevant table:

Python  gcovr
2.6     3.4
3.4     4.1

So I know what I want and where I need to get to, but I don't know how to get there. I think my pip install command invokes python 2.7 pip (my python knowledge is basically zero) so I get the feeling I need to invoke pip for python 3.6 to get the gcovr version I want (could be way off here). Knowing that I have various versions of python, it looks like my default version is 2.7: python --version: 2.7

Any clues how I can get gcovr updated (and maybe even my python version to default to 3.x)?

Update 1

I got a tiny bit further. I installed python alternatives:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2

Now I can swtich between python 2.x and 3.x. When I set python to 3.x and try to install gcovr I get:

sudo -H pip install gcovr
Collecting gcovr
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/gcovr/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/gcovr/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/gcovr/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/gcovr/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),)': /simple/gcovr/
  Could not find a version that satisfies the requirement gcovr (from versions: )
No matching distribution found for gcovr

I suppose I could just download a newer version of the gcovr script...


Solution

  • Gcovr is independent of the GCC version, but GCC 8 did slightly change the coverage format. These changes were first implemented in gcovr 4.0, but further improvements were added in gcovr 4.2. If you are using a compiler other than the one named gcc or g++ in your paths, you should tell gcovr which gcov version it needs to use (e.g. gcovr --gcov-executable gcov-7 ...).

    The problem in this case is that python and pip generally refer to the Python 2.7 versions, not to the Python 3 versions. The Python 3.x variants are available as python3 and pip3. Thus, the correct invocation would be:

    $ sudo pip3 install gcovr
    

    (Should also work without sudo if installing into your home directory.)

    If you want to install gcovr for a specific python, you can invoke pip like python -m pip ...:

    $ sudo /path/to/your/python3 -m pip install gcovr
    

    If you want to upgrade an existing installed Python package, you must explicitly tell pip to do so:

    $ pip install -U gcovr
    

    However, you must not use pip to update packages that were installed through apt. Instead, remove the apt package first, e.g. with sudo apt-get remove gcovr.

    To install a specific gcovr version, use a requirement specification like gcovr == 4.2 (but remember to use quotes):

    $ pip3 install 'gcovr == 4.2'
    

    You should not have to use mirrors unless required to do so by your local network circumstances, e.g. if you don't have an internet connection. If you are subject to TLS interception (which is essentially a man in the middle attack that breaks ordinary certificate validation), you might want to instead tell pip about your alternative CA with pip --cert /path/to/ca .... However, if you just don't want to install from PyPI you can also install from Github, e.g. pip install git+https://github.com/gcovr/gcovr.git for the development version, or pip install https://github.com/gcovr/gcovr/archive/4.2.tar.gz for a specific release.

    When upgrading gcovr, please also read the changelog as there have been changes that break compatibility in some edge cases, e.g. around argument handling or heuristics for finding out-of-source builds. This could change coverage metrics in some cases.

    Please also note that Python 2 is EOL and no longer supported. The next gcovr version (expected to be 4.3) will drop support for Python 2.x and 3.5. Even though Python 2.7 is dead, you should not change python to refer to Python 3 – this will break many programs on your system, potentially including vital operating system components. Instead, always explicitly use python3 if you want Python 3.