Fix for CC being sometimes a path and sometimes a file on PATH (#1724)

Possible fix for #1713

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
jkamins7
2022-07-30 13:48:38 -07:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent 13d6c33830
commit c13803de99
+12 -11
View File
@@ -26,18 +26,19 @@ def _detect_system_clang(repository_ctx):
# If the user provides an explicit `CC` environment variable, use that as
# the compiler. This should point at the `clang` executable to use.
cc = repository_ctx.os.environ.get("CC")
cc_path = None
if cc:
version_output = _run(repository_ctx, [cc, "--version"]).stdout
if not "clang" in version_output:
fail("The `CC` environment variable is not a Clang compiler.")
return repository_ctx.path(cc)
# Try looking on the path. We only check for the normal name.
system_clang = repository_ctx.which("clang")
if not system_clang:
fail("Unable to find a `clang` executable on the system path.")
return system_clang
cc_path = repository_ctx.path(cc)
if not cc_path.exists:
cc_path = repository_ctx.which(cc)
if not cc_path:
cc_path = repository_ctx.which("clang")
if not cc_path:
fail("Cannot find clang or CC (%s); either correct your path or set the CC environment variable" % cc)
version_output = _run(repository_ctx, [cc_path, "--version"]).stdout
if "clang" not in version_output:
fail("Searching for clang or CC (%s), and found (%s), which is not a Clang compiler" % (cc, cc_path))
return cc_path
def _compute_clang_resource_dir(repository_ctx, clang):
"""Runs the `clang` binary to get its resource dir."""