Exemplo n.º 1
0
def coverage(source_root, build_root, log_dir):
    (gcovr_exe, lcov_exe, genhtml_exe) = environment.find_coverage_tools()
    if gcovr_exe:
        subprocess.check_call([
            gcovr_exe,
            '-x',
            '-r',
            source_root,
            '-o',
            os.path.join(log_dir, 'coverage.xml'),
        ])
        subprocess.check_call([
            gcovr_exe,
            '-r',
            source_root,
            '-o',
            os.path.join(log_dir, 'coverage.txt'),
        ])
    if lcov_exe and genhtml_exe:
        htmloutdir = os.path.join(log_dir, 'coveragereport')
        covinfo = os.path.join(log_dir, 'coverage.info')
        initial_tracefile = covinfo + '.initial'
        run_tracefile = covinfo + '.run'
        subprocess.check_call([
            lcov_exe, '--directory', build_root, '--capture', '--initial',
            '--output-file', initial_tracefile
        ])
        subprocess.check_call([
            lcov_exe,
            '--directory',
            build_root,
            '--capture',
            '--output-file',
            run_tracefile,
            '--no-checksum',
            '--rc',
            'lcov_branch_coverage=1',
        ])
        # Join initial and test results.
        subprocess.check_call([
            lcov_exe, '-a', initial_tracefile, '-a', run_tracefile, '-o',
            covinfo
        ])
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/include/*')
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/local/include/*')
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/src/*')
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/lib/llvm-*/include/*')
        subprocess.check_call([
            genhtml_exe, '--prefix', build_root, '--output-directory',
            htmloutdir, '--title', 'Code coverage', '--legend',
            '--show-details', '--branch-coverage', covinfo
        ])
    return 0
Exemplo n.º 2
0
def coverage(source_root, build_root, log_dir):
    (gcovr_exe, lcov_exe, genhtml_exe) = environment.find_coverage_tools()
    if gcovr_exe:
        subprocess.check_call([gcovr_exe,
                               '-x',
                               '-r', source_root,
                               '-o', os.path.join(log_dir, 'coverage.xml'),
                               ])
        subprocess.check_call([gcovr_exe,
                               '-r', source_root,
                               '-o', os.path.join(log_dir, 'coverage.txt'),
                               ])
    if lcov_exe and genhtml_exe:
        htmloutdir = os.path.join(log_dir, 'coveragereport')
        covinfo = os.path.join(log_dir, 'coverage.info')
        initial_tracefile = covinfo + '.initial'
        run_tracefile = covinfo + '.run'
        subprocess.check_call([lcov_exe,
                               '--directory', build_root,
                               '--capture',
                               '--initial',
                               '--output-file',
                               initial_tracefile])
        subprocess.check_call([lcov_exe,
                               '--directory', build_root,
                               '--capture',
                               '--output-file', run_tracefile,
                               '--no-checksum',
                               '--rc', 'lcov_branch_coverage=1',
                               ])
        # Join initial and test results.
        subprocess.check_call([lcov_exe,
                               '-a', initial_tracefile,
                               '-a', run_tracefile,
                               '-o', covinfo])
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/include/*')
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/local/include/*')
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/src/*')
        remove_dir_from_trace(lcov_exe, covinfo, '/usr/lib/llvm-*/include/*')
        subprocess.check_call([genhtml_exe,
                               '--prefix', build_root,
                               '--output-directory', htmloutdir,
                               '--title', 'Code coverage',
                               '--legend',
                               '--show-details',
                               '--branch-coverage',
                               covinfo])
    return 0
Exemplo n.º 3
0
def coverage(outputs, source_root, subproject_root, build_root, log_dir):
    outfiles = []
    exitcode = 0

    (gcovr_exe, gcovr_new_rootdir, lcov_exe,
     genhtml_exe) = environment.find_coverage_tools()

    # gcovr >= 3.1 interprets rootdir differently
    if gcovr_new_rootdir:
        gcovr_rootdir = build_root
    else:
        gcovr_rootdir = source_root

    if not outputs or 'xml' in outputs:
        if gcovr_exe:
            subprocess.check_call([
                gcovr_exe,
                '-x',
                '-r',
                gcovr_rootdir,
                '-e',
                subproject_root,
                '-o',
                os.path.join(log_dir, 'coverage.xml'),
            ])
            outfiles.append(('Xml', pathlib.Path(log_dir, 'coverage.xml')))
        elif outputs:
            print('gcovr needed to generate Xml coverage report')
            exitcode = 1

    if not outputs or 'text' in outputs:
        if gcovr_exe:
            subprocess.check_call([
                gcovr_exe,
                '-r',
                gcovr_rootdir,
                '-e',
                subproject_root,
                '-o',
                os.path.join(log_dir, 'coverage.txt'),
            ])
            outfiles.append(('Text', pathlib.Path(log_dir, 'coverage.txt')))
        elif outputs:
            print('gcovr needed to generate text coverage report')
            exitcode = 1

    if not outputs or 'html' in outputs:
        if lcov_exe and genhtml_exe:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            covinfo = os.path.join(log_dir, 'coverage.info')
            initial_tracefile = covinfo + '.initial'
            run_tracefile = covinfo + '.run'
            raw_tracefile = covinfo + '.raw'
            subprocess.check_call([
                lcov_exe, '--directory', build_root, '--capture', '--initial',
                '--output-file', initial_tracefile
            ])
            subprocess.check_call([
                lcov_exe,
                '--directory',
                build_root,
                '--capture',
                '--output-file',
                run_tracefile,
                '--no-checksum',
                '--rc',
                'lcov_branch_coverage=1',
            ])
            # Join initial and test results.
            subprocess.check_call([
                lcov_exe, '-a', initial_tracefile, '-a', run_tracefile, '--rc',
                'lcov_branch_coverage=1', '-o', raw_tracefile
            ])
            # Remove all directories outside the source_root from the covinfo
            subprocess.check_call([
                lcov_exe, '--extract', raw_tracefile,
                os.path.join(source_root, '*'), '--rc',
                'lcov_branch_coverage=1', '--output-file', covinfo
            ])
            # Remove all directories inside subproject dir
            subprocess.check_call([
                lcov_exe, '--remove', covinfo,
                os.path.join(subproject_root, '*'), '--rc',
                'lcov_branch_coverage=1', '--output-file', covinfo
            ])
            subprocess.check_call([
                genhtml_exe, '--prefix', build_root, '--output-directory',
                htmloutdir, '--title', 'Code coverage', '--legend',
                '--show-details', '--branch-coverage', covinfo
            ])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif gcovr_exe and gcovr_new_rootdir:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            if not os.path.isdir(htmloutdir):
                os.mkdir(htmloutdir)
            subprocess.check_call([
                gcovr_exe,
                '--html',
                '--html-details',
                '--print-summary',
                '-r',
                build_root,
                '-e',
                subproject_root,
                '-o',
                os.path.join(htmloutdir, 'index.html'),
            ])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif outputs:
            print(
                'lcov/genhtml or gcovr >= 3.2 needed to generate Html coverage report'
            )
            exitcode = 1

    if not outputs and not outfiles:
        print('Need gcovr or lcov/genhtml to generate any coverage reports')
        exitcode = 1

    if outfiles:
        print('')
        for (filetype, path) in outfiles:
            print(filetype + ' coverage report can be found at', path.as_uri())

    return exitcode
Exemplo n.º 4
0
def coverage(outputs: T.List[str], source_root: str, subproject_root: str, build_root: str, log_dir: str, use_llvm_cov: bool) -> int:
    outfiles = []
    exitcode = 0

    (gcovr_exe, gcovr_new_rootdir, lcov_exe, genhtml_exe, llvm_cov_exe) = environment.find_coverage_tools()

    # gcovr >= 4.2 requires a different syntax for out of source builds
    if gcovr_new_rootdir:
        gcovr_base_cmd = [gcovr_exe, '-r', source_root, build_root]
    else:
        gcovr_base_cmd = [gcovr_exe, '-r', build_root]

    if use_llvm_cov:
        gcov_exe_args = ['--gcov-executable', llvm_cov_exe + ' gcov']
    else:
        gcov_exe_args = []

    if not outputs or 'xml' in outputs:
        if gcovr_exe:
            subprocess.check_call(gcovr_base_cmd +
                                  ['-x',
                                   '-e', subproject_root,
                                   '-o', os.path.join(log_dir, 'coverage.xml')
                                   ] + gcov_exe_args)
            outfiles.append(('Xml', pathlib.Path(log_dir, 'coverage.xml')))
        elif outputs:
            print('gcovr >= 3.3 needed to generate Xml coverage report')
            exitcode = 1

    if not outputs or 'text' in outputs:
        if gcovr_exe:
            subprocess.check_call(gcovr_base_cmd +
                                  ['-e', subproject_root,
                                   '-o', os.path.join(log_dir, 'coverage.txt')
                                   ] + gcov_exe_args)
            outfiles.append(('Text', pathlib.Path(log_dir, 'coverage.txt')))
        elif outputs:
            print('gcovr >= 3.3 needed to generate text coverage report')
            exitcode = 1

    if not outputs or 'html' in outputs:
        if lcov_exe and genhtml_exe:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            covinfo = os.path.join(log_dir, 'coverage.info')
            initial_tracefile = covinfo + '.initial'
            run_tracefile = covinfo + '.run'
            raw_tracefile = covinfo + '.raw'
            if use_llvm_cov:
                # Create a shim to allow using llvm-cov as a gcov tool.
                if mesonlib.is_windows():
                    llvm_cov_shim_path = os.path.join(log_dir, 'llvm-cov.bat')
                    with open(llvm_cov_shim_path, 'w') as llvm_cov_bat:
                        llvm_cov_bat.write('@"{}" gcov %*'.format(llvm_cov_exe))
                else:
                    llvm_cov_shim_path = os.path.join(log_dir, 'llvm-cov.sh')
                    with open(llvm_cov_shim_path, 'w') as llvm_cov_sh:
                        llvm_cov_sh.write('#!/usr/bin/env sh\nexec "{}" gcov $@'.format(llvm_cov_exe))
                    os.chmod(llvm_cov_shim_path, os.stat(llvm_cov_shim_path).st_mode | stat.S_IEXEC)
                gcov_tool_args = ['--gcov-tool', llvm_cov_shim_path]
            else:
                gcov_tool_args = []
            subprocess.check_call([lcov_exe,
                                   '--directory', build_root,
                                   '--capture',
                                   '--initial',
                                   '--output-file',
                                   initial_tracefile] +
                                  gcov_tool_args)
            subprocess.check_call([lcov_exe,
                                   '--directory', build_root,
                                   '--capture',
                                   '--output-file', run_tracefile,
                                   '--no-checksum',
                                   '--rc', 'lcov_branch_coverage=1'] +
                                  gcov_tool_args)
            # Join initial and test results.
            subprocess.check_call([lcov_exe,
                                   '-a', initial_tracefile,
                                   '-a', run_tracefile,
                                   '--rc', 'lcov_branch_coverage=1',
                                   '-o', raw_tracefile])
            # Remove all directories outside the source_root from the covinfo
            subprocess.check_call([lcov_exe,
                                   '--extract', raw_tracefile,
                                   os.path.join(source_root, '*'),
                                   '--rc', 'lcov_branch_coverage=1',
                                   '--output-file', covinfo])
            # Remove all directories inside subproject dir
            subprocess.check_call([lcov_exe,
                                   '--remove', covinfo,
                                   os.path.join(subproject_root, '*'),
                                   '--rc', 'lcov_branch_coverage=1',
                                   '--output-file', covinfo])
            subprocess.check_call([genhtml_exe,
                                   '--prefix', build_root,
                                   '--prefix', source_root,
                                   '--output-directory', htmloutdir,
                                   '--title', 'Code coverage',
                                   '--legend',
                                   '--show-details',
                                   '--branch-coverage',
                                   covinfo])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif gcovr_exe:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            if not os.path.isdir(htmloutdir):
                os.mkdir(htmloutdir)
            subprocess.check_call(gcovr_base_cmd +
                                  ['--html',
                                   '--html-details',
                                   '--print-summary',
                                   '-e', subproject_root,
                                   '-o', os.path.join(htmloutdir, 'index.html'),
                                   ])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif outputs:
            print('lcov/genhtml or gcovr >= 3.3 needed to generate Html coverage report')
            exitcode = 1

    if not outputs and not outfiles:
        print('Need gcovr or lcov/genhtml to generate any coverage reports')
        exitcode = 1

    if outfiles:
        print('')
        for (filetype, path) in outfiles:
            print(filetype + ' coverage report can be found at', path.as_uri())

    return exitcode
Exemplo n.º 5
0
def coverage(outputs, source_root, subproject_root, build_root, log_dir):
    outfiles = []
    exitcode = 0

    (gcovr_exe, gcovr_new_rootdir, lcov_exe, genhtml_exe) = environment.find_coverage_tools()

    # gcovr >= 3.1 interprets rootdir differently
    if gcovr_new_rootdir:
        gcovr_rootdir = build_root
    else:
        gcovr_rootdir = source_root

    if not outputs or 'xml' in outputs:
        if gcovr_exe:
            subprocess.check_call([gcovr_exe,
                                   '-x',
                                   '-r', gcovr_rootdir,
                                   '-e', subproject_root,
                                   '-o', os.path.join(log_dir, 'coverage.xml'),
                                   ])
            outfiles.append(('Xml', pathlib.Path(log_dir, 'coverage.xml')))
        elif outputs:
            print('gcovr needed to generate Xml coverage report')
            exitcode = 1

    if not outputs or 'text' in outputs:
        if gcovr_exe:
            subprocess.check_call([gcovr_exe,
                                   '-r', gcovr_rootdir,
                                   '-e', subproject_root,
                                   '-o', os.path.join(log_dir, 'coverage.txt'),
                                   ])
            outfiles.append(('Text', pathlib.Path(log_dir, 'coverage.txt')))
        elif outputs:
            print('gcovr needed to generate text coverage report')
            exitcode = 1

    if not outputs or 'html' in outputs:
        if lcov_exe and genhtml_exe:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            covinfo = os.path.join(log_dir, 'coverage.info')
            initial_tracefile = covinfo + '.initial'
            run_tracefile = covinfo + '.run'
            raw_tracefile = covinfo + '.raw'
            subprocess.check_call([lcov_exe,
                                   '--directory', build_root,
                                   '--capture',
                                   '--initial',
                                   '--output-file',
                                   initial_tracefile])
            subprocess.check_call([lcov_exe,
                                   '--directory', build_root,
                                   '--capture',
                                   '--output-file', run_tracefile,
                                   '--no-checksum',
                                   '--rc', 'lcov_branch_coverage=1',
                                   ])
            # Join initial and test results.
            subprocess.check_call([lcov_exe,
                                   '-a', initial_tracefile,
                                   '-a', run_tracefile,
                                   '-o', raw_tracefile])
            # Remove all directories outside the source_root from the covinfo
            subprocess.check_call([lcov_exe,
                                   '--extract', raw_tracefile,
                                   os.path.join(source_root, '*'),
                                   '--output-file', covinfo])
            # Remove all directories inside subproject dir
            subprocess.check_call([lcov_exe,
                                   '--remove', covinfo,
                                   os.path.join(subproject_root, '*'),
                                   '--output-file', covinfo])
            subprocess.check_call([genhtml_exe,
                                   '--prefix', build_root,
                                   '--output-directory', htmloutdir,
                                   '--title', 'Code coverage',
                                   '--legend',
                                   '--show-details',
                                   '--branch-coverage',
                                   covinfo])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif gcovr_exe and gcovr_new_rootdir:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            if not os.path.isdir(htmloutdir):
                os.mkdir(htmloutdir)
            subprocess.check_call([gcovr_exe,
                                   '--html',
                                   '--html-details',
                                   '-r', build_root,
                                   '-e', subproject_root,
                                   '-o', os.path.join(htmloutdir, 'index.html'),
                                   ])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif outputs:
            print('lcov/genhtml or gcovr >= 3.1 needed to generate Html coverage report')
            exitcode = 1

    if not outputs and not outfiles:
        print('Need gcovr or lcov/genhtml to generate any coverage reports')
        exitcode = 1

    if outfiles:
        print('')
        for (filetype, path) in outfiles:
            print(filetype + ' coverage report can be found at', path.as_uri())

    return exitcode
Exemplo n.º 6
0
def coverage(source_root, build_root, log_dir):
    (gcovr_exe, gcovr_new_rootdir, lcov_exe,
     genhtml_exe) = environment.find_coverage_tools()
    if gcovr_exe:
        # gcovr >= 3.1 interprets rootdir differently
        if gcovr_new_rootdir:
            rootdir = build_root
        else:
            rootdir = source_root
        subprocess.check_call([
            gcovr_exe,
            '-x',
            '-r',
            rootdir,
            '-o',
            os.path.join(log_dir, 'coverage.xml'),
        ])
        subprocess.check_call([
            gcovr_exe,
            '-r',
            rootdir,
            '-o',
            os.path.join(log_dir, 'coverage.txt'),
        ])
    if lcov_exe and genhtml_exe:
        htmloutdir = os.path.join(log_dir, 'coveragereport')
        covinfo = os.path.join(log_dir, 'coverage.info')
        initial_tracefile = covinfo + '.initial'
        run_tracefile = covinfo + '.run'
        raw_tracefile = covinfo + '.raw'
        subprocess.check_call([
            lcov_exe, '--directory', build_root, '--capture', '--initial',
            '--output-file', initial_tracefile
        ])
        subprocess.check_call([
            lcov_exe,
            '--directory',
            build_root,
            '--capture',
            '--output-file',
            run_tracefile,
            '--no-checksum',
            '--rc',
            'lcov_branch_coverage=1',
        ])
        # Join initial and test results.
        subprocess.check_call([
            lcov_exe, '-a', initial_tracefile, '-a', run_tracefile, '-o',
            raw_tracefile
        ])
        # Remove all directories outside the source_root from the covinfo
        subprocess.check_call([
            lcov_exe, '--extract', raw_tracefile,
            os.path.join(source_root, '*'), '--output-file', covinfo
        ])
        subprocess.check_call([
            genhtml_exe, '--prefix', build_root, '--output-directory',
            htmloutdir, '--title', 'Code coverage', '--legend',
            '--show-details', '--branch-coverage', covinfo
        ])
    elif gcovr_exe and gcovr_new_rootdir:
        htmloutdir = os.path.join(log_dir, 'coveragereport')
        subprocess.check_call([
            gcovr_exe,
            '--html',
            '--html-details',
            '-r',
            build_root,
            '-o',
            os.path.join(htmloutdir, 'index.html'),
        ])
    if gcovr_exe:
        print('')
        print('XML coverage report can be found at',
              pathlib.Path(log_dir, 'coverage.xml').as_uri())
        print('Text coverage report can be found at',
              pathlib.Path(log_dir, 'coverage.txt').as_uri())
    if (lcov_exe and genhtml_exe) or (gcovr_exe and gcovr_new_rootdir):
        print('Html coverage report can be found at',
              pathlib.Path(htmloutdir, 'index.html').as_uri())
    return 0
Exemplo n.º 7
0
def coverage(outputs: T.List[str], source_root: str, subproject_root: str,
             build_root: str, log_dir: str, use_llvm_cov: bool) -> int:
    outfiles = []
    exitcode = 0

    (gcovr_exe, gcovr_version, lcov_exe, genhtml_exe,
     llvm_cov_exe) = environment.find_coverage_tools()

    # load config files for tools if available in the source tree
    # - lcov requires manually specifying a per-project config
    # - gcovr picks up the per-project config, and also supports filtering files
    #   so don't exclude subprojects ourselves, if the project has a config,
    #   because they either don't want that, or should set it themselves
    lcovrc = os.path.join(source_root, '.lcovrc')
    if os.path.exists(lcovrc):
        lcov_config = ['--config-file', lcovrc]
    else:
        lcov_config = []

    gcovr_config = ['-e', re.escape(subproject_root)]

    # gcovr >= 4.2 requires a different syntax for out of source builds
    if gcovr_exe and mesonlib.version_compare(gcovr_version, '>=4.2'):
        gcovr_base_cmd = [gcovr_exe, '-r', source_root, build_root]
        # it also started supporting the config file
        if os.path.exists(os.path.join(source_root, 'gcovr.cfg')):
            gcovr_config = []
    else:
        gcovr_base_cmd = [gcovr_exe, '-r', build_root]

    if use_llvm_cov:
        gcov_exe_args = ['--gcov-executable', llvm_cov_exe + ' gcov']
    else:
        gcov_exe_args = []

    if not outputs or 'xml' in outputs:
        if gcovr_exe and mesonlib.version_compare(gcovr_version, '>=3.3'):
            subprocess.check_call(
                gcovr_base_cmd + gcovr_config +
                ['-x', '-o', os.path.join(log_dir, 'coverage.xml')] +
                gcov_exe_args)
            outfiles.append(('Xml', pathlib.Path(log_dir, 'coverage.xml')))
        elif outputs:
            print('gcovr >= 3.3 needed to generate Xml coverage report')
            exitcode = 1

    if not outputs or 'sonarqube' in outputs:
        if gcovr_exe and mesonlib.version_compare(gcovr_version, '>=4.2'):
            subprocess.check_call(gcovr_base_cmd + gcovr_config + [
                '--sonarqube',
                '-o',
                os.path.join(log_dir, 'sonarqube.xml'),
            ] + gcov_exe_args)
            outfiles.append(('Sonarqube', pathlib.Path(log_dir,
                                                       'sonarqube.xml')))
        elif outputs:
            print('gcovr >= 4.2 needed to generate Xml coverage report')
            exitcode = 1

    if not outputs or 'text' in outputs:
        if gcovr_exe and mesonlib.version_compare(gcovr_version, '>=3.3'):
            subprocess.check_call(
                gcovr_base_cmd + gcovr_config +
                ['-o', os.path.join(log_dir, 'coverage.txt')] + gcov_exe_args)
            outfiles.append(('Text', pathlib.Path(log_dir, 'coverage.txt')))
        elif outputs:
            print('gcovr >= 3.3 needed to generate text coverage report')
            exitcode = 1

    if not outputs or 'html' in outputs:
        if lcov_exe and genhtml_exe:
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            covinfo = os.path.join(log_dir, 'coverage.info')
            initial_tracefile = covinfo + '.initial'
            run_tracefile = covinfo + '.run'
            raw_tracefile = covinfo + '.raw'
            if use_llvm_cov:
                # Create a shim to allow using llvm-cov as a gcov tool.
                if mesonlib.is_windows():
                    llvm_cov_shim_path = os.path.join(log_dir, 'llvm-cov.bat')
                    with open(llvm_cov_shim_path, 'w',
                              encoding='utf-8') as llvm_cov_bat:
                        llvm_cov_bat.write(f'@"{llvm_cov_exe}" gcov %*')
                else:
                    llvm_cov_shim_path = os.path.join(log_dir, 'llvm-cov.sh')
                    with open(llvm_cov_shim_path, 'w',
                              encoding='utf-8') as llvm_cov_sh:
                        llvm_cov_sh.write(
                            f'#!/usr/bin/env sh\nexec "{llvm_cov_exe}" gcov $@'
                        )
                    os.chmod(
                        llvm_cov_shim_path,
                        os.stat(llvm_cov_shim_path).st_mode | stat.S_IEXEC)
                gcov_tool_args = ['--gcov-tool', llvm_cov_shim_path]
            else:
                gcov_tool_args = []
            subprocess.check_call([
                lcov_exe, '--directory', build_root, '--capture', '--initial',
                '--output-file', initial_tracefile
            ] + lcov_config + gcov_tool_args)
            subprocess.check_call([
                lcov_exe, '--directory', build_root, '--capture',
                '--output-file', run_tracefile, '--no-checksum', '--rc',
                'lcov_branch_coverage=1'
            ] + lcov_config + gcov_tool_args)
            # Join initial and test results.
            subprocess.check_call([
                lcov_exe, '-a', initial_tracefile, '-a', run_tracefile, '--rc',
                'lcov_branch_coverage=1', '-o', raw_tracefile
            ] + lcov_config)
            # Remove all directories outside the source_root from the covinfo
            subprocess.check_call([
                lcov_exe, '--extract', raw_tracefile,
                os.path.join(source_root, '*'), '--rc',
                'lcov_branch_coverage=1', '--output-file', covinfo
            ] + lcov_config)
            # Remove all directories inside subproject dir
            subprocess.check_call([
                lcov_exe, '--remove', covinfo,
                os.path.join(subproject_root, '*'), '--rc',
                'lcov_branch_coverage=1', '--output-file', covinfo
            ] + lcov_config)
            subprocess.check_call([
                genhtml_exe, '--prefix', build_root, '--prefix', source_root,
                '--output-directory', htmloutdir, '--title', 'Code coverage',
                '--legend', '--show-details', '--branch-coverage', covinfo
            ])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif gcovr_exe and mesonlib.version_compare(gcovr_version, '>=3.3'):
            htmloutdir = os.path.join(log_dir, 'coveragereport')
            if not os.path.isdir(htmloutdir):
                os.mkdir(htmloutdir)
            subprocess.check_call(gcovr_base_cmd + gcovr_config + [
                '--html',
                '--html-details',
                '--print-summary',
                '-o',
                os.path.join(htmloutdir, 'index.html'),
            ])
            outfiles.append(('Html', pathlib.Path(htmloutdir, 'index.html')))
        elif outputs:
            print(
                'lcov/genhtml or gcovr >= 3.3 needed to generate Html coverage report'
            )
            exitcode = 1

    if not outputs and not outfiles:
        print('Need gcovr or lcov/genhtml to generate any coverage reports')
        exitcode = 1

    if outfiles:
        print('')
        for (filetype, path) in outfiles:
            print(filetype + ' coverage report can be found at', path.as_uri())

    return exitcode