diff --git a/sdk_container/src/third_party/portage-stable/eclass/llvm.eclass b/sdk_container/src/third_party/portage-stable/eclass/llvm.eclass index d61effb5e9..9a6f0c8b6b 100644 --- a/sdk_container/src/third_party/portage-stable/eclass/llvm.eclass +++ b/sdk_container/src/third_party/portage-stable/eclass/llvm.eclass @@ -1,4 +1,4 @@ -# Copyright 1999-2019 Gentoo Authors +# Copyright 1999-2022 Gentoo Authors # Distributed under the terms of the GNU General Public License v2 # @ECLASS: llvm.eclass @@ -6,7 +6,7 @@ # Michał Górny # @AUTHOR: # Michał Górny -# @SUPPORTED_EAPIS: 6 7 +# @SUPPORTED_EAPIS: 6 7 8 # @BLURB: Utility functions to build against slotted LLVM # @DESCRIPTION: # The llvm.eclass provides utility functions that can be used to build @@ -17,21 +17,21 @@ # a proper dependency string yourself to guarantee that appropriate # version of LLVM is installed. # -# Example use for a package supporting LLVM 5 to 7: +# Example use for a package supporting LLVM 9 to 11: # @CODE -# inherit cmake-utils llvm +# inherit cmake llvm # # RDEPEND=" -# ] @@ -173,14 +177,7 @@ get_llvm_prefix() { die "${FUNCNAME}: invalid max_slot=${max_slot}" fi - # fallback to :0 - # assume it's always <= 4 (the lower max_slot allowed) - if has_version ${hv_switch} "sys-devel/llvm:0"; then - echo "${prefix}/usr" - return - fi - - die "No LLVM slot${1:+ <= ${1}} found installed!" + die "No LLVM slot${1:+ <= ${1}} satisfying the package's dependencies found installed!" } # @FUNCTION: llvm_pkg_setup @@ -201,13 +198,29 @@ llvm_pkg_setup() { debug-print-function ${FUNCNAME} "${@}" if [[ ${MERGE_TYPE} != binary ]]; then - local llvm_prefix=$(get_llvm_prefix "${LLVM_MAX_SLOT}") + local llvm_path=$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin + local IFS=: + local split_path=( ${PATH} ) + local new_path=() + local x added= - # do not prepend /usr/bin, it's not necessary and breaks other - # prepends, https://bugs.gentoo.org/622866 - if [[ ${llvm_prefix} != ${EPREFIX}/usr ]]; then - export PATH=${llvm_prefix}/bin:${PATH} - fi + # prepend new path before first LLVM version found + for x in "${split_path[@]}"; do + if [[ ${x} == */usr/lib/llvm/*/bin ]]; then + if [[ ${x} != ${llvm_path} ]]; then + new_path+=( "${llvm_path}" ) + elif [[ ${added} && ${x} == ${llvm_path} ]]; then + # deduplicate + continue + fi + added=1 + fi + new_path+=( "${x}" ) + done + # ...or to the end of PATH + [[ ${added} ]] || new_path+=( "${llvm_path}" ) + + export PATH=${new_path[*]} fi }