• [gentoo-dev] [PATCH 1/2] llvm.eclass: Fix CC/CXX version to prevent the

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Sun Oct 16 19:10:01 2022
    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>
    ---
    eclass/llvm.eclass | 36 ++++++++++++++++++++++++++++++++++++
    1 file changed, 36 insertions(+)

    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//
  • From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Sun Oct 16 19:10:01 2022
    Fix the LLVM tool path in variables such as AR, LD, etc. to their
    current locations prior to manipulating PATH, in order to prevent
    llvm.eclass from overriding them. Otherwise, a package requiring older
    LLVM libraries could force older tool versions, possibly incompatible
    with the object files produced by a newer clang version.

    Signed-off-by: Michał Górny <mgorny@gentoo.org>
    ---
    eclass/llvm.eclass | 27 +++++++++++++++++++++++++++
    1 file changed, 27 insertions(+)

    diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
    index 39299d06dbe9..16596ec2ea66 100644
    --- a/eclass/llvm.eclass
    +++ b/eclass/llvm.eclass
    @@ -214,6 +214,30 @@ llvm_fix_clang_version() {
    ${shopt_save}
    }

    +# @FUNCTION: llvm_fix_tool_path
    +# @USAGE: <variable-name>...
    +# @DESCRIPTION:
    +# Fix the LLVM tools referenced in the specified variables to their
    +# current location, to prevent PATH alterations from forcing older
    +# versions being used.
    +llvm_fix_tool_path() {
    + debug-print-function ${FUNCNAME} "${@}"
    +
    + local shopt_save=$(shopt -p -o noglob)
    + set -f
    + local var
    + for var; do
    + local split=( ${!var} )
    + local path=$(type -P ${split[0]} 2>/dev/null)
    + # if it resides in one of the LLVM prefixes, it's an LLVM tool! + if [[ ${path} == "${BROOT}/usr/lib/llvm"* ]]; then
    + split[0]=${path}
    + declare -g "${var}=${split[*]}"
    + fi
    + done
    + ${shopt_save}
    +}
    +
    # @FUNCTION