public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] lua.eclass: initial implementation
@ 2020-09-03 13:37 Marek Szuba
  2020-09-03 13:37 ` [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass Marek Szuba
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Marek Szuba @ 2020-09-03 13:37 UTC (permalink / raw
  To: gentoo-dev

Ladies and gentlemen,

Here is my first attempt on creating an eclass which would handle
installation of Lua modules for multiple implementations. As some of you
are aware of, the lack of such an eclass has been a major issue for our
efforts on slotting dev-lang/lua.

With many, many thanks to mgorny and everyone else who has worked on
python-r1.eclass, to whom lua.eclass bears, ahem, striking resemblance.

At the moment this is only really useful for installing Lua modules but
assuming it doesn't turn out to be a total failure, I'll work on
single-target support as the next step. We should probably think about
adding LuaJIT support at some point too.

Comments are very much welcome!




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

* [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass
  2020-09-03 13:37 [gentoo-dev] [PATCH] lua.eclass: initial implementation Marek Szuba
@ 2020-09-03 13:37 ` Marek Szuba
  2020-09-04  8:38   ` Marek Szuba
  2020-09-06 17:13   ` Azamat Hackimov
  2020-09-03 13:37 ` [gentoo-dev] [PATCH 2/2] profiles/desc: describe LUA_TARGETS Marek Szuba
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 10+ messages in thread
From: Marek Szuba @ 2020-09-03 13:37 UTC (permalink / raw
  To: gentoo-dev

This eclass should be to Lua what python-r1 is to Python. Indeed, most
of the plumbing has been shamelessly stolen from that eclass.

What works:
 - support for slotted dev-lang/lua
 - building and installing Lua modules, for multiple Lua implementations
 - dependencies on other Lua modules

What doesn't work yet:
 - support for dev-lang/luajit (not in the least because the versions
   currently in the tree share module directories with dev-lang/lua)
 - proper support for building against a single Lua target

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

diff --git a/eclass/lua.eclass b/eclass/lua.eclass
new file mode 100644
index 00000000000..1b104b31cda
--- /dev/null
+++ b/eclass/lua.eclass
@@ -0,0 +1,710 @@
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: lua.eclass
+# @MAINTAINER:
+# 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: A common eclass for Lua packages
+# @DESCRIPTION:
+# A common eclass providing helper functions to build and install
+# packages supporting being installed for multiple Lua implementations.
+#
+# This eclass sets correct IUSE. Modification of REQUIRED_USE has to
+# be done by the author of the ebuild (but LUA_REQUIRED_USE is
+# provided for convenience, see below). The eclass exports LUA_DEPS
+# and LUA_USEDEP so you can create correct dependencies for your
+# 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.
+#
+# @EXAMPLE:
+# @CODE
+# EAPI=7
+#
+# LUA_COMPAT=( lua5-{1..3} )
+#
+# inherit lua
+#
+# [...]
+#
+# REQUIRED_USE="${LUA_REQUIRED_USE}"
+# DEPEND="${LUA_DEPS}"
+# RDEPEND="${DEPEND}
+#	dev-lua/foo[${LUA_USEDEP}]"
+# BDEPEND="virtual/pkgconfig"
+#
+# lua_src_install() {
+#	emake LUA_VERSION="$(lua_get_version)" install
+# }
+#
+# src_install() {
+#	lua_foreach_impl lua_src_install
+# }
+# @CODE
+
+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_R0} ]]; then
+
+inherit multibuild toolchain-funcs
+
+BDEPEND="virtual/pkgconfig"
+
+fi
+
+# @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: BUILD_DIR
+# @OUTPUT_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# The current build directory. In global scope, it is supposed to
+# contain an initial build directory; if unset, it defaults to ${S}.
+#
+# In functions run by lua_foreach_impl(), the BUILD_DIR is locally
+# set to an implementation-specific build directory. That path is
+# created through appending a hyphen and the implementation name
+# to the final component of the initial BUILD_DIR.
+#
+# Example value:
+# @CODE
+# ${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:
+# 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_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
+
+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:
+# Enforce the proper setting of LUA_TARGETS, if LUA_COMPAT_OVERRIDE
+# is not in effect. If it is, just warn that the flags will be ignored.
+_lua_validate_useflags() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	if [[ ${LUA_COMPAT_OVERRIDE} ]]; then
+		if [[ ! ${_LUA_COMPAT_OVERRIDE_WARNED} ]]; then
+			ewarn "WARNING: LUA_COMPAT_OVERRIDE in effect. The following Lua"
+			ewarn "implementations will be enabled:"
+			ewarn
+			ewarn "	${LUA_COMPAT_OVERRIDE}"
+			ewarn
+			ewarn "Dependencies won't be satisfied, and LUA_TARGETS will be ignored."
+			_LUA_COMPAT_OVERRIDE_WARNED=1
+		fi
+		# we do not use flags with LCO
+		return
+	fi
+
+	local i
+
+	for i in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		use "lua_targets_${i}" && return 0
+	done
+
+	eerror "No Lua implementation selected for the build. Please add one"
+	eerror "of the following values to your LUA_TARGETS (in make.conf):"
+	eerror
+	eerror "${LUA_COMPAT[@]}"
+	echo
+	die "No supported Lua implementation in LUA_TARGETS."
+}
+
+# @FUNCTION: _lua_obtain_impls
+# @INTERNAL
+# @DESCRIPTION:
+# Set up the enabled implementation list.
+_lua_obtain_impls() {
+	_lua_validate_useflags
+
+	if [[ ${LUA_COMPAT_OVERRIDE} ]]; then
+		MULTIBUILD_VARIANTS=( ${LUA_COMPAT_OVERRIDE} )
+		return
+	fi
+
+	MULTIBUILD_VARIANTS=()
+
+	local impl
+	for impl in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		has "${impl}" "${LUA_COMPAT[@]}" && \
+		use "lua_targets_${impl}" && MULTIBUILD_VARIANTS+=( "${impl}" )
+	done
+}
+
+
+# @FUNCTION: _lua_multibuild_wrapper
+# @USAGE: <command> [<args>...]
+# @INTERNAL
+# @DESCRIPTION:
+# Initialize the environment for the Lua implementation selected
+# for multibuild.
+_lua_multibuild_wrapper() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local -x ELUA LUA
+	_lua_export "${MULTIBUILD_VARIANT}" ELUA LUA
+	local -x PATH=${PATH} PKG_CONFIG_PATH=${PKG_CONFIG_PATH}
+	_lua_wrapper_setup
+
+	"${@}"
+}
+
+# @FUNCTION: _lua_wrapper_setup
+# @USAGE: [<path> [<impl>]]
+# @INTERNAL
+# @DESCRIPTION:
+# Create proper 'lua' executable 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
+# implementation.
+#
+# The sources are always copied from initial BUILD_DIR (or S if unset)
+# to implementation-specific build directory matching BUILD_DIR used by
+# lua_foreach_abi().
+lua_copy_sources() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local MULTIBUILD_VARIANTS
+	_lua_obtain_impls
+
+	multibuild_copy_sources
+}
+
+# @FUNCTION: lua_foreach_impl
+# @USAGE: <command> [<args>...]
+# @DESCRIPTION:
+# Run the given command for each of the enabled Lua implementations.
+# If additional parameters are passed, they will be passed through
+# to the command.
+#
+# The function will return 0 status if all invocations succeed.
+# Otherwise, the return code from first failing invocation will
+# be returned.
+#
+# For each command being run, ELUA, LUA and BUILD_DIR are set
+# locally, and the former two are exported to the command environment.
+lua_foreach_impl() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local MULTIBUILD_VARIANTS
+	_lua_obtain_impls
+
+	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 - 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:
+# Sets all the global output variables provided by this eclass.
+# This function must be called once, in global scope.
+_lua_set_globals() {
+	local deps i LUA_PKG_DEP
+
+	_lua_set_impls
+
+	for i in "${_LUA_SUPPORTED_IMPLS[@]}"; do
+		_lua_export "${i}" LUA_PKG_DEP
+		deps+="lua_targets_${i}? ( ${LUA_PKG_DEP} ) "
+	done
+
+	local flags=( "${_LUA_SUPPORTED_IMPLS[@]/#/lua_targets_}" )
+	local optflags=${flags[@]/%/(-)?}
+
+	local requse="|| ( ${flags[*]} )"
+	local usedep=${optflags// /,}
+
+	if [[ ${LUA_DEPS+1} ]]; then
+		# IUSE is magical, so we can't really check it
+		# (but we verify LUA_COMPAT already)
+
+		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_USEDEP} != "${usedep}" ]]; then
+			eerror "LUA_USEDEP have changed between inherits!"
+			eerror "Before: ${LUA_USEDEP}"
+			eerror "Now   : ${usedep}"
+			die "LUA_USEDEP integrity check failed"
+		fi
+	else
+		IUSE=${flags[*]}
+
+		LUA_DEPS=${deps}
+		LUA_REQUIRED_USE=${requse}
+		LUA_USEDEP=${usedep}
+		readonly LUA_DEPS LUA_REQUIRED_USE
+	fi
+}
+
+_lua_set_globals
+unset -f _lua_set_globals _lua_set_impls
-- 
2.26.2



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

* [gentoo-dev] [PATCH 2/2] profiles/desc: describe LUA_TARGETS
  2020-09-03 13:37 [gentoo-dev] [PATCH] lua.eclass: initial implementation Marek Szuba
  2020-09-03 13:37 ` [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass Marek Szuba
@ 2020-09-03 13:37 ` Marek Szuba
       [not found] ` <c0cdb2ea-8932-72ca-1561-5dcb3df2880e@veremit.xyz>
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Marek Szuba @ 2020-09-03 13:37 UTC (permalink / raw
  To: gentoo-dev

Already includes lua-5.4.

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

diff --git a/profiles/desc/lua_targets.desc b/profiles/desc/lua_targets.desc
new file mode 100644
index 00000000000..2575de0bcfd
--- /dev/null
+++ b/profiles/desc/lua_targets.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_TARGETS USE_EXPAND flags.
+
+lua5-1 - Build with Lua 5.1
+lua5-2 - Build with Lua 5.2
+lua5-3 - Build with Lua 5.3
+lua5-4 - Build with Lua 5.4
-- 
2.26.2



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

* Re: [gentoo-dev] [PATCH] lua.eclass: initial implementation
       [not found] ` <c0cdb2ea-8932-72ca-1561-5dcb3df2880e@veremit.xyz>
@ 2020-09-03 18:24   ` Kent Fredric
  0 siblings, 0 replies; 10+ messages in thread
From: Kent Fredric @ 2020-09-03 18:24 UTC (permalink / raw
  To: Michael 'veremitz' Everitt; +Cc: gentoo-dev, Marek Szuba, graaff

[-- Attachment #1: Type: text/plain, Size: 1232 bytes --]

On Thu, 3 Sep 2020 14:49:25 +0100
Michael 'veremitz' Everitt <gentoo@veremit.xyz> wrote:

> I know this is a much more onerous "solution" but I thought I would throw
> it out there, and see if any other interested parties (eg. kent\n and
> potentially graaff) may be able to share their thoughts..

Actually, the more I think about it, there are 2 major reasons not to do this:

1. Its a premature abstraction that centralises a point of failure, and
so any defects in this POF scale to all places, producing even more
places where changing one eclass requires regenerating the md5 cache
for the whole tree, and makes it *harder* to specify logic that only
occurs in one languages ecosystem.

2. What happens if two eclasses inherit this shared eclass, and
declares "which variables do I look into" via other variables that
define its API?, and then, one ebuild consumes *both*.

Presently, inheriting two eclasses, one for python, one for lua, and
taping together how they build inside the ebuild itself seems viable.

But if the logic is shoehorned into a common eclass, that will likely
go really fucking pear shaped, unless done with a very fucked
up/complicated API.

I don't think this is worth it.

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass
  2020-09-03 13:37 ` [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass Marek Szuba
@ 2020-09-04  8:38   ` Marek Szuba
  2020-09-06 17:13   ` Azamat Hackimov
  1 sibling, 0 replies; 10+ messages in thread
From: Marek Szuba @ 2020-09-04  8:38 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 1535 bytes --]

On 2020-09-03 15:37, Marek Szuba wrote:

For the record, some mostly-cosmetic issues that have already been
identified. Will include them in the next revision:

> +if [[ ! ${_LUA_R0} ]]; then
> +
> +inherit multibuild toolchain-funcs
> +
> +BDEPEND="virtual/pkgconfig"

There should be no BDEPEND in the eclass any more, it's a leftover from
an earlier iteration which retrieved module directories in less
conditional fashion.

> +# Please note that you can also use bash brace expansion if you like:
> +# @CODE
> +# LUA_COMPAT=( lua5_{1..3} )

s/_/-/

> +	eerror "No Lua implementation selected for the build. Please add one"
> +	eerror "of the following values to your LUA_TARGETS (in make.conf):"

Will add "or package.use" here.

> +# @FUNCTION: _lua_wrapper_setup
> +# @USAGE: [<path> [<impl>]]
> +# @INTERNAL
> +# @DESCRIPTION:
> +# Create proper 'lua' executable and pkg-config wrappers

Should be "proper Lua executables" - for dev-lang/lua we have got both
'lua' and 'luac', and for dev-lang/luajit we'll probably have 'luajit'
(have yet to see if invoking 'luajit' as 'lua' works).

> +# 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 - dead implementations),

Just say "minus" here, as it stands it is a bit confusing (at least to
me) because my first reaction is to read the - as a dash, not as an
arithmetic minus.

-- 
MS


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH] lua.eclass: initial implementation
  2020-09-03 13:37 [gentoo-dev] [PATCH] lua.eclass: initial implementation Marek Szuba
                   ` (2 preceding siblings ...)
       [not found] ` <c0cdb2ea-8932-72ca-1561-5dcb3df2880e@veremit.xyz>
@ 2020-09-06 15:46 ` David Seifert
  2020-09-07 14:27   ` Marek Szuba
  2020-09-08 14:32 ` Marek Szuba
  4 siblings, 1 reply; 10+ messages in thread
From: David Seifert @ 2020-09-06 15:46 UTC (permalink / raw
  To: gentoo-dev

On Thu, 2020-09-03 at 15:37 +0200, Marek Szuba wrote:
> Ladies and gentlemen,
> 
> Here is my first attempt on creating an eclass which would handle
> installation of Lua modules for multiple implementations. As some of
> you
> are aware of, the lack of such an eclass has been a major issue for
> our
> efforts on slotting dev-lang/lua.
> 
> With many, many thanks to mgorny and everyone else who has worked on
> python-r1.eclass, to whom lua.eclass bears, ahem, striking
> resemblance.
> 
> At the moment this is only really useful for installing Lua modules
> but
> assuming it doesn't turn out to be a total failure, I'll work on
> single-target support as the next step. We should probably think about
> adding LuaJIT support at some point too.
> 
> Comments are very much welcome!

This is finally going in the right direction. Unfortunately we won't get
around a single-r1-style eclass too. What about all those programs
embedding a specific lua version as plugin architecture? Conversely, we
also won't get around the multi eclass too, given how many upstreams
won't unbundle/port their lua dependencies and require access to pure-
lua packages. But the basic principles underlying your eclass are
finally correct, unlike the previous lua.eclass attempt.



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

* Re: [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass
  2020-09-03 13:37 ` [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass Marek Szuba
  2020-09-04  8:38   ` Marek Szuba
@ 2020-09-06 17:13   ` Azamat Hackimov
  1 sibling, 0 replies; 10+ messages in thread
From: Azamat Hackimov @ 2020-09-06 17:13 UTC (permalink / raw
  To: gentoo-dev

Hello!

Some notes from me.

чт, 3 сент. 2020 г. в 16:37, Marek Szuba <marecki@gentoo.org>:

> +# @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

I think there also needs a LUAC variable that points to the current
Lua compiler.

> +# @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}"
> +}

There needs a LUA_MAJOR_VERSION (V variable in lua.pc, i.e. 5.1, 5.2,
5.3) instead of full version (R variable in lua.pc, i.e 5.1.5, 5.2.4).
Some obscure Lua packages are required to define V variable to work
properly.


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

* Re: [gentoo-dev] [PATCH] lua.eclass: initial implementation
  2020-09-06 15:46 ` David Seifert
@ 2020-09-07 14:27   ` Marek Szuba
  0 siblings, 0 replies; 10+ messages in thread
From: Marek Szuba @ 2020-09-07 14:27 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 1984 bytes --]

On 2020-09-06 17:46, David Seifert wrote:

> Unfortunately we won't get around a single-r1-style eclass too. What
> about all those programs embedding a specific lua version as plugin
> architecture?

This is still very much on my to-do list, I simply figured it would make
it easier for everyone reviewing this to leave it until the next iteration.

> But the basic principles underlying your eclass
> are finally correct, unlike the previous lua.eclass attempt.

Thank you! Of course it would have been much more difficult to achieve
were it not for Michał's work on python-r1.


On 2020-09-06 19:13, Azamat Hackimov wrote:

>> +# @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
>
> I think there also needs a LUAC variable that points to the current
> Lua compiler.

Possibly, then again I have begun to wonder if we even need LUA
itself... Moreover, there would be no LUAC were the eclass made to
support luajit.

I guess we'll see how many ebuilds actually need these once we have
begun porting them to lua.eclass.

> There needs a LUA_MAJOR_VERSION (V variable in lua.pc, i.e. 5.1, 5.2,
> 5.3) instead of full version (R variable in lua.pc, i.e 5.1.5, 5.2.4).
> Some obscure Lua packages are required to define V variable to work
> properly.

Nah, one can easily go from the full version to the ABI version
(<nitpick>LUA_MAJOR_VERSION would just be 5</nitpick) in an ebuild by
either removing the "lua" prefix from ELUA or using ver_cut on the
output of $(lua_get_version). I would rather have the eclass output more
information that the user can partly discard, than output less
information and run into problems with that one braindead package which
insists of being passed the full Lua version.

-- 
MS


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH] lua.eclass: initial implementation
  2020-09-03 13:37 [gentoo-dev] [PATCH] lua.eclass: initial implementation Marek Szuba
                   ` (3 preceding siblings ...)
  2020-09-06 15:46 ` David Seifert
@ 2020-09-08 14:32 ` Marek Szuba
  2020-09-08 15:04   ` Azamat Hackimov
  4 siblings, 1 reply; 10+ messages in thread
From: Marek Szuba @ 2020-09-08 14:32 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 103 bytes --]

Merged, thank you everyone who has weighed in with their comments both
on IRC and here.

-- 
MS


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [gentoo-dev] [PATCH] lua.eclass: initial implementation
  2020-09-08 14:32 ` Marek Szuba
@ 2020-09-08 15:04   ` Azamat Hackimov
  0 siblings, 0 replies; 10+ messages in thread
From: Azamat Hackimov @ 2020-09-08 15:04 UTC (permalink / raw
  To: gentoo-dev

Marek,

Is there any plans how to begin migrating lua packages to new eclass?
As I can see, the current stable dev-lang/lua:0 package is not suited
for it, while other slotted packages have major flaws about *.pc
handling.

вт, 8 сент. 2020 г. в 17:32, Marek Szuba <marecki@gentoo.org>:
>
> Merged, thank you everyone who has weighed in with their comments both
> on IRC and here.
>
> --
> MS
>


-- 
From Siberia with Love!


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

end of thread, other threads:[~2020-09-08 15:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-03 13:37 [gentoo-dev] [PATCH] lua.eclass: initial implementation Marek Szuba
2020-09-03 13:37 ` [gentoo-dev] [PATCH 1/2] eclass: Add first version of lua.eclass Marek Szuba
2020-09-04  8:38   ` Marek Szuba
2020-09-06 17:13   ` Azamat Hackimov
2020-09-03 13:37 ` [gentoo-dev] [PATCH 2/2] profiles/desc: describe LUA_TARGETS Marek Szuba
     [not found] ` <c0cdb2ea-8932-72ca-1561-5dcb3df2880e@veremit.xyz>
2020-09-03 18:24   ` [gentoo-dev] [PATCH] lua.eclass: initial implementation Kent Fredric
2020-09-06 15:46 ` David Seifert
2020-09-07 14:27   ` Marek Szuba
2020-09-08 14:32 ` Marek Szuba
2020-09-08 15:04   ` Azamat Hackimov

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