From 5d3807ea598f853c7d059ed693cedcd170976ad5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Hern=C3=A1ndez=20Cordero?= Date: Fri, 24 May 2024 18:54:19 +0200 Subject: [PATCH] Fixed lcov error (#771) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fixed lcov error * Added more ignores * Used personal fork Signed-off-by: Alejandro Hernández Cordero --- linux_docker_resources/Dockerfile | 5 ++++- ros2_batch_job/__main__.py | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/linux_docker_resources/Dockerfile b/linux_docker_resources/Dockerfile index ad1331a9..2c97f99c 100644 --- a/linux_docker_resources/Dockerfile +++ b/linux_docker_resources/Dockerfile @@ -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 diff --git a/ros2_batch_job/__main__.py b/ros2_batch_job/__main__.py index 832b8941..a26bc59e 100644 --- a/ros2_batch_job/__main__.py +++ b/ros2_batch_job/__main__.py @@ -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 @@ -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