Skip to content

Commit

Permalink
Fixed lcov error (#771)
Browse files Browse the repository at this point in the history
* Fixed lcov error

* Added more ignores

* Used personal fork

Signed-off-by: Alejandro Hernández Cordero <[email protected]>
  • Loading branch information
ahcorde authored May 24, 2024
1 parent c1fbffe commit 5d3807e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion linux_docker_resources/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ RUN if test ${COMPILE_WITH_CLANG} = true; then apt-get update && apt-get install
# Install coverage build dependencies.
RUN apt-get update && apt-get install --no-install-recommends -y lcov

RUN pip3 install -U lcov_cobertura_fix
# There is a bug in upstream lcov-to-cobertura-xml with newer versions of lcov. There is an
# open PR for it in https://github.com/eriwen/lcov-to-cobertura-xml/pull/55, but until that is
# merged use the fork with the fix.
RUN pip3 install -U git+https://github.com/ahcorde/lcov-to-cobertura-xml@master

# Install the Connext binary from the OSRF repositories.
RUN if test \( ${PLATFORM} = x86 -a ${INSTALL_CONNEXT_DEBS} = true \); then apt-get update && RTI_NC_LICENSE_ACCEPTED=yes apt-get install -y rti-connext-dds-6.0.1; fi
Expand Down
24 changes: 22 additions & 2 deletions ros2_batch_job/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,36 @@ def __call__(self, parser, namespace, values, option_string=None):
setattr(args, name, space_directory)
return args

def get_lcov_version():
try:
result = subprocess.run(['lcov', '--version'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True, check=True)
version_output = result.stdout.strip().replace('lcov: LCOV version ', '')
return version_output
except subprocess.CalledProcessError as e:
return ""

def process_coverage(args, job):
print('# BEGIN SUBSECTION: coverage analysis')
# Capture all gdca/gcno files (all them inside buildspace)
coverage_file = os.path.join(args.buildspace, 'coverage.info')

version = get_lcov_version()
lcov_arguments = []
if version.startswith('2'):
lcov_arguments = ['--ignore-errors', 'inconsistent,inconsistent',
'--ignore-errors', 'mismatch,mismatch',
'--ignore-errors', 'negative,negative',
'--ignore-errors', 'unused,unused',
'--ignore-errors', 'empty,empty']

cmd = [
'lcov',
'--capture',
'--directory', args.buildspace,
'--output', str(coverage_file)]
'--output', str(coverage_file)] + lcov_arguments
print(cmd)
subprocess.run(cmd, check=True)
# Filter out system coverage and test code
Expand All @@ -288,7 +308,7 @@ def process_coverage(args, job):
'*/test/*',
'*/tests/*',
'*gtest_vendor*',
'*gmock_vendor*']
'*gmock_vendor*'] + lcov_arguments
print(cmd)
subprocess.run(cmd, check=True)
# Transform results to the cobertura format
Expand Down

0 comments on commit 5d3807e

Please sign in to comment.