Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/2] llvm.eclass: Fix CC/CXX version to prevent the eclass overriding it
Date: Sun, 16 Oct 2022 17:08:28
Message-Id: 20221016170816.1421946-1-mgorny@gentoo.org
1 Fix the clang executable in CC, CPP and CXX variables to include
2 the version number, in order to prevent the PATH manipulations done
3 by llvm.eclass from overriding the compiler. Otherwise, a package
4 requiring older LLVM libraries could cause an older compiler version
5 being used, effectively resulting in a system built by mixed set
6 of clang versions.
7
8 Signed-off-by: Michał Górny <mgorny@g.o>
9 ---
10 eclass/llvm.eclass | 36 ++++++++++++++++++++++++++++++++++++
11 1 file changed, 36 insertions(+)
12
13 diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
14 index 1effcc555905..39299d06dbe9 100644
15 --- a/eclass/llvm.eclass
16 +++ b/eclass/llvm.eclass
17 @@ -180,6 +180,40 @@ get_llvm_prefix() {
18 die "No LLVM slot${1:+ <= ${1}} satisfying the package's dependencies found installed!"
19 }
20
21 +# @FUNCTION: llvm_fix_clang_version
22 +# @USAGE: <variable-name>...
23 +# @DESCRIPTION:
24 +# Fix the clang compiler name in specified variables to include
25 +# the major version, to prevent PATH alterations from forcing an older
26 +# clang version being used.
27 +llvm_fix_clang_version() {
28 + debug-print-function ${FUNCNAME} "${@}"
29 +
30 + local shopt_save=$(shopt -p -o noglob)
31 + set -f
32 + local var
33 + for var; do
34 + local split=( ${!var} )
35 + case ${split[0]} in
36 + *clang|*clang++|*clang-cpp)
37 + local version=()
38 + read -r -a version < <("${split[0]}" --version)
39 + local major=${version[-1]%%.*}
40 + if [[ -n ${major//[0-9]} ]]; then
41 + die "${var}=${!var} produced invalid --version: ${version[*]}"
42 + fi
43 +
44 + split[0]+=-${major}
45 + if ! type -P "${split[0]}" &>/dev/null; then
46 + die "${split[0]} does not seem to exist"
47 + fi
48 + declare -g "${var}=${split[*]}"
49 + ;;
50 + esac
51 + done
52 + ${shopt_save}
53 +}
54 +
55 # @FUNCTION: llvm_pkg_setup
56 # @DESCRIPTION:
57 # Prepend the appropriate executable directory for the newest
58 @@ -198,6 +232,8 @@ llvm_pkg_setup() {
59 debug-print-function ${FUNCNAME} "${@}"
60
61 if [[ ${MERGE_TYPE} != binary ]]; then
62 + llvm_fix_clang_version CC CPP CXX
63 +
64 local llvm_path=$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin
65 local IFS=:
66 local split_path=( ${PATH} )
67 --
68 2.38.0

Replies