Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of source builds produce coverage for generated files #33

Closed
PhilipMourdjis opened this issue Sep 23, 2019 · 9 comments · Fixed by #34
Closed

Out of source builds produce coverage for generated files #33

PhilipMourdjis opened this issue Sep 23, 2019 · 9 comments · Fixed by #34

Comments

@PhilipMourdjis
Copy link

When running fastcov in project/src/build no coverage info is produced for generated source files that are created in this build directory. This is expected.

When running fastcov from a build directory that is a sibling of a source directory (project/build). Generated source files are included in the coverage report and I do not know how to exclude them from the report (adding ../build/ to the exclude folders list has no effect).

@RPGillespie6
Copy link
Owner

RPGillespie6 commented Sep 23, 2019

Are the generated source files in project/src/build? If so, you'll want to add --exclude ../src/build, not ../build/

@PhilipMourdjis
Copy link
Author

When cmake+ctest+fastcov are invoked from project/src/build the generated files are in project/src/build and they do not end up in the report.

When cmake+ctest+fastcov are invoked from project/build the generated files are in project/build and they are included in the report.

I would like to be able to build in project/build without the generated files showing up.

@RPGillespie6
Copy link
Owner

RPGillespie6 commented Sep 23, 2019

In that case you should be able to do --exclude build/ and it will exclude any source file inside of project/build/ (as well as any other directory with the substring build/ in it). Or, if your generated file names have some kind of pattern like gen_x.cpp, gen_y.cpp, etc. you could do --exclude gen_ or you could make it so the generated files go into their own directory like project/build/generated and then just --exclude generated/.

Alternatively, you can whitelist the source files you want with --include ../src or explicitly with --source-files ${SOURCE_FILES}

If that doesn't help I'll need to know a few more details on the directory layout of your project.

@PhilipMourdjis
Copy link
Author

--exclude build/ doesn't work for me, this feels like a bug as these are automatically ignored in the case where the build directory is a subfolder of the src directory. I'll fork the example script here to see if I can show a minimal example of this but don't have time to do it this evening.

@RPGillespie6
Copy link
Owner

Fastcov will never automatically ignore source files that are linked to test binaries, so if it is not including them, either one of the CLI flags is filtering them, or there is a different reason behind it. A minimum example would be great, I would be able to tell exactly what is happening.

@PhilipMourdjis
Copy link
Author

I have modified the example project in a fork of this repo: https://github.com/PhilipMourdjis/fastcov/tree/Ignore_build_directory

cd example
./build.sh

The ignore_me.cpp file generated by cmake is included in the example.json output even after attempts to exclude the build directory

@RPGillespie6
Copy link
Owner

RPGillespie6 commented Sep 26, 2019

I see what the problem is. This is actually related to #17 . It is a quirk with CMake/Ninja where it appears that files in the build directory use relative paths while paths outside of the build directory (sometimes?) use absolute paths. Switching the build system to use Make instead of Ninja "fixes" the issue.

However, I still consider this a bug in fastcov, so I will fix it so that fastcov converts all paths to absolute before filtering.

RPGillespie6 added a commit that referenced this issue Sep 26, 2019
RPGillespie6 added a commit that referenced this issue Sep 26, 2019
RPGillespie6 added a commit that referenced this issue Sep 26, 2019
@RPGillespie6
Copy link
Owner

Could you please try the latest on master and see if it fixes your issues? I won't release/push to pypi until then.

@PhilipMourdjis
Copy link
Author

Works great! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants