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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crosstool/BUILD.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,23 @@ filegroup(
],
)

filegroup(
name = "tools_coverage",
srcs = [
":gcov.sh",
":llvm-profdata.sh",
":llvm-cov.sh",
],
)

[
cc_toolchain(
name = "cc-compiler-" + arch,
all_files = ":tools",
ar_files = ":tools",
as_files = ":tools",
compiler_files = ":tools",
coverage_files = ":tools_coverage",
dwp_files = ":empty",
linker_files = ":tools",
objcopy_files = ":empty",
Expand Down
3 changes: 3 additions & 0 deletions crosstool/cov_tool_wrapper.sh.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

%{command} "$@"
28 changes: 23 additions & 5 deletions crosstool/osx_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ def _generate_system_modulemap(repository_ctx, script, output):
def _copy_file(repository_ctx, src, dest):
repository_ctx.file(dest, content = repository_ctx.read(src))

def _get_tool_wrapper(repository_ctx, wrapper_script_name, tool_name, path_env_var):
cov_tool_wrapper_template = Label("@build_bazel_apple_support//crosstool:cov_tool_wrapper.sh.tpl")

command = "xcrun --run " + tool_name

override_path = repository_ctx.os.environ.get(path_env_var)
if override_path:
if not override_path.startswith("/"):
override_path = repository_ctx.which(override_path)
command = '"{}"'.format(override_path)

repository_ctx.template(
wrapper_script_name,
cov_tool_wrapper_template,
{
"%{command}": command,
},
)
return wrapper_script_name

def configure_osx_toolchain(repository_ctx):
"""Configure C++ toolchain on macOS.

Expand Down Expand Up @@ -153,11 +173,9 @@ def configure_osx_toolchain(repository_ctx):
)

tool_paths = {}
gcov_path = repository_ctx.os.environ.get("GCOV")
if gcov_path != None:
if not gcov_path.startswith("/"):
gcov_path = repository_ctx.which(gcov_path)
tool_paths["gcov"] = gcov_path
tool_paths["gcov"] = _get_tool_wrapper(repository_ctx, "gcov.sh", "llvm-profdata", "GCOV")
tool_paths["llvm-cov"] = _get_tool_wrapper(repository_ctx, "llvm-cov.sh", "llvm-cov", "BAZEL_LLVM_COV")
tool_paths["llvm-profdata"] = _get_tool_wrapper(repository_ctx, "llvm-profdata.sh", "llvm-profdata", "BAZEL_LLVM_PROFDATA")

features = []
if _succeeds(repository_ctx, "ld", "-no_warn_duplicate_libraries", "-v"):
Expand Down
2 changes: 2 additions & 0 deletions crosstool/setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ _apple_cc_autoconf = repository_rule(
_OLD_DISABLE_ENV_VAR,
"APPLE_SUPPORT_LAYERING_CHECK_BETA",
"BAZEL_ALLOW_NON_APPLICATIONS_XCODE", # Signals to configure_osx_toolchain that some Xcodes may live outside of /Applications and we need to probe further when detecting/configuring them.
"BAZEL_LLVM_COV", # Makes it possible to override the llvm-cov path.
"BAZEL_LLVM_PROFDATA", # Makes it possible to override the llvm-profdata path.
"DEVELOPER_DIR", # Used for making sure we use the right Xcode for compiling toolchain binaries
"GCOV", # TODO: Remove this
"USE_CLANG_CL", # Kept as a hack for those who rely on this invaliding the toolchain
Expand Down