public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds
@ 2020-09-30 16:23 Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 1/4] lua.eclass: split some stuff out as lua-utils.eclass Marek Szuba
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Marek Szuba @ 2020-09-30 16:23 UTC (permalink / raw
  To: gentoo-dev

Same as lua.eclass and python-r1, this is a Lua version of
python-single-r1. Setting LUA_SINGLE_TARGETS allows one to choose the
(slotted) Lua implementation to build your ebuild against, optionally
including both single- and multi-implementation Lua packages as
dependencies.

Tested using modified ebuilds of the following packages:

 - dev-lua/lgi - the multi-impl package I previously used to test
   lua.eclass, rebuilt this time to make sure said eclass still works
   properly after having moved some variables and functions to
   lua-utils.eclass (it does);

 - x11-wm/awesome - single-implementation, unconditionally depends on
   both dev-lang/lua itself and dev-lua/lgi (as well as some other
   dev-lua packages used by the test suite, which however I ignored).
   Links fine against whichever Lua version is selected by
   LUA_SINGLE_TARGET, requiring correct LUA_TARGETS to be enabled for
   dev-lua/lgi in either case;

 - media-gfx/darktable - conditional dependency on dev-lang/lua
   controlled by USE=lua. Also builds fine, although with it only
   supporting lua-5.3+ there wasn't much I could do in terms of version
   switching beyond confirming that LUA_REQUIRED_USE correctly specifies
   that exactly one single target must be specified.




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

* [gentoo-dev] [PATCH 1/4] lua.eclass: split some stuff out as lua-utils.eclass
  2020-09-30 16:23 [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds Marek Szuba
@ 2020-09-30 16:23 ` Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 2/4] lua.eclass: die if lua-single.eclass has already been loaded Marek Szuba
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marek Szuba @ 2020-09-30 16:23 UTC (permalink / raw
  To: gentoo-dev

These are the things that will be used by both lua and lua-single.

Signed-off-by: Marek Szuba <marecki@gentoo.org>
---
 eclass/lua-utils.eclass | 373 ++++++++++++++++++++++++++++++++++++++++
 eclass/lua.eclass       | 345 +------------------------------------
 2 files changed, 379 insertions(+), 339 deletions(-)
 create mode 100644 eclass/lua-utils.eclass

diff --git a/eclass/lua-utils.eclass b/eclass/lua-utils.eclass
new file mode 100644
index 00000000000..490d19a0019
--- /dev/null
+++ b/eclass/lua-utils.eclass
@@ -0,0 +1,373 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: lua-utils.eclass
+# @MAINTAINER:
+# William Hubbs <williamh@gentoo.org>
+# Marek Szuba <marecki@gentoo.org>
+# @AUTHOR:
+# Marek Szuba <marecki@gentoo.org>
+# Based on python-utils-r1.eclass by Michał Górny <mgorny@gentoo.org> et al.
+# @SUPPORTED_EAPIS: 7
+# @BLURB: Utility functions for packages with Lua parts
+# @DESCRIPTION:
+# A utility eclass providing functions to query Lua implementations,
+# install Lua modules and scripts.
+#
+# Please note that for the time being this eclass does NOT support luajit.
+#
+# This eclass neither sets any metadata variables nor exports any phase
+# functions. It can be inherited safely.
+
+case ${EAPI:-0} in
+	0|1|2|3|4|5|6)
+		die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
+		;;
+	7)
+		;;
+	*)
+		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+		;;
+esac
+
+if [[ ! ${_LUA_UTILS_R0} ]]; then
+
+inherit toolchain-funcs
+
+# @ECLASS-VARIABLE: _LUA_ALL_IMPLS
+# @INTERNAL
+# @DESCRIPTION:
+# All supported Lua implementations, most preferred last
+_LUA_ALL_IMPLS=(
+	lua5-1
+	lua5-2
+	lua5-3
+	lua5-4
+)
+readonly _LUA_ALL_IMPLS
+
+# @FUNCTION: _lua_set_impls
+# @INTERNAL
+# @DESCRIPTION:
+# Check LUA_COMPAT for well-formedness and validity, then set
+# two global variables:
+#
+# - _LUA_SUPPORTED_IMPLS containing valid implementations supported
+#   by the ebuild (LUA_COMPAT minus dead implementations),
+#
+# - and _LUA_UNSUPPORTED_IMPLS containing valid implementations that
+#   are not supported by the ebuild.
+#
+# Implementations in both variables are ordered using the pre-defined
+# eclass implementation ordering.
+#
+# This function must only be called once.
+_lua_set_impls() {
+	local i
+
+	if ! declare -p LUA_COMPAT &>/dev/null; then
+		die 'LUA_COMPAT not declared.'
+	fi
+	if [[ $(declare -p LUA_COMPAT) != "declare -a"* ]]; then
+		die 'LUA_COMPAT must be an array.'
+	fi
+
+	local supp=() unsupp=()
+
+	for i in "${_LUA_ALL_IMPLS[@]}"; do
+		if has "${i}" "${LUA_COMPAT[@]}"; then
+			supp+=( "${i}" )
+		else
+			unsupp+=( "${i}" )
+		fi
+	done
+
+	if [[ ! ${supp[@]} ]]; then
+		die "No supported implementation in LUA_COMPAT."
+	fi
+
+	if [[ ${_LUA_SUPPORTED_IMPLS[@]} ]]; then
+		# set once already, verify integrity
+		if [[ ${_LUA_SUPPORTED_IMPLS[@]} != ${supp[@]} ]]; then
+			eerror "Supported impls (LUA_COMPAT) changed between inherits!"
+			eerror "Before: ${_LUA_SUPPORTED_IMPLS[*]}"
+			eerror "Now   : ${supp[*]}"
+			die "_LUA_SUPPORTED_IMPLS integrity check failed"
+		fi
+		if [[ ${_LUA_UNSUPPORTED_IMPLS[@]} != ${unsupp[@]} ]]; then
+			eerror "Unsupported impls changed between inherits!"
+			eerror "Before: ${_LUA_UNSUPPORTED_IMPLS[*]}"
+			eerror "Now   : ${unsupp[*]}"
+			die "_LUA_UNSUPPORTED_IMPLS integrity check failed"
+		fi
+	else
+		_LUA_SUPPORTED_IMPLS=( "${supp[@]}" )
+		_LUA_UNSUPPORTED_IMPLS=( "${unsupp[@]}" )
+		readonly _LUA_SUPPORTED_IMPLS _LUA_UNSUPPORTED_IMPLS
+	fi
+}
+
+# @FUNCTION: _lua_wrapper_setup
+# @USAGE: [<path> [<impl>]]
+# @INTERNAL
+# @DESCRIPTION:
+# Create proper Lua executables and pkg-config wrappers
+# (if available) in the directory named by <path>. Set up PATH
+# and PKG_CONFIG_PATH appropriately. <path> defaults to ${T}/${ELUA}.
+#
+# The wrappers will be created for implementation named by <impl>,
+# or for one named by ${ELUA} if no <impl> passed.
+#
+# If the named directory contains a lua symlink already, it will
+# be assumed to contain proper wrappers already and only environment
+# setup will be done. If wrapper update is requested, the directory
+# shall be removed first.
+_lua_wrapper_setup() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local workdir=${1:-${T}/${ELUA}}
+	local impl=${2:-${ELUA}}
+
+	[[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
+	[[ ${impl} ]] || die "${FUNCNAME}: no impl nor ELUA specified."
+
+	if [[ ! -x ${workdir}/bin/lua ]]; then
+		mkdir -p "${workdir}"/{bin,pkgconfig} || die
+
+		# Clean up, in case we were supposed to do a cheap update
+		rm -f "${workdir}"/bin/lua{,c} || die
+		rm -f "${workdir}"/pkgconfig/lua.pc || die
+
+		local ELUA LUA
+		_lua_export "${impl}" ELUA LUA
+
+		# Lua interpreter and compiler
+		ln -s "${EPREFIX}"/usr/bin/${ELUA} "${workdir}"/bin/lua || die
+		ln -s "${EPREFIX}"/usr/bin/${ELUA/a/ac} "${workdir}"/bin/luac || die
+
+		# pkg-config
+		ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${ELUA}.pc \
+			"${workdir}"/pkgconfig/lua.pc || die
+	fi
+
+	# Now, set the environment.
+	# But note that ${workdir} may be shared with something else,
+	# and thus already on top of PATH.
+	if [[ ${PATH##:*} != ${workdir}/bin ]]; then
+		PATH=${workdir}/bin${PATH:+:${PATH}}
+	fi
+	if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
+		PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
+	fi
+	export PATH PKG_CONFIG_PATH
+}
+
+# @ECLASS-VARIABLE: ELUA
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# The executable name of the current Lua interpreter. This variable is set
+# automatically in functions called by lua_foreach_impl().
+#
+# Example value:
+# @CODE
+# lua5.1
+# @CODE
+
+# @ECLASS-VARIABLE: LUA
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# The absolute path to the current Lua interpreter. This variable is set
+# automatically in functions called by lua_foreach_impl().
+#
+# Example value:
+# @CODE
+# /usr/bin/lua5.1
+# @CODE
+
+# @FUNCTION: _lua_export
+# @USAGE: [<impl>] <variables>...
+# @INTERNAL
+# @DESCRIPTION:
+# Set and export the Lua implementation-relevant variables passed
+# as parameters.
+#
+# The optional first parameter may specify the requested Lua
+# implementation (either as LUA_TARGETS value, e.g. lua5-2,
+# or an ELUA one, e.g. lua5.2). If no implementation passed,
+# the current one will be obtained from ${ELUA}.
+_lua_export() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl var
+
+	case "${1}" in
+		lua*)
+			impl=${1/-/.}
+			shift
+			;;
+		*)
+			impl=${ELUA}
+			if [[ -z ${impl} ]]; then
+				die "_lua_export called without a Lua implementation and ELUA is unset"
+			fi
+			;;
+	esac
+	debug-print "${FUNCNAME}: implementation: ${impl}"
+
+	for var; do
+		case "${var}" in
+			ELUA)
+				export ELUA=${impl}
+				debug-print "${FUNCNAME}: ELUA = ${ELUA}"
+				;;
+			LUA)
+				export LUA="${EPREFIX}"/usr/bin/${impl}
+				debug-print "${FUNCNAME}: LUA = ${LUA}"
+				;;
+			LUA_CFLAGS)
+				local val
+
+				val=$($(tc-getPKG_CONFIG) --cflags ${impl}) || die
+
+				export LUA_CFLAGS=${val}
+				debug-print "${FUNCNAME}: LUA_CFLAGS = ${LUA_CFLAGS}"
+				;;
+			LUA_CMOD_DIR)
+				local val
+
+				val=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${impl}) || die
+
+				export LUA_CMOD_DIR=${val}
+				debug-print "${FUNCNAME}: LUA_CMOD_DIR = ${LUA_CMOD_DIR}"
+				;;
+			LUA_LIBS)
+				local val
+
+				val=$($(tc-getPKG_CONFIG) --libs ${impl}) || die
+
+				export LUA_LIBS=${val}
+				debug-print "${FUNCNAME}: LUA_LIBS = ${LUA_LIBS}"
+				;;
+			LUA_LMOD_DIR)
+				local val
+
+				val=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${impl}) || die
+
+				export LUA_LMOD_DIR=${val}
+				debug-print "${FUNCNAME}: LUA_LMOD_DIR = ${LUA_LMOD_DIR}"
+				;;
+			LUA_PKG_DEP)
+				local d
+				case ${impl} in
+					lua*)
+						LUA_PKG_DEP="dev-lang/lua:${impl#lua}"
+						;;
+					*)
+						die "Invalid implementation: ${impl}"
+						;;
+				esac
+
+				# use-dep
+				if [[ ${LUA_REQ_USE} ]]; then
+					LUA_PKG_DEP+=[${LUA_REQ_USE}]
+				fi
+
+				export LUA_PKG_DEP
+				debug-print "${FUNCNAME}: LUA_PKG_DEP = ${LUA_PKG_DEP}"
+				;;
+			LUA_VERSION)
+				local val
+
+				val=$($(tc-getPKG_CONFIG) --modversion ${impl}) || die
+
+				export LUA_VERSION=${val}
+				debug-print "${FUNCNAME}: LUA_VERSION = ${LUA_VERSION}"
+				;;
+			*)
+				die "_lua_export: unknown variable ${var}"
+				;;
+		esac
+	done
+}
+
+# @FUNCTION: lua_get_CFLAGS
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the compiler flags for building against Lua,
+# for the given implementation. If no implementation is provided,
+# ${ELUA} will be used.
+#
+# Please note that this function requires Lua and pkg-config installed,
+# and therefore proper build-time dependencies need be added to the ebuild.
+lua_get_CFLAGS() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	_lua_export "${@}" LUA_CFLAGS
+	echo "${LUA_CFLAGS}"
+}
+
+# @FUNCTION: lua_get_cmod_dir
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the name of the directory into which compiled Lua
+# modules are installed, for the given implementation. If no implementation
+# is provided, ${ELUA} will be used.
+#
+# Please note that this function requires Lua and pkg-config installed,
+# and therefore proper build-time dependencies need be added to the ebuild.
+lua_get_cmod_dir() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	_lua_export "${@}" LUA_CMOD_DIR
+	echo "${LUA_CMOD_DIR}"
+}
+
+# @FUNCTION: lua_get_LIBS
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the compiler flags for linking against Lua,
+# for the given implementation. If no implementation is provided,
+# ${ELUA} will be used.
+#
+# Please note that this function requires Lua and pkg-config installed,
+# and therefore proper build-time dependencies need be added to the ebuild.
+lua_get_LIBS() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	_lua_export "${@}" LUA_LIBS
+	echo "${LUA_LIBS}"
+}
+
+# @FUNCTION: lua_get_lmod_dir
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the name of the directory into which native-Lua
+# modules are installed, for the given implementation. If no implementation
+# is provided, ${ELUA} will be used.
+#
+# Please note that this function requires Lua and pkg-config installed,
+# and therefore proper build-time dependencies need be added to the ebuild.
+lua_get_lmod_dir() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	_lua_export "${@}" LUA_LMOD_DIR
+	echo "${LUA_LMOD_DIR}"
+}
+
+# @FUNCTION: lua_get_version
+# @USAGE: [<impl>]
+# @DESCRIPTION:
+# Obtain and print the full version number of the given Lua implementation.
+# If no implementation is provided, ${ELUA} will be used.
+#
+# Please note that this function requires Lua and pkg-config installed,
+# and therefore proper build-time dependencies need be added to the ebuild.
+lua_get_version() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	_lua_export "${@}" LUA_VERSION
+	echo "${LUA_VERSION}"
+}
+
+_LUA_UTILS_R0=1
+fi
diff --git a/eclass/lua.eclass b/eclass/lua.eclass
index 7dccba6980a..f4594872e58 100644
--- a/eclass/lua.eclass
+++ b/eclass/lua.eclass
@@ -7,7 +7,7 @@
 # Marek Szuba <marecki@gentoo.org>
 # @AUTHOR:
 # Marek Szuba <marecki@gentoo.org>
-# Based on python{,-utils}-r1.eclass by Michał Górny <mgorny@gentoo.org> et al.
+# Based on python-r1.eclass by Michał Górny <mgorny@gentoo.org> et al.
 # @SUPPORTED_EAPIS: 7
 # @BLURB: A common eclass for Lua packages
 # @DESCRIPTION:
@@ -21,7 +21,9 @@
 # package easily. It also provides methods to easily run a command for
 # each enabled Lua implementation and duplicate the sources for them.
 #
-# Please note that for the time being this eclass does NOT support luajit.
+# Note that since this eclass always inherits lua-utils as well, in ebuilds
+# using the former there is no need to explicitly inherit the latter in order
+# to use helper functions such as lua_get_CFLAGS.
 #
 # @EXAMPLE:
 # @CODE
@@ -61,7 +63,7 @@ esac
 
 if [[ ! ${_LUA_R0} ]]; then
 
-inherit multibuild toolchain-funcs
+inherit multibuild lua-utils
 
 fi
 
@@ -140,28 +142,6 @@ fi
 # ${WORKDIR}/foo-1.3-lua5-1
 # @CODE
 
-# @ECLASS-VARIABLE: ELUA
-# @DEFAULT_UNSET
-# @DESCRIPTION:
-# The executable name of the current Lua interpreter. This variable is set
-# automatically in functions called by lua_foreach_impl().
-#
-# Example value:
-# @CODE
-# lua5.1
-# @CODE
-
-# @ECLASS-VARIABLE: LUA
-# @DEFAULT_UNSET
-# @DESCRIPTION:
-# The absolute path to the current Lua interpreter. This variable is set
-# automatically in functions called by lua_foreach_impl().
-#
-# Example value:
-# @CODE
-# /usr/bin/lua5.1
-# @CODE
-
 # @ECLASS-VARIABLE: LUA_DEPS
 # @OUTPUT_VARIABLE
 # @DESCRIPTION:
@@ -219,112 +199,6 @@ fi
 
 if [[ ! ${_LUA_R0} ]]; then
 
-# @FUNCTION: _lua_export
-# @USAGE: [<impl>] <variables>...
-# @INTERNAL
-# @DESCRIPTION:
-# Set and export the Lua implementation-relevant variables passed
-# as parameters.
-#
-# The optional first parameter may specify the requested Lua
-# implementation (either as LUA_TARGETS value, e.g. lua5-2,
-# or an ELUA one, e.g. lua5.2). If no implementation passed,
-# the current one will be obtained from ${ELUA}.
-_lua_export() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	local impl var
-
-	case "${1}" in
-		lua*)
-			impl=${1/-/.}
-			shift
-			;;
-		*)
-			impl=${ELUA}
-			if [[ -z ${impl} ]]; then
-				die "_lua_export called without a Lua implementation and ELUA is unset"
-			fi
-			;;
-	esac
-	debug-print "${FUNCNAME}: implementation: ${impl}"
-
-	for var; do
-		case "${var}" in
-			ELUA)
-				export ELUA=${impl}
-				debug-print "${FUNCNAME}: ELUA = ${ELUA}"
-				;;
-			LUA)
-				export LUA="${EPREFIX}"/usr/bin/${impl}
-				debug-print "${FUNCNAME}: LUA = ${LUA}"
-				;;
-			LUA_CFLAGS)
-				local val
-
-				val=$($(tc-getPKG_CONFIG) --cflags ${impl}) || die
-
-				export LUA_CFLAGS=${val}
-				debug-print "${FUNCNAME}: LUA_CFLAGS = ${LUA_CFLAGS}"
-				;;
-			LUA_CMOD_DIR)
-				local val
-
-				val=$($(tc-getPKG_CONFIG) --variable INSTALL_CMOD ${impl}) || die
-
-				export LUA_CMOD_DIR=${val}
-				debug-print "${FUNCNAME}: LUA_CMOD_DIR = ${LUA_CMOD_DIR}"
-				;;
-			LUA_LIBS)
-				local val
-
-				val=$($(tc-getPKG_CONFIG) --libs ${impl}) || die
-
-				export LUA_LIBS=${val}
-				debug-print "${FUNCNAME}: LUA_LIBS = ${LUA_LIBS}"
-				;;
-			LUA_LMOD_DIR)
-				local val
-
-				val=$($(tc-getPKG_CONFIG) --variable INSTALL_LMOD ${impl}) || die
-
-				export LUA_LMOD_DIR=${val}
-				debug-print "${FUNCNAME}: LUA_LMOD_DIR = ${LUA_LMOD_DIR}"
-				;;
-			LUA_PKG_DEP)
-				local d
-				case ${impl} in
-					lua*)
-						LUA_PKG_DEP="dev-lang/lua:${impl#lua}"
-						;;
-					*)
-						die "Invalid implementation: ${impl}"
-						;;
-				esac
-
-				# use-dep
-				if [[ ${LUA_REQ_USE} ]]; then
-					LUA_PKG_DEP+=[${LUA_REQ_USE}]
-				fi
-
-				export LUA_PKG_DEP
-				debug-print "${FUNCNAME}: LUA_PKG_DEP = ${LUA_PKG_DEP}"
-				;;
-			LUA_VERSION)
-				local val
-
-				val=$($(tc-getPKG_CONFIG) --modversion ${impl}) || die
-
-				export LUA_VERSION=${val}
-				debug-print "${FUNCNAME}: LUA_VERSION = ${LUA_VERSION}"
-				;;
-			*)
-				die "_lua_export: unknown variable ${var}"
-				;;
-		esac
-	done
-}
-
 # @FUNCTION: _lua_validate_useflags
 # @INTERNAL
 # @DESCRIPTION:
@@ -401,61 +275,6 @@ _lua_multibuild_wrapper() {
 	"${@}"
 }
 
-# @FUNCTION: _lua_wrapper_setup
-# @USAGE: [<path> [<impl>]]
-# @INTERNAL
-# @DESCRIPTION:
-# Create proper Lua executables and pkg-config wrappers
-# (if available) in the directory named by <path>. Set up PATH
-# and PKG_CONFIG_PATH appropriately. <path> defaults to ${T}/${ELUA}.
-#
-# The wrappers will be created for implementation named by <impl>,
-# or for one named by ${ELUA} if no <impl> passed.
-#
-# If the named directory contains a lua symlink already, it will
-# be assumed to contain proper wrappers already and only environment
-# setup will be done. If wrapper update is requested, the directory
-# shall be removed first.
-_lua_wrapper_setup() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	local workdir=${1:-${T}/${ELUA}}
-	local impl=${2:-${ELUA}}
-
-	[[ ${workdir} ]] || die "${FUNCNAME}: no workdir specified."
-	[[ ${impl} ]] || die "${FUNCNAME}: no impl nor ELUA specified."
-
-	if [[ ! -x ${workdir}/bin/lua ]]; then
-		mkdir -p "${workdir}"/{bin,pkgconfig} || die
-
-		# Clean up, in case we were supposed to do a cheap update
-		rm -f "${workdir}"/bin/lua{,c} || die
-		rm -f "${workdir}"/pkgconfig/lua.pc || die
-
-		local ELUA LUA
-		_lua_export "${impl}" ELUA LUA
-
-		# Lua interpreter and compiler
-		ln -s "${EPREFIX}"/usr/bin/${ELUA} "${workdir}"/bin/lua || die
-		ln -s "${EPREFIX}"/usr/bin/${ELUA/a/ac} "${workdir}"/bin/luac || die
-
-		# pkg-config
-		ln -s "${EPREFIX}"/usr/$(get_libdir)/pkgconfig/${ELUA}.pc \
-			"${workdir}"/pkgconfig/lua.pc || die
-	fi
-
-	# Now, set the environment.
-	# But note that ${workdir} may be shared with something else,
-	# and thus already on top of PATH.
-	if [[ ${PATH##:*} != ${workdir}/bin ]]; then
-		PATH=${workdir}/bin${PATH:+:${PATH}}
-	fi
-	if [[ ${PKG_CONFIG_PATH##:*} != ${workdir}/pkgconfig ]]; then
-		PKG_CONFIG_PATH=${workdir}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}
-	fi
-	export PATH PKG_CONFIG_PATH
-}
-
 # @FUNCTION: lua_copy_sources
 # @DESCRIPTION:
 # Create a single copy of the package sources for each enabled Lua
@@ -495,161 +314,9 @@ lua_foreach_impl() {
 	multibuild_foreach_variant _lua_multibuild_wrapper "${@}"
 }
 
-# @FUNCTION: lua_get_CFLAGS
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the compiler flags for building against Lua,
-# for the given implementation. If no implementation is provided,
-# ${ELUA} will be used.
-#
-# Please note that this function requires Lua and pkg-config installed,
-# and therefore proper build-time dependencies need be added to the ebuild.
-lua_get_CFLAGS() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	_lua_export "${@}" LUA_CFLAGS
-	echo "${LUA_CFLAGS}"
-}
-
-# @FUNCTION: lua_get_cmod_dir
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the name of the directory into which compiled Lua
-# modules are installed, for the given implementation. If no implementation
-# is provided, ${ELUA} will be used.
-#
-# Please note that this function requires Lua and pkg-config installed,
-# and therefore proper build-time dependencies need be added to the ebuild.
-lua_get_cmod_dir() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	_lua_export "${@}" LUA_CMOD_DIR
-	echo "${LUA_CMOD_DIR}"
-}
-
-# @FUNCTION: lua_get_LIBS
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the compiler flags for linking against Lua,
-# for the given implementation. If no implementation is provided,
-# ${ELUA} will be used.
-#
-# Please note that this function requires Lua and pkg-config installed,
-# and therefore proper build-time dependencies need be added to the ebuild.
-lua_get_LIBS() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	_lua_export "${@}" LUA_LIBS
-	echo "${LUA_LIBS}"
-}
-
-# @FUNCTION: lua_get_lmod_dir
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the name of the directory into which native-Lua
-# modules are installed, for the given implementation. If no implementation
-# is provided, ${ELUA} will be used.
-#
-# Please note that this function requires Lua and pkg-config installed,
-# and therefore proper build-time dependencies need be added to the ebuild.
-lua_get_lmod_dir() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	_lua_export "${@}" LUA_LMOD_DIR
-	echo "${LUA_LMOD_DIR}"
-}
-
-# @FUNCTION: lua_get_version
-# @USAGE: [<impl>]
-# @DESCRIPTION:
-# Obtain and print the full version number of the given Lua implementation.
-# If no implementation is provided, ${ELUA} will be used.
-#
-# Please note that this function requires Lua and pkg-config installed,
-# and therefore proper build-time dependencies need be added to the ebuild.
-lua_get_version() {
-	debug-print-function ${FUNCNAME} "${@}"
-
-	_lua_export "${@}" LUA_VERSION
-	echo "${LUA_VERSION}"
-}
-
 _LUA_R0=1
 fi
 
-# @ECLASS-VARIABLE: _LUA_ALL_IMPLS
-# @INTERNAL
-# @DESCRIPTION:
-# All supported Lua implementations, most preferred last
-_LUA_ALL_IMPLS=(
-	lua5-1
-	lua5-2
-	lua5-3
-	lua5-4
-)
-readonly _LUA_ALL_IMPLS
-
-# @FUNCTION: _lua_set_impls
-# @INTERNAL
-# @DESCRIPTION:
-# Check LUA_COMPAT for well-formedness and validity, then set
-# two global variables:
-#
-# - _LUA_SUPPORTED_IMPLS containing valid implementations supported
-#   by the ebuild (LUA_COMPAT minus dead implementations),
-#
-# - and _LUA_UNSUPPORTED_IMPLS containing valid implementations that
-#   are not supported by the ebuild.
-#
-# Implementations in both variables are ordered using the pre-defined
-# eclass implementation ordering.
-#
-# This function must only be called once.
-_lua_set_impls() {
-	local i
-
-	if ! declare -p LUA_COMPAT &>/dev/null; then
-		die 'LUA_COMPAT not declared.'
-	fi
-	if [[ $(declare -p LUA_COMPAT) != "declare -a"* ]]; then
-		die 'LUA_COMPAT must be an array.'
-	fi
-
-	local supp=() unsupp=()
-
-	for i in "${_LUA_ALL_IMPLS[@]}"; do
-		if has "${i}" "${LUA_COMPAT[@]}"; then
-			supp+=( "${i}" )
-		else
-			unsupp+=( "${i}" )
-		fi
-	done
-
-	if [[ ! ${supp[@]} ]]; then
-		die "No supported implementation in LUA_COMPAT."
-	fi
-
-	if [[ ${_LUA_SUPPORTED_IMPLS[@]} ]]; then
-		# set once already, verify integrity
-		if [[ ${_LUA_SUPPORTED_IMPLS[@]} != ${supp[@]} ]]; then
-			eerror "Supported impls (LUA_COMPAT) changed between inherits!"
-			eerror "Before: ${_LUA_SUPPORTED_IMPLS[*]}"
-			eerror "Now   : ${supp[*]}"
-			die "_LUA_SUPPORTED_IMPLS integrity check failed"
-		fi
-		if [[ ${_LUA_UNSUPPORTED_IMPLS[@]} != ${unsupp[@]} ]]; then
-			eerror "Unsupported impls changed between inherits!"
-			eerror "Before: ${_LUA_UNSUPPORTED_IMPLS[*]}"
-			eerror "Now   : ${unsupp[*]}"
-			die "_LUA_UNSUPPORTED_IMPLS integrity check failed"
-		fi
-	else
-		_LUA_SUPPORTED_IMPLS=( "${supp[@]}" )
-		_LUA_UNSUPPORTED_IMPLS=( "${unsupp[@]}" )
-		readonly _LUA_SUPPORTED_IMPLS _LUA_UNSUPPORTED_IMPLS
-	fi
-}
-
 # @FUNCTION: _lua_set_globals
 # @INTERNAL
 # @DESCRIPTION:
@@ -707,4 +374,4 @@ _lua_set_globals() {
 }
 
 _lua_set_globals
-unset -f _lua_set_globals _lua_set_impls
+unset -f _lua_set_globals
-- 
2.26.2



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

* [gentoo-dev] [PATCH 2/4] lua.eclass: die if lua-single.eclass has already been loaded
  2020-09-30 16:23 [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 1/4] lua.eclass: split some stuff out as lua-utils.eclass Marek Szuba
@ 2020-09-30 16:23 ` Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 3/4] profiles/desc: describe LUA_SINGLE_TARGET Marek Szuba
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Marek Szuba @ 2020-09-30 16:23 UTC (permalink / raw
  To: gentoo-dev

Signed-off-by: Marek Szuba <marecki@gentoo.org>
---
 eclass/lua.eclass | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/eclass/lua.eclass b/eclass/lua.eclass
index f4594872e58..8ade9c0f079 100644
--- a/eclass/lua.eclass
+++ b/eclass/lua.eclass
@@ -63,6 +63,10 @@ esac
 
 if [[ ! ${_LUA_R0} ]]; then
 
+if [[ ${_LUA_SINGLE_R0} ]]; then
+	die 'lua.eclass cannot be used with lua-single.eclass.'
+fi
+
 inherit multibuild lua-utils
 
 fi
-- 
2.26.2



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

* [gentoo-dev] [PATCH 3/4] profiles/desc: describe LUA_SINGLE_TARGET
  2020-09-30 16:23 [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 1/4] lua.eclass: split some stuff out as lua-utils.eclass Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 2/4] lua.eclass: die if lua-single.eclass has already been loaded Marek Szuba
@ 2020-09-30 16:23 ` Marek Szuba
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 4/4] lua-single.eclass: new eclass for single-implementation Lua ebuilds Marek Szuba
  2020-10-01 18:31 ` [gentoo-dev] [PATCH 0/4] Eclass for single-impl " Daniel Pielmeier
  4 siblings, 0 replies; 8+ messages in thread
From: Marek Szuba @ 2020-09-30 16:23 UTC (permalink / raw
  To: gentoo-dev

Already includes lua-5.4.

Signed-off-by: Marek Szuba <marecki@gentoo.org>
---
 profiles/desc/lua_single_target.desc | 9 +++++++++
 1 file changed, 9 insertions(+)
 create mode 100644 profiles/desc/lua_single_target.desc

diff --git a/profiles/desc/lua_single_target.desc b/profiles/desc/lua_single_target.desc
new file mode 100644
index 00000000000..1bee02b6978
--- /dev/null
+++ b/profiles/desc/lua_single_target.desc
@@ -0,0 +1,9 @@
+# Copyright 1999-2020 Gentoo Authors.
+# Distributed under the terms of the GNU General Public License v2
+
+# This file contains descriptions of LUA_SINGLE_TARGET USE_EXPAND flags.
+
+lua5-1 - Build for Lua 5.1 only
+lua5-2 - Build for Lua 5.2 only
+lua5-3 - Build for Lua 5.3 only
+lua5-4 - Build for Lua 5.4 only
-- 
2.26.2



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

* [gentoo-dev] [PATCH 4/4] lua-single.eclass: new eclass for single-implementation Lua ebuilds
  2020-09-30 16:23 [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds Marek Szuba
                   ` (2 preceding siblings ...)
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 3/4] profiles/desc: describe LUA_SINGLE_TARGET Marek Szuba
@ 2020-09-30 16:23 ` Marek Szuba
  2020-10-01 18:31 ` [gentoo-dev] [PATCH 0/4] Eclass for single-impl " Daniel Pielmeier
  4 siblings, 0 replies; 8+ messages in thread
From: Marek Szuba @ 2020-09-30 16:23 UTC (permalink / raw
  To: gentoo-dev

With many thanks to Michał Górny and other authors of
python-single-r1.eclass.

Signed-off-by: Marek Szuba <marecki@gentoo.org>
---
 eclass/lua-single.eclass | 510 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 510 insertions(+)
 create mode 100644 eclass/lua-single.eclass

diff --git a/eclass/lua-single.eclass b/eclass/lua-single.eclass
new file mode 100644
index 00000000000..2233fdd33b6
--- /dev/null
+++ b/eclass/lua-single.eclass
@@ -0,0 +1,510 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: lua-single.eclass
+# @MAINTAINER:
+# William Hubbs <williamh@gentoo.org>
+# Marek Szuba <marecki@gentoo.org>
+# @AUTHOR:
+# Marek Szuba <marecki@gentoo.org>
+# Based on python-single-r1.eclass by Michał Górny <mgorny@gentoo.org> et al.
+# @SUPPORTED_EAPIS: 7
+# @BLURB: An eclass for Lua packages not installed for multiple implementations.
+# @DESCRIPTION:
+# An extension of lua.eclass suite for packages which don't support being
+# installed for multiple Lua implementations. This mostly includes software
+# embedding Lua.
+#
+# This eclass sets correct IUSE.  It also provides LUA_DEPS
+# and LUA_REQUIRED_USE that need to be added to appropriate ebuild
+# metadata variables.
+#
+# The eclass exports LUA_SINGLE_USEDEP that is suitable for depending
+# on other packages using the eclass.  Dependencies on packages using
+# lua.eclass should be created via lua_gen_cond_dep() function, using
+# LUA_USEDEP placeholder.
+#
+# Please note that packages support multiple Lua implementations
+# (using lua.eclass) cannot depend on packages not supporting
+# them (using this eclass).
+#
+# Note that since this eclass always inherits lua-utils as well, in ebuilds
+# using the former there is no need to explicitly inherit the latter in order
+# to use helper functions such as lua_get_CFLAGS.
+
+case ${EAPI:-0} in
+	0|1|2|3|4|5|6)
+		die "Unsupported EAPI=${EAPI} (too old) for ${ECLASS}"
+		;;
+	7)
+		;;
+	*)
+		die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}"
+		;;
+esac
+
+if [[ ! ${_LUA_SINGLE_R0} ]]; then
+
+if [[ ${_LUA_R0} ]]; then
+	die 'lua-single.eclass cannot be used with lua.eclass.'
+fi
+
+inherit lua-utils
+
+fi
+
+EXPORT_FUNCTIONS pkg_setup
+
+# @ECLASS-VARIABLE: LUA_COMPAT
+# @REQUIRED
+# @PRE_INHERIT
+# @DESCRIPTION:
+# This variable contains a list of Lua implementations the package
+# supports. It must be set before the `inherit' call. It has to be
+# an array.
+#
+# Example:
+# @CODE
+# LUA_COMPAT=( lua5-1 lua5-2 lua5-3 )
+# @CODE
+#
+# Please note that you can also use bash brace expansion if you like:
+# @CODE
+# LUA_COMPAT=( lua5-{1..3} )
+# @CODE
+
+# @ECLASS-VARIABLE: LUA_COMPAT_OVERRIDE
+# @USER_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# This variable can be used when working with ebuilds to override
+# the in-ebuild LUA_COMPAT. It is a string listing all
+# the implementations which package will be built for. It need be
+# specified in the calling environment, and not in ebuilds.
+#
+# It should be noted that in order to preserve metadata immutability,
+# LUA_COMPAT_OVERRIDE does not affect IUSE nor dependencies.
+# The state of LUA_TARGETS is ignored, and all the implementations
+# in LUA_COMPAT_OVERRIDE are built. Dependencies need to be satisfied
+# manually.
+#
+# Example:
+# @CODE
+# LUA_COMPAT_OVERRIDE='lua5-2' emerge -1v dev-lua/foo
+# @CODE
+
+# @ECLASS-VARIABLE: LUA_REQ_USE
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# The list of USE flags required to be enabled on the chosen Lua
+# implementations, formed as a USE-dependency string. It should be valid
+# for all implementations in LUA_COMPAT, so it may be necessary to
+# use USE defaults.
+# This must be set before calling `inherit'.
+#
+# Example:
+# @CODE
+# LUA_REQ_USE="deprecated"
+# @CODE
+#
+# It will cause the Lua dependencies to look like:
+# @CODE
+# lua_targets_luaX-Y? ( dev-lang/lua:X.Y[deprecated] )
+# @CODE
+
+# @ECLASS-VARIABLE: LUA_DEPS
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# This is an eclass-generated Lua dependency string for all
+# implementations listed in LUA_COMPAT.
+#
+# Example use:
+# @CODE
+# RDEPEND="${LUA_DEPS}
+#   dev-foo/mydep"
+# DEPEND="${RDEPEND}"
+# @CODE
+#
+# Example value:
+# @CODE
+# lua_targets_lua5-1? ( dev-lang/lua:5.1 )
+# lua_targets_lua5-2? ( dev-lang/lua:5.2 )
+# @CODE
+
+# @ECLASS-VARIABLE: LUA_REQUIRED_USE
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# This is an eclass-generated required-use expression which ensures at
+# least one Lua implementation has been enabled.
+#
+# This expression should be utilized in an ebuild by including it in
+# REQUIRED_USE, optionally behind a use flag.
+#
+# Example use:
+# @CODE
+# REQUIRED_USE="lua? ( ${LUA_REQUIRED_USE} )"
+# @CODE
+#
+# Example value:
+# @CODE
+# || ( lua_targets_lua5-1 lua_targets_lua5-2 )
+# @CODE
+
+# @ECLASS-VARIABLE: LUA_SINGLE_USEDEP
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# This is an eclass-generated USE-dependency string which can be used
+# to depend on another lua-single package being built for the same
+# Lua implementations.
+#
+# If you need to depend on a multi-impl (lua.eclass) package, use
+# lua_gen_cond_dep with LUA_USEDEP placeholder instead.
+#
+# Example use:
+# @CODE
+# RDEPEND="dev-lua/foo[${LUA_SINGLE_USEDEP}]"
+# @CODE
+#
+# Example value:
+# @CODE
+# lua_single_target_lua5-1(-)?
+# @CODE
+
+# @ECLASS-VARIABLE: LUA_USEDEP
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# This is an eclass-generated USE-dependency string which can be used to
+# depend on another Lua package being built for the same Lua
+# implementations.
+#
+# Example use:
+# @CODE
+# RDEPEND="dev-lua/foo[${LUA_USEDEP}]"
+# @CODE
+#
+# Example value:
+# @CODE
+# lua_targets_lua5-1(-)?,lua_targets_lua5-2(-)?
+# @CODE
+
+# @FUNCTION: _lua_single_set_globals
+# @INTERNAL
+# @DESCRIPTION:
+# Sets all the global output variables provided by this eclass.
+# This function must be called once, in global scope.
+_lua_single_set_globals() {
+	_lua_set_impls
+
+	local flags=( "${_LUA_SUPPORTED_IMPLS[@]/#/lua_single_target_}" )
+
+	if [[ ${#_LUA_SUPPORTED_IMPLS[@]} -eq 1 ]]; then
+		# if only one implementation is supported, use IUSE defaults
+		# to avoid requesting the user to enable it
+		IUSE="+${flags[0]}"
+	else
+		IUSE="${flags[*]}"
+	fi
+
+	local requse="^^ ( ${flags[*]} )"
+	local single_flags="${flags[@]/%/(-)?}"
+	local single_usedep=${single_flags// /,}
+
+	local deps= i PYTHON_PKG_DEP
+	for i in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		_lua_export "${i}" LUA_PKG_DEP
+		deps+="lua_single_target_${i}? ( ${LUA_PKG_DEP} ) "
+	done
+
+	if [[ ${LUA_DEPS+1} ]]; then
+		if [[ ${LUA_DEPS} != "${deps}" ]]; then
+			eerror "LUA_DEPS have changed between inherits (LUA_REQ_USE?)!"
+			eerror "Before: ${LUA_DEPS}"
+			eerror "Now   : ${deps}"
+			die "LUA_DEPS integrity check failed"
+		fi
+
+		# these two are formality -- they depend on LUA_COMPAT only
+		if [[ ${LUA_REQUIRED_USE} != ${requse} ]]; then
+			eerror "LUA_REQUIRED_USE have changed between inherits!"
+			eerror "Before: ${LUA_REQUIRED_USE}"
+			eerror "Now   : ${requse}"
+			die "LUA_REQUIRED_USE integrity check failed"
+		fi
+
+		if [[ ${LUA_SINGLE_USEDEP} != "${single_usedep}" ]]; then
+			eerror "LUA_SINGLE_USEDEP have changed between inherits!"
+			eerror "Before: ${LUA_SINGLE_USEDEP}"
+			eerror "Now   : ${single_usedep}"
+			die "LUA_SINGLE_USEDEP integrity check failed"
+		fi
+	else
+		LUA_DEPS=${deps}
+		LUA_REQUIRED_USE=${requse}
+		LUA_SINGLE_USEDEP=${single_usedep}
+		LUA_USEDEP='%LUA_USEDEP-NEEDS-TO-BE-USED-IN-LUA_GEN_COND_DEP%'
+		readonly LUA_DEPS LUA_REQUIRED_USE LUA_SINGLE_USEDEP LUA_USEDEP
+	fi
+}
+
+_lua_single_set_globals
+unset -f _lua_single_set_globals
+
+if [[ ! ${_LUA_SINGLE_R0} ]]; then
+
+# @FUNCTION: _lua_gen_usedep
+# @USAGE: [<pattern>...]
+# @INTERNAL
+# @DESCRIPTION:
+# Output a USE dependency string for Lua implementations which
+# are both in LUA_COMPAT and match any of the patterns passed
+# as parameters to the function.
+#
+# The patterns can be fnmatch-style patterns (matched via bash == operator
+# against LUA_COMPAT values). Remember to escape or quote the fnmatch
+# patterns to prevent accidental shell filename expansion.
+#
+# This is an internal function used to implement lua_gen_cond_dep.
+_lua_gen_usedep() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl matches=()
+
+	_lua_verify_patterns "${@}"
+	for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		if _lua_impl_matches "${impl}" "${@}"; then
+			matches+=(
+				"lua_single_target_${impl}(-)?"
+			)
+		fi
+	done
+
+	[[ ${matches[@]} ]] || die "No supported implementations match lua_gen_usedep patterns: ${@}"
+
+	local out=${matches[@]}
+	echo "${out// /,}"
+}
+
+# @FUNCTION: _lua_impl_matches
+# @USAGE: <impl> [<pattern>...]
+# @INTERNAL
+# @DESCRIPTION:
+# Check whether the specified <impl> matches at least one
+# of the patterns following it. Return 0 if it does, 1 otherwise.
+# Matches if no patterns are provided.
+#
+# <impl> can be in LUA_COMPAT or ELUA form. The patterns can be
+# fnmatch-style patterns, e.g. 'lua5*', '..
+_lua_impl_matches() {
+	[[ ${#} -ge 1 ]] || die "${FUNCNAME}: takes at least 1 parameter"
+	[[ ${#} -eq 1 ]] && return 0
+
+	local impl=${1} pattern
+	shift
+
+	for pattern; do
+		# unify value style to allow lax matching
+		if [[ ${impl/./-} == ${pattern/./-} ]]; then
+			return 0
+		fi
+	done
+
+	return 1
+}
+
+# @FUNCTION: _lua_verify_patterns
+# @USAGE: <pattern>...
+# @INTERNAL
+# @DESCRIPTION:
+# Verify whether the patterns passed to the eclass function are correct
+# (i.e. can match any valid implementation).  Dies on wrong pattern.
+_lua_verify_patterns() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl pattern
+	for pattern; do
+		for impl in "${_LUA_ALL_IMPLS[@]}"; do
+			[[ ${impl} == ${pattern/./-} ]] && continue 2
+		done
+
+		die "Invalid implementation pattern: ${pattern}"
+	done
+}
+
+# @FUNCTION: lua_gen_cond_dep
+# @USAGE: <dependency> [<pattern>...]
+# @DESCRIPTION:
+# Output a list of <dependency>-ies made conditional to USE flags
+# of Lua implementations which are both in LUA_COMPAT and match
+# any of the patterns passed as the remaining parameters.
+#
+# The patterns can be fnmatch-style patterns (matched via bash == operator
+# against LUA_COMPAT values). Remember to escape or quote the fnmatch
+# patterns to prevent accidental shell filename expansion.
+#
+# In order to enforce USE constraints on the packages, verbatim
+# '${LUA_SINGLE_USEDEP}' and '${LUA_USEDEP}' (quoted!) may
+# be placed in the dependency specification. It will get expanded within
+# the function into a proper USE dependency string.
+#
+# Example:
+# @CODE
+# LUA_COMPAT=( lua5-{1..3} )
+# RDEPEND="$(lua_gen_cond_dep \
+#   'dev-lua/backported_core_module[${LUA_USEDEP}]' lua5-1 lua5-2 )"
+# @CODE
+#
+# It will cause the variable to look like:
+# @CODE
+# RDEPEND="lua_single_target_lua5-1? (
+#     dev-lua/backported_core_module[lua_targets_lua5-1(-)?,...] )
+#	lua_single_target_lua5-2? (
+#     dev-lua/backported_core_module[lua_targets_lua5-2(-)?,...] )"
+# @CODE
+lua_gen_cond_dep() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl matches=()
+
+	local dep=${1}
+	shift
+
+	_lua_verify_patterns "${@}"
+	for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		if _lua_impl_matches "${impl}" "${@}"; then
+			# substitute ${LUA_SINGLE_USEDEP} if used
+			# (since lua_gen_usedep() will not return
+			#  ${LUA_SINGLE_USEDEP}, the code is run at most once)
+			if [[ ${dep} == *'${LUA_SINGLE_USEDEP}'* ]]; then
+				local usedep=$(_lua_gen_usedep "${@}")
+				dep=${dep//\$\{LUA_SINGLE_USEDEP\}/${usedep}}
+			fi
+			local multi_usedep="lua_targets_${impl}(-)"
+
+			local subdep=${dep//\$\{LUA_MULTI_USEDEP\}/${multi_usedep}}
+			matches+=( "lua_single_target_${impl}? (
+				${subdep//\$\{LUA_USEDEP\}/${multi_usedep}} )" )
+		fi
+	done
+
+	echo "${matches[@]}"
+}
+
+# @FUNCTION: lua_gen_impl_dep
+# @USAGE: [<requested-use-flags> [<impl-pattern>...]]
+# @DESCRIPTION:
+# Output a dependency on Lua implementations with the specified USE
+# dependency string appended, or no USE dependency string if called
+# without the argument (or with empty argument). If any implementation
+# patterns are passed, the output dependencies will be generated only
+# for the implementations matching them.
+#
+# The patterns can be fnmatch-style patterns (matched via bash == operator
+# against LUA_COMPAT values). Remember to escape or quote the fnmatch
+# patterns to prevent accidental shell filename expansion.
+#
+# Use this function when you need to request different USE flags
+# on the Lua interpreter depending on package's USE flags. If you
+# only need a single set of interpreter USE flags, just set
+# LUA_REQ_USE and use ${LUA_DEPS} globally.
+#
+# Example:
+# @CODE
+# LUA_COMPAT=( lua5-{1..3} )
+# RDEPEND="foo? ( $(lua_gen_impl_dep 'deprecated(+)' lua5-3 ) )"
+# @CODE
+#
+# It will cause the variable to look like:
+# @CODE
+# RDEPEND="foo? (
+#	lua_single_target_lua5-3? ( dev-lang/lua:5.3[deprecated(+)] )
+# )"
+# @CODE
+lua_gen_impl_dep() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl
+	local matches=()
+
+	local LUA_REQ_USE=${1}
+	shift
+
+	_lua_verify_patterns "${@}"
+	for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		if _lua_impl_matches "${impl}" "${@}"; then
+			local LUA_PKG_DEP
+			_lua_export "${impl}" LUA_PKG_DEP
+			matches+=( "lua_single_target_${impl}? ( ${LUA_PKG_DEP} )" )
+		fi
+	done
+
+	echo "${matches[@]}"
+}
+
+# @FUNCTION: lua_setup
+# @DESCRIPTION:
+# Determine what the selected Lua implementation is and set
+# the Lua build environment up for it.
+lua_setup() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	unset ELUA
+
+	# support developer override
+	if [[ ${LUA_COMPAT_OVERRIDE} ]]; then
+		local impls=( ${LUA_COMPAT_OVERRIDE} )
+		[[ ${#impls[@]} -eq 1 ]] || die "LUA_COMPAT_OVERRIDE must name exactly one implementation for lua-single"
+
+		ewarn "WARNING: LUA_COMPAT_OVERRIDE in effect. The following Lua"
+		ewarn "implementation will be used:"
+		ewarn
+		ewarn "	${LUA_COMPAT_OVERRIDE}"
+		ewarn
+		ewarn "Dependencies won't be satisfied, and LUA_SINGLE_TARGET flags will be ignored."
+
+		_lua_export "${impls[0]}" ELUA LUA
+		_lua_wrapper_setup
+		einfo "Using ${ELUA} to build"
+		return
+	fi
+
+	local impl
+	for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		if use "lua_single_target_${impl}"; then
+			if [[ ${ELUA} ]]; then
+				eerror "Your LUA_SINGLE_TARGET setting lists more than a single Lua"
+				eerror "implementation. Please set it to just one value. If you need"
+				eerror "to override the value for a single package, please use package.env"
+				eerror "or an equivalent solution (man 5 portage)."
+				echo
+				die "More than one implementation in LUA_SINGLE_TARGET."
+			fi
+
+			_lua_export "${impl}" ELUA LUA
+			_lua_wrapper_setup
+			einfo "Using ${ELUA} to build"
+		fi
+	done
+
+	if [[ ! ${ELUA} ]]; then
+		eerror "No Lua implementation selected for the build. Please set"
+		eerror "the LUA_SINGLE_TARGET variable in your make.conf to one"
+		eerror "of the following values:"
+		eerror
+		eerror "${_LUA_SUPPORTED_IMPLS[@]}"
+		echo
+		die "No supported Lua implementation in LUA_SINGLE_TARGET."
+	fi
+}
+
+# @FUNCTION: lua-single_pkg_setup
+# @DESCRIPTION:
+# Runs lua_setup.
+lua-single_pkg_setup() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	[[ ${MERGE_TYPE} != binary ]] && lua_setup
+}
+
+_LUA_SINGLE_R0=1
+fi
-- 
2.26.2



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

* Re: [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds
  2020-09-30 16:23 [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds Marek Szuba
                   ` (3 preceding siblings ...)
  2020-09-30 16:23 ` [gentoo-dev] [PATCH 4/4] lua-single.eclass: new eclass for single-implementation Lua ebuilds Marek Szuba
@ 2020-10-01 18:31 ` Daniel Pielmeier
  2020-10-01 20:24   ` Marek Szuba
  4 siblings, 1 reply; 8+ messages in thread
From: Daniel Pielmeier @ 2020-10-01 18:31 UTC (permalink / raw
  To: gentoo-dev

Marek Szuba schrieb am 30.09.20 um 18:23:
> Same as lua.eclass and python-r1, this is a Lua version of
> python-single-r1. Setting LUA_SINGLE_TARGETS allows one to choose the
> (slotted) Lua implementation to build your ebuild against, optionally
> including both single- and multi-implementation Lua packages as
> dependencies.
> 

Hello Marek!

First of all thank you very much for your work on the eclasses
supporting slotted lua. It is very much appreciated.

As I am not really capable of doing a review I took your eclasses and
tried to use it for app-admin/conky (using lua-single) where new
versions already need at least lua-5.2. See the changes below.

I already had slotted lua 5.1 and 5.3 installed and the modified ebuild
built fine with lua-5.3 as before. However when I tried setting
LUA_SINGLE_TARGET="lua5-2", lua-5.2 was pulled in as a dependency but
conky still built against lua-5.3. The temporary pkg-config environment
was set correct but somehow it seems not used. Conky uses cmake and
pkg_search_module [1] to detect lua preferring 5.3 over 5.2.

Am I doing something wrong using the eclass or is there an issue with
the lua detection in conky or maybe the the eclass?

[1]
https://github.com/brndnmtthws/conky/blob/master/cmake/ConkyPlatformChecks.cmake

--- conky-1.11.6.ebuild	2020-09-21 12:32:10.180949870 +0200
+++ conky-1.11.6-r1.ebuild	2020-10-01 00:04:13.099147223 +0200
@@ -3,7 +3,9 @@

 EAPI=7

-inherit cmake linux-info readme.gentoo-r1 xdg
+LUA_COMPAT=( lua5-{2..3} )
+
+inherit cmake linux-info lua-single readme.gentoo-r1 xdg

 DESCRIPTION="An advanced, highly configurable system monitor for X"
 HOMEPAGE="https://github.com/brndnmtthws/conky"
@@ -45,7 +47,7 @@
 	weather-metar? ( net-misc/curl )
 	webserver? ( net-libs/libmicrohttpd )
 	xmms2? ( media-sound/xmms2 )
-	|| ( dev-lang/lua:5.3 dev-lang/lua:5.2 )
+	${LUA_DEPS}
 "
 RDEPEND="
 	${COMMON_DEPEND}
@@ -85,6 +87,8 @@

 pkg_setup() {
 	use ipv6 && linux-info_pkg_setup
+
+	lua-single_pkg_setup
 }

 src_prepare() {

-- 
-- 
Daniel Pielmeier


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

* Re: [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds
  2020-10-01 18:31 ` [gentoo-dev] [PATCH 0/4] Eclass for single-impl " Daniel Pielmeier
@ 2020-10-01 20:24   ` Marek Szuba
  2020-10-01 20:49     ` Daniel Pielmeier
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Szuba @ 2020-10-01 20:24 UTC (permalink / raw
  To: gentoo-dev

On 2020-10-01 20:31, Daniel Pielmeier wrote:

> I already had slotted lua 5.1 and 5.3 installed and the modified ebuild
> built fine with lua-5.3 as before. However when I tried setting
> LUA_SINGLE_TARGET="lua5-2", lua-5.2 was pulled in as a dependency but
> conky still built against lua-5.3. The temporary pkg-config environment
> was set correct but somehow it seems not used. Conky uses cmake and
> pkg_search_module [1] to detect lua preferring 5.3 over 5.2.
> 
> Am I doing something wrong using the eclass or is there an issue with
> the lua detection in conky or maybe the the eclass?

I noticed the same thing while adapting x11-wm/awesome, it's caused by
how the CMake module FindLua works. You will have to make sure that
cmake looks for a specific version.

-- 
MS


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

* Re: [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds
  2020-10-01 20:24   ` Marek Szuba
@ 2020-10-01 20:49     ` Daniel Pielmeier
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Pielmeier @ 2020-10-01 20:49 UTC (permalink / raw
  To: gentoo-dev

Marek Szuba schrieb am 01.10.20 um 22:24:
> On 2020-10-01 20:31, Daniel Pielmeier wrote:
> 
>> I already had slotted lua 5.1 and 5.3 installed and the modified ebuild
>> built fine with lua-5.3 as before. However when I tried setting
>> LUA_SINGLE_TARGET="lua5-2", lua-5.2 was pulled in as a dependency but
>> conky still built against lua-5.3. The temporary pkg-config environment
>> was set correct but somehow it seems not used. Conky uses cmake and
>> pkg_search_module [1] to detect lua preferring 5.3 over 5.2.
>>
>> Am I doing something wrong using the eclass or is there an issue with
>> the lua detection in conky or maybe the the eclass?
> 
> I noticed the same thing while adapting x11-wm/awesome, it's caused by
> how the CMake module FindLua works. You will have to make sure that
> cmake looks for a specific version.
> 

Thanks Marek!

Probably the easiest solution is to pin it to 5.3 then.

-- 
Best Regards
Daniel


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

end of thread, other threads:[~2020-10-01 20:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-30 16:23 [gentoo-dev] [PATCH 0/4] Eclass for single-impl Lua ebuilds Marek Szuba
2020-09-30 16:23 ` [gentoo-dev] [PATCH 1/4] lua.eclass: split some stuff out as lua-utils.eclass Marek Szuba
2020-09-30 16:23 ` [gentoo-dev] [PATCH 2/4] lua.eclass: die if lua-single.eclass has already been loaded Marek Szuba
2020-09-30 16:23 ` [gentoo-dev] [PATCH 3/4] profiles/desc: describe LUA_SINGLE_TARGET Marek Szuba
2020-09-30 16:23 ` [gentoo-dev] [PATCH 4/4] lua-single.eclass: new eclass for single-implementation Lua ebuilds Marek Szuba
2020-10-01 18:31 ` [gentoo-dev] [PATCH 0/4] Eclass for single-impl " Daniel Pielmeier
2020-10-01 20:24   ` Marek Szuba
2020-10-01 20:49     ` Daniel Pielmeier

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