Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/4] llvm.eclass: Support checking LLVM deps via llvm_check_deps()
Date: Fri, 30 Jun 2017 21:36:20
Message-Id: 20170630213431.17767-3-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending by "Michał Górny"
1 Introduce the support for llvm_check_deps() function to override
2 the default LLVM slot acceptance test (checking whether sys-devel/llvm
3 is installed). This can be used to match more complex dependency
4 specifications, e.g. to find a LLVM slot that has a matching clang
5 version, or to request USE dependencies on LLVM or clang.
6 ---
7 eclass/llvm.eclass | 60 ++++++++++++++++++++++++++++++++++++++++--------------
8 1 file changed, 45 insertions(+), 15 deletions(-)
9
10 diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
11 index 94adba17a2b7..2aeba9c8ae39 100644
12 --- a/eclass/llvm.eclass
13 +++ b/eclass/llvm.eclass
14 @@ -37,6 +37,21 @@
15 # do-something-else
16 # }
17 # @CODE
18 +#
19 +# Example for a package needing LLVM+clang w/ a specific target:
20 +# @CODE
21 +# inherit cmake-utils llvm
22 +#
23 +# # note: do not use := on both clang and llvm, it can match different
24 +# # slots then. clang pulls llvm in, so we can skip the latter.
25 +# RDEPEND="
26 +# >=sys-devel/clang-4:=[llvm_targets_AMDGPU(+)]
27 +# "
28 +#
29 +# llvm_check_deps() {
30 +# has_version "sys-devel/clang:${LLVM_SLOT}[llvm_targets_AMDGPU(+)]"
31 +# }
32 +# @CODE
33
34 case "${EAPI:-0}" in
35 0|1|2|3|4|5)
36 @@ -68,14 +83,22 @@ declare -g -r _LLVM_KNOWN_SLOTS=( 5 4 )
37 # @FUNCTION: get_llvm_prefix
38 # @USAGE: [<max_slot>]
39 # @DESCRIPTION:
40 -# Prints the absolute path to an LLVM install prefix corresponding to
41 -# the newest installed version of LLVM that is not newer than
42 -# <max_slot>. If no <max_slot> is specified, there is no upper limit.
43 +# Find the newest LLVM install that is acceptable for the package,
44 +# and print an absolute path to it.
45 +#
46 +# If <max_slot> is specified, then only LLVM versions that are not newer
47 +# than <max_slot> will be considered. Otherwise, all LLVM versions would
48 +# be considered acceptable. The function does not support specifying
49 +# minimal supported version -- the developer must ensure that a version
50 +# new enough is installed via providing appropriate dependencies.
51 #
52 -# Note that the function does not support lower-bound version, so you
53 -# need to provide correct dependencies to ensure that a new enough
54 -# version will be always installed. Otherwise, the function could return
55 -# a version lower than required.
56 +# If llvm_check_deps() function is defined within the ebuild, it will
57 +# be called to verify whether a particular slot is accepable. Within
58 +# the function scope, LLVM_SLOT will be defined to the SLOT value
59 +# (0, 4, 5...). The function should return a true status if the slot
60 +# is acceptable, false otherwise. If llvm_check_deps() is not defined,
61 +# the function defaults to checking whether sys-devel/llvm:${LLVM_SLOT}
62 +# is installed.
63 get_llvm_prefix() {
64 debug-print-function ${FUNCNAME} "${@}"
65
66 @@ -91,11 +114,16 @@ get_llvm_prefix() {
67 fi
68 fi
69
70 - # check if LLVM package is installed
71 - if has_version "sys-devel/llvm:${slot}"; then
72 - echo "${EPREFIX}/usr/lib/llvm/${slot}"
73 - return
74 + if declare -f llvm_check_deps >/dev/null; then
75 + local LLVM_SLOT=${slot}
76 + llvm_check_deps || continue
77 + else
78 + # check if LLVM package is installed
79 + has_version "sys-devel/llvm:${slot}" || continue
80 fi
81 +
82 + echo "${EPREFIX}/usr/lib/llvm/${slot}"
83 + return
84 done
85
86 # max_slot should have been unset in the iteration
87 @@ -115,10 +143,12 @@ get_llvm_prefix() {
88
89 # @FUNCTION: llvm_pkg_setup
90 # @DESCRIPTION:
91 -# Prepend the executable directory corresponding to the newest
92 -# installed LLVM version that is not newer than ${LLVM_MAX_SLOT}
93 -# to PATH. If LLVM_MAX_SLOT is unset or empty, the newest installed
94 -# slot will be used.
95 +# Prepend the appropriate executable directory for the newest
96 +# acceptable LLVM slot to the PATH. For path determination logic,
97 +# please see the get_llvm_prefix documentation.
98 +#
99 +# The highest acceptable LLVM slot can be set in LLVM_MAX_SLOT variable.
100 +# If it is unset or empty, any slot is acceptable.
101 #
102 # The PATH manipulation is only done for source builds. The function
103 # is a no-op when installing a binary package.
104 --
105 2.13.2