Skip to content

Commit

Permalink
Rework the gcov setup to only enable is gcov can be used (linux/gcc b…
Browse files Browse the repository at this point in the history
…asically).
  • Loading branch information
ionelmc committed Jun 4, 2020
1 parent 3da6256 commit e516588
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 15 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io
import os
import platform
import re
from glob import glob
from os.path import basename
Expand All @@ -27,6 +28,17 @@ def read(*names, **kwargs):
return fh.read()


# Enable code coverage for C code: we can't use CFLAGS=-coverage in tox.ini, since that may mess with compiling
# dependencies (e.g. numpy). Therefore we set SETUPPY_CFLAGS=-coverage in tox.ini and copy it to CFLAGS here (after
# deps have been safely installed).
if 'TOXENV' in os.environ and os.environ.get('SETUPPY_GCOV') == 'enabled' and platform.system() == 'Linux':
CFLAGS = ['-fprofile-arcs', '-ftest-coverage']
LFLAGS = ['-lgcov']
else:
CFLAGS = []
LFLAGS = []


class optional_build_ext(build_ext):
"""Allow the building of C extensions to fail."""
def run(self):
Expand Down Expand Up @@ -117,9 +129,9 @@ def _unavailable(self, e):
Extension(
splitext(relpath(path, 'src').replace(os.sep, '.'))[0],
sources=[path],
extra_compile_args=os.environ.get('SETUPPY_CFLAGS', '').split(),
extra_link_args=os.environ.get('SETUPPY_LFLAGS', '').split(),
include_dirs=[dirname(path)],
extra_compile_args=CFLAGS,
extra_link_args=LFLAGS,
include_dirs=[dirname(path)]
)
for root, _, _ in os.walk('src')
for path in glob(join(root, '*.c'))
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ basepython =
setenv =
PYTHONPATH={toxinidir}/tests
PYTHONUNBUFFERED=yes
cover: SETUPPY_CFLAGS=-fprofile-arcs -ftest-coverage
cover: SETUPPY_LFLAGS=-lgcov
cover: SETUPPY_GCOV=enabled
passenv =
*
usedevelop =
Expand Down

0 comments on commit e516588

Please sign in to comment.