commit:     672d7885d6de8969dbc8df5b168a253afa68cbea
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 30 21:09:33 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sat Aug 12 21:21:29 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=672d7885

llvm.eclass: Support checking LLVM deps via llvm_check_deps()

Introduce the support for llvm_check_deps() function to override
the default LLVM slot acceptance test (checking whether sys-devel/llvm
is installed). This can be used to match more complex dependency
specifications, e.g. to find a LLVM slot that has a matching clang
version, or to request USE dependencies on LLVM or clang.

 eclass/llvm.eclass | 60 ++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 45 insertions(+), 15 deletions(-)

diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
index 4df3825e6e3..fc09a7d9598 100644
--- a/eclass/llvm.eclass
+++ b/eclass/llvm.eclass
@@ -37,6 +37,21 @@
 #      do-something-else
 # }
 # @CODE
+#
+# Example for a package needing LLVM+clang w/ a specific target:
+# @CODE
+# inherit cmake-utils 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-4:=[llvm_targets_AMDGPU(+)]
+# "
+#
+# llvm_check_deps() {
+#      has_version "sys-devel/clang:${LLVM_SLOT}[llvm_targets_AMDGPU(+)]"
+# }
+# @CODE
 
 case "${EAPI:-0}" in
        0|1|2|3|4|5)
@@ -68,14 +83,22 @@ declare -g -r _LLVM_KNOWN_SLOTS=( 6 5 4 )
 # @FUNCTION: get_llvm_prefix
 # @USAGE: [<max_slot>]
 # @DESCRIPTION:
-# Prints the absolute path to an LLVM install prefix corresponding to
-# the newest installed version of LLVM that is not newer than
-# <max_slot>. If no <max_slot> is specified, there is no upper limit.
+# Find the newest LLVM install that is acceptable for the package,
+# and print an absolute path to it.
+#
+# If <max_slot> is specified, then only LLVM versions that are not newer
+# than <max_slot> will be considered. Otherwise, all LLVM versions would
+# be considered acceptable. The function does not support specifying
+# minimal supported version -- the developer must ensure that a version
+# new enough is installed via providing appropriate dependencies.
 #
-# Note that the function does not support lower-bound version, so you
-# need to provide correct dependencies to ensure that a new enough
-# version will be always installed. Otherwise, the function could return
-# a version lower than required.
+# If llvm_check_deps() function is defined within the ebuild, it will
+# be called to verify whether a particular slot is accepable. Within
+# the function scope, LLVM_SLOT will be defined to the SLOT value
+# (0, 4, 5...). The function should return a true status if the slot
+# is acceptable, false otherwise. If llvm_check_deps() is not defined,
+# the function defaults to checking whether sys-devel/llvm:${LLVM_SLOT}
+# is installed.
 get_llvm_prefix() {
        debug-print-function ${FUNCNAME} "${@}"
 
@@ -91,11 +114,16 @@ get_llvm_prefix() {
                        fi
                fi
 
-               # check if LLVM package is installed
-               if has_version "sys-devel/llvm:${slot}"; then
-                       echo "${EPREFIX}/usr/lib/llvm/${slot}"
-                       return
+               if declare -f llvm_check_deps >/dev/null; then
+                       local LLVM_SLOT=${slot}
+                       llvm_check_deps || continue
+               else
+                       # check if LLVM package is installed
+                       has_version "sys-devel/llvm:${slot}" || continue
                fi
+
+               echo "${EPREFIX}/usr/lib/llvm/${slot}"
+               return
        done
 
        # max_slot should have been unset in the iteration
@@ -115,10 +143,12 @@ get_llvm_prefix() {
 
 # @FUNCTION: llvm_pkg_setup
 # @DESCRIPTION:
-# Prepend the executable directory corresponding to the newest
-# installed LLVM version that is not newer than ${LLVM_MAX_SLOT}
-# to PATH. If LLVM_MAX_SLOT is unset or empty, the newest installed
-# slot will be used.
+# Prepend the appropriate executable directory for the newest
+# acceptable LLVM slot to the PATH. For path determination logic,
+# please see the get_llvm_prefix documentation.
+#
+# The highest acceptable LLVM slot can be set in LLVM_MAX_SLOT variable.
+# If it is unset or empty, any slot is acceptable.
 #
 # The PATH manipulation is only done for source builds. The function
 # is a no-op when installing a binary package.

Reply via email to