public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending
@ 2017-06-30 21:34 Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 1/4] llvm.eclass: Check for installed package rather than executable Michał Górny
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Michał Górny @ 2017-06-30 21:34 UTC (permalink / raw
  To: gentoo-dev

Hi,

Here's a quick batch of patches to llvm.eclass that aims to solve two
problems.

The first two patches (and the package example following the patch set)
redesign the slot testing mechanism to allow llvm_check_deps() function
(alike python_check_deps() in python-any-r1). It can be used to redefine
how the eclass checks whether the specific LLVM slot is acceptable.

For example, if you define:

  llvm_check_deps() { has_version "sys-devel/clang:${LLVM_SLOT}"; }

then it will only consider the slots which have clang installed. You can
also use it to check USE dependencies. This way we can write ebuilds
that can handle the case when user has multiple LLVM slots installed
in different configurations. This is bug #622782 [1], solved in a bit
more generic way.

The third patch ensures that only /usr/lib/llvm/* paths are prepended to
PATH, and not /usr/bin (for slot 0). The latter is unnecessary
and breaks other prepends, e.g. distcc/ccache. This is bug #622866 [2].

Please review. TIA.

[1]:https://bugs.gentoo.org/show_bug.cgi?id=622782
[2]:https://bugs.gentoo.org/show_bug.cgi?id=622866

--
Best regards,
Michał Górny



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 1/4] llvm.eclass: Check for installed package rather than executable
  2017-06-30 21:34 [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending Michał Górny
@ 2017-06-30 21:34 ` Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 2/4] llvm.eclass: Support checking LLVM deps via llvm_check_deps() Michał Górny
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2017-06-30 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Ensure that a specific LLVM slot is installed via using has_version on
"sys-devel/llvm:${SLOT}" rather than checking whether llvm-config is
installed in expected location. While it is a bit slower, this is closer
to a canonical way of testing it and will be useful when we allow
testing for more specific dependency strings. Right now, it could be
helpful if one has broken LLVM installation (i.e. stray files).
---
 eclass/llvm.eclass | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
index 294e27b019b9..94adba17a2b7 100644
--- a/eclass/llvm.eclass
+++ b/eclass/llvm.eclass
@@ -91,9 +91,9 @@ get_llvm_prefix() {
 			fi
 		fi
 
-		local p=${EPREFIX}/usr/lib/llvm/${slot}
-		if [[ -x ${p}/bin/llvm-config ]]; then
-			echo "${p}"
+		# check if LLVM package is installed
+		if has_version "sys-devel/llvm:${slot}"; then
+			echo "${EPREFIX}/usr/lib/llvm/${slot}"
 			return
 		fi
 	done
@@ -105,13 +105,12 @@ get_llvm_prefix() {
 
 	# fallback to :0
 	# assume it's always <= 4 (the lower max_slot allowed)
-	p=${EPREFIX}/usr
-	if [[ -x ${p}/bin/llvm-config ]]; then
-		echo "${p}"
+	if has_version "sys-devel/llvm:0"; then
+		echo "${EPREFIX}/usr"
 		return
 	fi
 
-	die "No LLVM slot${1:+ <= ${1}} found in PATH!"
+	die "No LLVM slot${1:+ <= ${1}} found installed!"
 }
 
 # @FUNCTION: llvm_pkg_setup
-- 
2.13.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 2/4] llvm.eclass: Support checking LLVM deps via llvm_check_deps()
  2017-06-30 21:34 [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 1/4] llvm.eclass: Check for installed package rather than executable Michał Górny
@ 2017-06-30 21:34 ` Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 3/4] llvm.eclass: Do not prepend /usr/bin to PATH, #622866 Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 4/4] dev-util/creduce: Require an LLVM slot with clang installed Michał Górny
  3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2017-06-30 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 3/4] llvm.eclass: Do not prepend /usr/bin to PATH, #622866
  2017-06-30 21:34 [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 1/4] llvm.eclass: Check for installed package rather than executable Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 2/4] llvm.eclass: Support checking LLVM deps via llvm_check_deps() Michał Górny
@ 2017-06-30 21:34 ` Michał Górny
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 4/4] dev-util/creduce: Require an LLVM slot with clang installed Michał Górny
  3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2017-06-30 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

---
 eclass/llvm.eclass | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass
index 2aeba9c8ae39..73af88e44b8e 100644
--- a/eclass/llvm.eclass
+++ b/eclass/llvm.eclass
@@ -159,7 +159,13 @@ llvm_pkg_setup() {
 	debug-print-function ${FUNCNAME} "${@}"
 
 	if [[ ${MERGE_TYPE} != binary ]]; then
-		export PATH=$(get_llvm_prefix ${LLVM_MAX_SLOT})/bin:${PATH}
+		local llvm_prefix=$(get_llvm_prefix "${LLVM_MAX_SLOT}")
+
+		# 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
 	fi
 }
 
-- 
2.13.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [gentoo-dev] [PATCH 4/4] dev-util/creduce: Require an LLVM slot with clang installed
  2017-06-30 21:34 [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending Michał Górny
                   ` (2 preceding siblings ...)
  2017-06-30 21:34 ` [gentoo-dev] [PATCH 3/4] llvm.eclass: Do not prepend /usr/bin to PATH, #622866 Michał Górny
@ 2017-06-30 21:34 ` Michał Górny
  3 siblings, 0 replies; 5+ messages in thread
From: Michał Górny @ 2017-06-30 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

---
 dev-util/creduce/creduce-9999.ebuild | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/dev-util/creduce/creduce-9999.ebuild b/dev-util/creduce/creduce-9999.ebuild
index 2e937d6c35e0..f22a1889c848 100644
--- a/dev-util/creduce/creduce-9999.ebuild
+++ b/dev-util/creduce/creduce-9999.ebuild
@@ -7,7 +7,7 @@ EGIT_REPO_URI="https://github.com/csmith-project/creduce
 	git://github.com/csmith-project/creduce"
 
 : ${CMAKE_MAKEFILE_GENERATOR=ninja}
-inherit cmake-utils git-r3
+inherit cmake-utils git-r3 llvm
 
 DESCRIPTION="C-Reduce - a plugin-based C program reducer"
 HOMEPAGE="http://embed.cs.utah.edu/creduce/"
@@ -31,3 +31,7 @@ RDEPEND="${COMMON_DEPEND}
 	dev-util/astyle
 	dev-util/indent"
 DEPEND="${COMMON_DEPEND}"
+
+llvm_check_deps() {
+	has_version "sys-devel/clang:${LLVM_SLOT}"
+}
-- 
2.13.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-06-30 21:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-30 21:34 [gentoo-dev] [PATCHES] llvm.eclass: More flexible slot testing and fix to /usr/bin PATH prepending Michał Górny
2017-06-30 21:34 ` [gentoo-dev] [PATCH 1/4] llvm.eclass: Check for installed package rather than executable Michał Górny
2017-06-30 21:34 ` [gentoo-dev] [PATCH 2/4] llvm.eclass: Support checking LLVM deps via llvm_check_deps() Michał Górny
2017-06-30 21:34 ` [gentoo-dev] [PATCH 3/4] llvm.eclass: Do not prepend /usr/bin to PATH, #622866 Michał Górny
2017-06-30 21:34 ` [gentoo-dev] [PATCH 4/4] dev-util/creduce: Require an LLVM slot with clang installed Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox