[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gentoo-dev
Subject:    [gentoo-dev] [PATCH 2/4] llvm.eclass: Support checking LLVM deps via llvm_check_deps()
From:       Michał Górny <mgorny () gentoo ! org>
Date:       2017-06-30 21:34:29
Message-ID: 20170630213431.17767-3-mgorny () gentoo ! org
[Download RAW message or body]

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 94adba17a2b7..2aeba9c8ae39 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=( 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.
-- 
2.13.2


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic