2

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...

code_fodder
  • 15,263
  • 17
  • 90
  • 167

2 Answers2

2

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.

amon
  • 57,091
  • 2
  • 89
  • 149
  • thanks very much - we need to use mirrors due to anal levels of network security : ( ... so I think I understand all that you wrote - some I have found out by trial and error also. I have gcovr working, but only when I set python alternatives to 3.x (I did this before you posted your answer). Now if I reset that python alt to 2.x I cannot run my gcovr 4.2 version that I installed with `pip` (you can see the specific line in my answer below)... so probably right about now I am wandering how to fix this. I think: 1. uninstall gcovr (with apt and pip), 2. reset python alts to 2.x ... – code_fodder Jan 05 '21 at 20:14
  • 3. Re-install gcovr with pip and then with pip3 - does that sound about right to you? – code_fodder Jan 05 '21 at 20:14
0

Updating gcovr to be inline with gcc is a little bit tricky - all the steps I mentioned above are valid and should infact work - so I will leave this question here since I think it has some value and I can't yet find this method anywhere else.

The final part of my puzzle was that I needed to use a local mirror so by running:

sudo pip install --index-url=https://xxxxxxx/artifactory/api/pypi/pypi/simple gcovr --user

With python alternatives set to python 3.x, then this installed gcovr at version 4. and then my coverage commands all started to work correctly.

But if you did not want to switch to python 3.x then (as long as you have pythong 3.x installed you can do the same command using pip3 instead of pip - this is untested by me.

code_fodder
  • 15,263
  • 17
  • 90
  • 167