Skip to content

Make it possible to use llvm-cov with bazel coverage #377

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mkosiba
Copy link
Contributor

@mkosiba mkosiba commented Mar 20, 2025

The fact that llvm-cov and llvm-profdata are not set seems to trip up the external/bazel_tools/tools/test/collect_cc_coverage.sh script resulting in empty .dat files.

To solve the issue we implement something similar to what's done in rules_cc.

After these changes bazel coverage <test target> no longer produces empty .dat files.

Copy link

google-cla bot commented Mar 20, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

])
if result.return_code != 0:
return None
return result.stdout.strip()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does these being host specific absolute paths affect caching? since this will have the absolute path to Xcode.app in it

Copy link
Contributor Author

@mkosiba mkosiba Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, you're right that the coverage actions will probably be cached incorrectly. This was already the case if the GCOV env var was set, so I didn't notice. What's a good way forward here?

Looks like I can put the _get_tool_path logic into a bash script and then:

tool_paths["llvm-cov"] = "llvm-cov.sh"

That should result in a relative path being baked into the action instead of an absolute path. Do you think that'd work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea i think that would work.

I think the reason the gcov one has flown under the radar is because in apple specific (aka non-c++) tests the coverage logic is handled in rules_apple and sidesteps all of this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries. I think the updated version addresses this issue. If no overrides are present then the cache key contains a script which just says xcrun --run gcov/llvm-profdata/llvm-cov. Since the script is the same across machines caching should work fine.
If there are override env vars present, then as long as users set the override to the same value, they should also get cache hits.

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 this pull request may close these issues.

2 participants