eclass/llvm: Sync with gentoo

It's from gentoo commit 0b179593e7beb7c600e0c43e56c7d47dbb13a67d.
This commit is contained in:
Krzesimir Nowak 2022-03-03 16:32:40 +01:00
parent 27cf309356
commit f59e682175

View File

@ -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 <mgorny@gentoo.org>
# @AUTHOR:
# Michał Górny <mgorny@gentoo.org>
# @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="
# <sys-devel/llvm-8:=
# <sys-devel/llvm-11:=
# || (
# sys-devel/llvm:7
# sys-devel/llvm:6
# sys-devel/llvm:5
# sys-devel/llvm:9
# sys-devel/llvm:10
# sys-devel/llvm:11
# )
# "
# DEPEND=${RDEPEND}
#
# LLVM_MAX_SLOT=7
# LLVM_MAX_SLOT=11
#
# # only if you need to define one explicitly
# pkg_setup() {
@ -42,12 +42,12 @@
#
# Example for a package needing LLVM+clang w/ a specific target:
# @CODE
# inherit cmake-utils llvm
# inherit cmake llvm
#
# # note: do not use := on both clang and llvm, it can match different
# # slots then. clang pulls llvm in, so we can skip the latter.
# RDEPEND="
# >=sys-devel/clang-6:=[llvm_targets_AMDGPU(+)]
# >=sys-devel/clang-9:=[llvm_targets_AMDGPU(+)]
# "
# DEPEND=${RDEPEND}
#
@ -60,7 +60,7 @@ case "${EAPI:-0}" in
0|1|2|3|4|5)
die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}"
;;
6|7)
6|7|8)
;;
*)
die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
@ -71,6 +71,10 @@ EXPORT_FUNCTIONS pkg_setup
if [[ ! ${_LLVM_ECLASS} ]]; then
# make sure that the versions installing straight into /usr/bin
# are uninstalled
DEPEND="!!sys-devel/llvm:0"
# @ECLASS-VARIABLE: LLVM_MAX_SLOT
# @DEFAULT_UNSET
# @DESCRIPTION:
@ -81,7 +85,7 @@ if [[ ! ${_LLVM_ECLASS} ]]; then
# @INTERNAL
# @DESCRIPTION:
# Correct values of LLVM slots, newest first.
declare -g -r _LLVM_KNOWN_SLOTS=( 9 8 7 6 5 4 )
declare -g -r _LLVM_KNOWN_SLOTS=( {15..8} )
# @FUNCTION: get_llvm_prefix
# @USAGE: [-b|-d] [<max_slot>]
@ -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
}