summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2022-10-16 14:18:11 +0200
committerMichał Górny <mgorny@gentoo.org>2022-10-19 13:53:20 +0200
commit3fc1dcf9419e7692c152ccf948357b50c266c4eb (patch)
tree08edaa5dc9b15b9d1b1b5f2171055c9cb734e8a2 /eclass/llvm.eclass
parentkernel-build.eclass: Respect KV_FULL (diff)
downloadgentoo-3fc1dcf9419e7692c152ccf948357b50c266c4eb.tar.gz
gentoo-3fc1dcf9419e7692c152ccf948357b50c266c4eb.tar.bz2
gentoo-3fc1dcf9419e7692c152ccf948357b50c266c4eb.zip
llvm.eclass: Fix CC/CXX version to prevent the eclass overriding it
Fix the clang executable in CC, CPP and CXX variables to include the version number, in order to prevent the PATH manipulations done by llvm.eclass from overriding the compiler. Otherwise, a package requiring older LLVM libraries could cause an older compiler version being used, effectively resulting in a system built by mixed set of clang versions. Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/llvm.eclass')
-rw-r--r--eclass/llvm.eclass36
1 files changed, 36 insertions, 0 deletions
diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
index 1effcc555905..39299d06dbe9 100644
--- a/eclass/llvm.eclass
+++ b/eclass/llvm.eclass
@@ -180,6 +180,40 @@ get_llvm_prefix() {
die "No LLVM slot${1:+ <= ${1}} satisfying the package's dependencies found installed!"
}
+# @FUNCTION: llvm_fix_clang_version
+# @USAGE: <variable-name>...
+# @DESCRIPTION:
+# Fix the clang compiler name in specified variables to include
+# the major version, to prevent PATH alterations from forcing an older
+# clang version being used.
+llvm_fix_clang_version() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local shopt_save=$(shopt -p -o noglob)
+ set -f
+ local var
+ for var; do
+ local split=( ${!var} )
+ case ${split[0]} in
+ *clang|*clang++|*clang-cpp)
+ local version=()
+ read -r -a version < <("${split[0]}" --version)
+ local major=${version[-1]%%.*}
+ if [[ -n ${major//[0-9]} ]]; then
+ die "${var}=${!var} produced invalid --version: ${version[*]}"
+ fi
+
+ split[0]+=-${major}
+ if ! type -P "${split[0]}" &>/dev/null; then
+ die "${split[0]} does not seem to exist"
+ fi
+ declare -g "${var}=${split[*]}"
+ ;;
+ esac
+ done
+ ${shopt_save}
+}
+
# @FUNCTION: llvm_pkg_setup
# @DESCRIPTION:
# Prepend the appropriate executable directory for the newest
@@ -198,6 +232,8 @@ llvm_pkg_setup() {
debug-print-function ${FUNCNAME} "${@}"
if [[ ${MERGE_TYPE} != binary ]]; then
+ llvm_fix_clang_version CC CPP CXX
+
local llvm_path=$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin
local IFS=:
local split_path=( ${PATH} )