meson icon indicating copy to clipboard operation
meson copied to clipboard

fixes coverage with gcovr under Windows

Open msuesskraut opened this issue 4 years ago • 9 comments

This PR fixes coverage under Windows with gcovr.

The Problem

meson calls gcovr with filters (option -e) for the subprojects directory. On Windows it uses "Windows-slashes". However, gcovr requires "Posix-slashes" for option -e - see error message:

> ninja coverage
[1/1] Generates coverage reports
FAILED: meson-coverage
"C:\Python39\Scripts\meson" "--internal" "coverage" "C:\Users\Martin\Playground\tracer" "C:\Users\Martin\Playground\tracer\subprojects" "C:\Users\Martin\Playground\tracer\build_old" "C:\Users\Martin\Playground\tracer\build_old\meson-logs"
LLVM (http://llvm.org/):
  LLVM version 12.0.0
  Optimized build.
  Default target: x86_64-pc-windows-msvc
  Host CPU: skylake
(WARNING) filters must use forward slashes as path separators
(WARNING) your filter : C:\Users\Martin\Playground\tracer\subprojects
(WARNING) did you mean: C:\Users/Martin/Playground\tracer\subprojects
Traceback (most recent call last):
  File "c:\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Python39\Scripts\gcovr.exe\__main__.py", line 7, in <module>
  File "c:\python39\lib\site-packages\gcovr\__main__.py", line 237, in main
    options.exclude = [f.build_filter(logger) for f in options.exclude]
  File "c:\python39\lib\site-packages\gcovr\__main__.py", line 237, in <listcomp>
    options.exclude = [f.build_filter(logger) for f in options.exclude]
  File "c:\python39\lib\site-packages\gcovr\utils.py", line 174, in build_filter
    return AbsoluteFilter(self.regex)
  File "c:\python39\lib\site-packages\gcovr\utils.py", line 196, in __init__
    self.pattern = re.compile(pattern, flags)
  File "c:\python39\lib\re.py", line 252, in compile
    return _compile(pattern, flags)
  File "c:\python39\lib\re.py", line 304, in _compile
    p = sre_compile.compile(pattern, flags)
  File "c:\python39\lib\sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "c:\python39\lib\sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "c:\python39\lib\sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "c:\python39\lib\sre_parse.py", line 525, in _parse
    code = _escape(source, this, state)
  File "c:\python39\lib\sre_parse.py", line 381, in _escape
    raise source.error("incomplete escape %s" % escape, len(escape))
re.error: incomplete escape \U at position 2
Traceback (most recent call last):
  File "c:\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Python39\Scripts\meson.exe\__main__.py", line 7, in <module>
  File "c:\python39\lib\site-packages\mesonbuild\mesonmain.py", line 231, in main
    return run(sys.argv[1:], launcher)
  File "c:\python39\lib\site-packages\mesonbuild\mesonmain.py", line 220, in run
    return run_script_command(args[1], args[2:])
  File "c:\python39\lib\site-packages\mesonbuild\mesonmain.py", line 168, in run_script_command
    return module.run(script_args)
  File "c:\python39\lib\site-packages\mesonbuild\scripts\coverage.py", line 168, in run
    return coverage(options.outputs, options.source_root,
  File "c:\python39\lib\site-packages\mesonbuild\scripts\coverage.py", line 39, in coverage
    subprocess.check_call(gcovr_base_cmd +
  File "c:\python39\lib\subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['gcovr', '-r', 'C:\\Users\\Martin\\Playground\\tracer', 'C:\\Users\\Martin\\Playground\\tracer\\build_old', '-x', '-e', 'C:\\Users\\Martin\\Playground\\tracer\\subprojects', '-o', 
'C:\\Users\\Martin\\Playground\\tracer\\build_old\\meson-logs\\coverage.xml']' returned non-zero exit status 1.
ninja: build stopped: subcommand failed.

Fix

The fix converts the subproject_root always into a string with "Posix-slashes". This is essentially a no-op on Posix and does the right thing in Windows.

Tested

Manually tested on

  • Windows 10 with clang 12.0.0 and gcovr 5.0.0 and Python 3.9
  • Ubuntu 20.04 with gcc 9.3.0 and lcov 1.14 and Python 3.8
  • Ubuntu 20.04 with gcc 9.3.0 and gcovr 5.0 and Python 3.8

msuesskraut avatar Jun 19 '21 17:06 msuesskraut

This should really also come with a test to ensure that it doesn't break again.

Adding gcovr to the pip install command should at least get the Windows CI going.

mensinda avatar Jun 20 '21 09:06 mensinda

I added gcovr to run.ps1.

Is there already a test that runs ninja coverage or do you have any specific tips on how to write one?

msuesskraut avatar Jun 20 '21 17:06 msuesskraut

There are already tests in run_unittests.py, but (search for coverage in the Azure CI output) they are still being skipped...

mensinda avatar Jun 24 '21 14:06 mensinda

:crossed_swords: conflicts.

jpakkane avatar Jun 27 '21 21:06 jpakkane

I did a rebase to resolve the conflicts. I'll have a look at the Azure CI output after the checks finish.

msuesskraut avatar Jun 29 '21 16:06 msuesskraut

Codecov Report

Attention: Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 65.78%. Comparing base (82e92e9) to head (2371f13). Report is 3613 commits behind head on master.

Files Patch % Lines
mesonbuild/scripts/coverage.py 50.00% 0 Missing and 1 partial :warning:
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8906   +/-   ##
=======================================
  Coverage   65.78%   65.78%           
=======================================
  Files         374      374           
  Lines       84115    84119    +4     
  Branches    17470    17472    +2     
=======================================
+ Hits        55338    55341    +3     
+ Misses      23994    23993    -1     
- Partials     4783     4785    +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jul 23 '21 19:07 codecov[bot]

The build failures do not make sense. Maybe rebasing to current trunk would fix them?

jpakkane avatar Jul 23 '21 20:07 jpakkane

I did another rebase.

I'm looking forward to the vs2017 clangclx64ninja build. Last time it failed, without a clear indication whether this has something to do with the PR.

msuesskraut avatar Jul 28 '21 17:07 msuesskraut

Okay, it seams to me, that meson does not create the coverage-* ninja targets for vs2017 clangclx64ninja. I'll look into it. I tested the clang build locally not with clang-cl from vs2017, but with "pure" clang from https://releases.llvm.org/download.html

msuesskraut avatar Jul 28 '21 18:07 msuesskraut