Skip to content

Commit 18f4c4b

Browse files
author
Martin Kosiba
committed
Make it possible to use llvm-cov with bazel coverage
1 parent 4e82614 commit 18f4c4b

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

crosstool/osx_cc_configure.bzl

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ def _generate_system_modulemap(repository_ctx, script, output):
8888
def _copy_file(repository_ctx, src, dest):
8989
repository_ctx.file(dest, content = repository_ctx.read(src))
9090

91+
def _get_tool_path(repository_ctx, tool_name, path_env_var):
92+
tool_path = repository_ctx.os.environ.get(path_env_var)
93+
if tool_path != None:
94+
if not tool_path.startswith("/"):
95+
tool_path = repository_ctx.which(tool_path)
96+
return tool_path
97+
else:
98+
env = repository_ctx.os.environ
99+
result = repository_ctx.execute([
100+
"env",
101+
"-i",
102+
"DEVELOPER_DIR={}".format(env.get("DEVELOPER_DIR", default = "")),
103+
"xcrun",
104+
"--find",
105+
tool_name,
106+
])
107+
if result.return_code != 0:
108+
return None
109+
return result.stdout.strip()
110+
91111
def configure_osx_toolchain(repository_ctx):
92112
"""Configure C++ toolchain on macOS.
93113
@@ -153,11 +173,9 @@ def configure_osx_toolchain(repository_ctx):
153173
)
154174

155175
tool_paths = {}
156-
gcov_path = repository_ctx.os.environ.get("GCOV")
157-
if gcov_path != None:
158-
if not gcov_path.startswith("/"):
159-
gcov_path = repository_ctx.which(gcov_path)
160-
tool_paths["gcov"] = gcov_path
176+
tool_paths["gcov"] = _get_tool_path(repository_ctx, "llvm-profdata", "GCOV")
177+
tool_paths["llvm-cov"] = _get_tool_path(repository_ctx, "llvm-cov", "BAZEL_LLVM_COV")
178+
tool_paths["llvm-profdata"] = _get_tool_path(repository_ctx, "llvm-profdata", "BAZEL_LLVM_PROFDATA")
161179

162180
features = []
163181
if _succeeds(repository_ctx, "ld", "-no_warn_duplicate_libraries", "-v"):

crosstool/setup.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ _apple_cc_autoconf = repository_rule(
5656
_OLD_DISABLE_ENV_VAR,
5757
"APPLE_SUPPORT_LAYERING_CHECK_BETA",
5858
"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.
59+
"BAZEL_LLVM_COV", # Makes it possible to override the llvm-cov path.
60+
"BAZEL_LLVM_PROFDATA", # Makes it possible to override the llvm-profdata path.
5961
"DEVELOPER_DIR", # Used for making sure we use the right Xcode for compiling toolchain binaries
6062
"GCOV", # TODO: Remove this
6163
"USE_CLANG_CL", # Kept as a hack for those who rely on this invaliding the toolchain

0 commit comments

Comments
 (0)