|
|
@@ -18,25 +18,34 @@ def _run(repository_ctx, cmd):
|
|
|
return exec_result
|
|
|
|
|
|
def _clang_version(version_output):
|
|
|
- """Returns clang's major version number, or None if not found."""
|
|
|
+ """Returns version information, or a (None, "unknown") tuple if not found.
|
|
|
+
|
|
|
+ Returns both the major version number (14) and the full version number for
|
|
|
+ caching.
|
|
|
+ """
|
|
|
+ clang_version = None
|
|
|
+ clang_version_for_cache = "unknown"
|
|
|
+
|
|
|
version_prefix = "clang version "
|
|
|
version_start = version_output.find(version_prefix)
|
|
|
if version_start == -1:
|
|
|
# No version
|
|
|
- return None
|
|
|
+ return (clang_version, clang_version_for_cache)
|
|
|
version_start += len(version_prefix)
|
|
|
|
|
|
- # Find a dot to indicate something like 'clang version 14.0.6'.
|
|
|
- version_dot = version_output.find(".", version_start)
|
|
|
- if version_dot == -1:
|
|
|
- return None
|
|
|
+ # Find the newline.
|
|
|
+ version_newline = version_output.find("\n", version_start)
|
|
|
+ if version_newline == -1:
|
|
|
+ return (clang_version, clang_version_for_cache)
|
|
|
+ clang_version_for_cache = version_output[version_start:version_newline]
|
|
|
|
|
|
- # Make sure the dot was on the same line as the version.
|
|
|
- if version_output.find("\n", version_start) < version_dot:
|
|
|
- return None
|
|
|
+ # Find a dot to indicate something like 'clang version 14.0.6', and grab the
|
|
|
+ # major version.
|
|
|
+ version_dot = version_output.find(".", version_start)
|
|
|
+ if version_dot != -1 and version_dot < version_newline:
|
|
|
+ clang_version = int(version_output[version_start:version_dot])
|
|
|
|
|
|
- # Return the version as int.
|
|
|
- return int(version_output[version_start:version_dot])
|
|
|
+ return (clang_version, clang_version_for_cache)
|
|
|
|
|
|
def _detect_system_clang(repository_ctx):
|
|
|
"""Detects whether the system-provided clang can be used.
|
|
|
@@ -59,7 +68,8 @@ def _detect_system_clang(repository_ctx):
|
|
|
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, _clang_version(version_output))
|
|
|
+ clang_version, clang_version_for_cache = _clang_version(version_output)
|
|
|
+ return (cc_path, clang_version, clang_version_for_cache)
|
|
|
|
|
|
def _compute_clang_resource_dir(repository_ctx, clang):
|
|
|
"""Runs the `clang` binary to get its resource dir."""
|
|
|
@@ -152,7 +162,9 @@ def _configure_clang_toolchain_impl(repository_ctx):
|
|
|
# here as the other LLVM tools may not be symlinked into the PATH even if
|
|
|
# `clang` is. We also insist on finding the basename of `clang++` as that is
|
|
|
# important for C vs. C++ compiles.
|
|
|
- (clang, clang_version) = _detect_system_clang(repository_ctx)
|
|
|
+ (clang, clang_version, clang_version_for_cache) = _detect_system_clang(
|
|
|
+ repository_ctx,
|
|
|
+ )
|
|
|
clang = clang.realpath.dirname.get_child("clang++")
|
|
|
|
|
|
# Compute the various directories used by Clang.
|
|
|
@@ -190,6 +202,7 @@ def _configure_clang_toolchain_impl(repository_ctx):
|
|
|
"{LLVM_BINDIR}": str(arpath.dirname),
|
|
|
"{CLANG_BINDIR}": str(clang.dirname),
|
|
|
"{CLANG_VERSION}": str(clang_version),
|
|
|
+ "{CLANG_VERSION_FOR_CACHE}": clang_version_for_cache.replace('"', "_").replace("\\", "_"),
|
|
|
"{CLANG_RESOURCE_DIR}": resource_dir,
|
|
|
"{CLANG_INCLUDE_DIRS_LIST}": str(
|
|
|
[str(path) for path in include_dirs],
|