From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0D814158020 for ; Sun, 16 Oct 2022 17:08:28 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 967E8E0D17; Sun, 16 Oct 2022 17:08:24 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3AFA2E0D10 for ; Sun, 16 Oct 2022 17:08:24 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH 1/2] llvm.eclass: Fix CC/CXX version to prevent the eclass overriding it Date: Sun, 16 Oct 2022 19:08:15 +0200 Message-Id: <20221016170816.1421946-1-mgorny@gentoo.org> X-Mailer: git-send-email 2.38.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 91c749be-b9e9-458a-84b8-44077bb0e85b X-Archives-Hash: 9289cea9bc1ba5cf7641f743e9016629 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 --- 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: ... +# @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} ) -- 2.38.0