public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Horodniceanu Andrei" <a.horodniceanu@proton.me>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] repo/user/dlang:master commit in: eclass/
Date: Sat, 13 Apr 2024 23:04:28 +0000 (UTC)	[thread overview]
Message-ID: <1713048445.88e2ca3511032435742bd8d7d1c01d8a29588ba3.a.horodniceanu@gentoo> (raw)

commit:     88e2ca3511032435742bd8d7d1c01d8a29588ba3
Author:     Andrei Horodniceanu <a.horodniceanu <AT> proton <DOT> me>
AuthorDate: Sat Mar  2 14:27:21 2024 +0000
Commit:     Horodniceanu Andrei <a.horodniceanu <AT> proton <DOT> me>
CommitDate: Sat Apr 13 22:47:25 2024 +0000
URL:        https://gitweb.gentoo.org/repo/user/dlang.git/commit/?id=88e2ca35

dlang-compilers-r1.eclass: new eclass

Signed-off-by: Andrei Horodniceanu <a.horodniceanu <AT> proton.me>

 eclass/dlang-compilers-r1.eclass | 293 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 293 insertions(+)

diff --git a/eclass/dlang-compilers-r1.eclass b/eclass/dlang-compilers-r1.eclass
new file mode 100644
index 0000000..933b05a
--- /dev/null
+++ b/eclass/dlang-compilers-r1.eclass
@@ -0,0 +1,293 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dlang-compilers-r1.eclass
+# @MAINTAINER:
+# Andrei Horodniceanu <a.horodniceanu@proton.me>
+# @AUTHOR:
+# Andrei Horodniceanu <a.horodniceanu@proton.me>
+# Based on dlang-compilers.eclass by Marco Leise <marco.leise@gmx.de>.
+# @BUGREPORTS:
+# Please report bugs via https://github.com/gentoo/dlang/issues
+# @VCSURL: https://github.com/gentoo/dlang
+# @BLURB: Support data for dlang-utils.eclass
+# @DESCRIPTION:
+# Contains the available D compiler versions with their stable
+# architectures and the language version they support.
+
+if [[ ! ${_DLANG_COMPILERS_R1_ECLASS} ]] ; then
+_DLANG_COMPILERS_R1_ECLASS=1
+
+# @ECLASS_VARIABLE: _DLANG_DMD_FRONTENDS
+# @INTERNAL
+# @DESCRIPTION:
+# A list of dmd implementations with their dlang frontend version (which
+# happens to coincide with the implementation version) and the
+# architectures they support as a list of keywords. Only stable and
+# unstable keywords will appear.
+#
+# The elements are ordered, the higher implementation version has the
+# higher index.
+#
+# Example value for an element:
+# @CODE
+# "2.102 2.102 ~amd64 x86"
+# @CODE
+# Where the first 2.102 represents the implementation version,
+# the second one represents the D language version the implementation
+# supports and, lastly, there are two keywords.
+readonly _DLANG_DMD_FRONTENDS=(
+	"2.101 2.101 ~amd64 ~x86"
+	"2.102 2.102 ~amd64 ~x86"
+	"2.103 2.103 ~amd64 ~x86"
+	"2.104 2.104 ~amd64 ~x86"
+	"2.105 2.105 ~amd64 ~x86"
+	"2.106 2.106 ~amd64 ~x86"
+	"2.107 2.107 ~amd64 ~x86"
+)
+
+# @ECLASS_VARIABLE: _DLANG_GDC_FRONTENDS
+# @INTERNAL
+# @DESCRIPTION:
+# A list of gdc implementations with their dlang frontend version and
+# the architectures they support as a list of keywords. Only stable and
+# unstable keywords will appear.
+#
+# The elements are ordered, the higher implementation version has the
+# higher index.
+#
+# Example value for an element:
+# @CODE
+# "13 2.103 amd64 ~arm64 x86"
+# @CODE
+# Where 13 represents the implementation version, 2.103 represents the D
+# language version the implementation supports and, lastly, there are
+# three keywords.
+readonly _DLANG_GDC_FRONTENDS=(
+	"12 2.100 ~amd64 ~arm64 ~x86"
+	"13 2.103 ~amd64 ~arm64 ~x86"
+)
+
+# @ECLASS_VARIABLE: _DLANG_LDC2_FRONTENDS
+# @INTERNAL
+# @DESCRIPTION:
+# A list of ldc2 implementations with their dlang frontend version and
+# the architectures they support as a list of keywords. Only stable and
+# unstable keywords will appear.
+#
+# The elements are ordered, the higher implementation version has the
+# higher index.
+#
+# Example value for an element:
+# @CODE
+# 1.34 2.104 ~amd64 ~arm64
+# @CODE
+# Where 1.34 represents the implementation version, 2.104 represents the
+# D language version the implementation supports and, lastly, there are
+# two keywords.
+readonly _DLANG_LDC2_FRONTENDS=(
+	"1.32 2.102 ~amd64 ~arm64 ~x86"
+	"1.33 2.103 ~amd64 ~arm64 ~x86"
+	"1.34 2.104 ~amd64 ~arm64 ~x86"
+	"1.35 2.105 ~amd64 ~arm64 ~x86"
+	"1.36 2.106 ~amd64 ~arm64 ~x86"
+)
+
+# @FUNCTION: _dlang_accumulate_implementations
+# @INTERNAL
+# @DESCRIPTION:
+# Set the global variable _DLANG_ALL_IMPLS based on the three arrays:
+# _DLANG_(DMD|LDC2|GDC)_FRONTENDS. This function should be called once,
+# in global scope.
+_dlang_accumulate_implementations() {
+	local line result=()
+	for line in "${_DLANG_DMD_FRONTENDS[@]/#/dmd-}" \
+				"${_DLANG_GDC_FRONTENDS[@]/#/gdc-}" \
+				"${_DLANG_LDC2_FRONTENDS[@]/#/ldc2-}"
+	do
+		line=( ${line} )
+		# We only need the first component (name + version)
+		local impl=${line[0]/\./_}
+		result+=( "${impl}" )
+	done
+
+	if [[ ${_DLANG_ALL_IMPLS+1} ]]; then
+		if [[ ${_DLANG_ALL_IMPLS[@]} != ${result[@]} ]]; then
+			eerror "_DLANG_ALL_IMPLS has changed between inherits!"
+			eerror "Before: ${_DLANG_ALL_IMPLS[*]}"
+			eerror "Now   : ${result[*]}"
+			die "_DLANG_ALL_IMPLS integrity check failed!"
+		fi
+	else
+		_DLANG_ALL_IMPLS=( "${result[@]}" )
+		readonly _DLANG_ALL_IMPLS
+	fi
+}
+_dlang_accumulate_implementations
+unset -f _dlang_accumulate_implementations
+
+# @ECLASS_VARIABLE: _DLANG_ALL_IMPLS
+# @INTERNAL
+# @DESCRIPTION:
+# All supported Dlang implementations, most preferred last.
+
+# @ECLASS_VARIABLE: _DLANG_HISTORICAL_IMPLS
+# @INTERNAL
+# @DESCRIPTION:
+# All historical Dlang implementations that are no longer supported.
+readonly _DLANG_HISTORICAL_IMPLS=(
+	gdc-11
+)
+
+# @FUNCTION: dlang_compilers_stabs_required_use
+# @USAGE: <use_expand_name> [<impls>...]
+# @DESCRIPTION:
+# Generate a required-use expression which ensures that only supported
+# implementations can be selected.
+#
+# Check _dlang_get_bad_arches for a more detailed description of what
+# an implementation being supported means.
+#
+# <use_expand_name> is a string used to transform implementations as
+# they appear in <impls> into USE flags. Possible values are
+# "dlang_targets" and "dlang_single_target".
+#
+# Example: If we had the implementation dmd-2_105 with the keywords,
+# i.e. the keywords in _DLANG_DMD_FRONTENDS, `amd64 ~x86' and $KEYWORDS
+# has the contents `amd64 arm64 x86' the output should be:
+# @CODE
+# "<use_expand_name>_dmd-2_105? ( !x86 ) <use_expand_name>_dmd-2_105? ( !arm64 )"
+# @CODE
+dlang_compilers_stabs_required_use() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local use_expand_name=${1}
+	local impls=( ${@:2} )
+
+	local result=() impl
+	for impl in "${impls[@]}"; do
+		local badArches=( $(_dlang_get_bad_arches "${impl}") )
+		local arch
+		for arch in "${badArches[@]}"; do
+			result+=( "${use_expand_name}_${impl}? ( !${arch} )" )
+		done
+	done
+
+	echo "${result[@]}"
+}
+
+# @FUNCTION: dlang_compilers_stabs_impl_dep
+# @USAGE: <impl> <dep_string>
+# @DESCRIPTION:
+# Print a dependency string based on <dep_string>, USE disabled on
+# architectures found in $KEYWORDS that are not supported by <impl>.
+#
+# To see what it means for an architecture to be unsupported check
+# _dlang_get_bad_arches.
+#
+# Example: If we had the implementation dmd-2_105 with the keywords,
+# i.e. the keywords in _DLANG_DMD_FRONTENDS, `amd64 ~x86' and $KEYWORDS
+# has the contents `amd64 arm64 x86' the output should be:
+# @CODE
+# "!arm64? ( !x86? ( <dep_string> ) ) "
+# @CODE
+# Where <dep_string> looks like `dlang_single_target_dmd-2_105? ( dev-lang/dmd:2.105= ) '
+dlang_compilers_stabs_impl_dep() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl=${1} dep=${2}
+	local badArches=( $(_dlang_get_bad_arches "${impl}") )
+
+	local arch
+	for arch in "${badArches[@]}"; do
+		dep="!${arch}? ( ${dep}) "
+	done
+
+	echo "${dep}"
+}
+
+# @FUNCTION: _dlang_get_bad_arches
+# @USAGE: <impl>
+# @INTERNAL
+# @DESCRIPTION:
+# Output a string of all the arches that are unsupported by <impl> in
+# regards to $KEYWORDS.
+#
+# An architecture is considered unsupported if it:
+#
+# - appears in $KEYWORDS (either as stable or unstable) and it doesn't
+#   appear in the keywords of <impl>, the ones from the
+#   _DLANG_*_FRONTENDS arrays.
+#
+# - appears in $KEYWORDS as stable and it appears in the keywords of
+#   <impl> as unstable.
+#
+# For example, if we had the implementation dmd-2_105 with the keywords,
+# i.e. the keywords in _DLANG_DMD_FRONTENDS, `amd64 ~x86' and $KEYWORDS
+# has the contents `amd64 arm64 x86' the output should be, in no
+# particular order:
+# @CODE
+# x86 arm64
+# @CODE
+_dlang_get_bad_arches() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local details=( $(_dlang_get_impl_details "${1}") )
+	local implKeywords=( ${details[@]:2} )
+
+	local result=() keyword
+	# Meh, $KEYWORDS can contain -* (like for dmd) and that is globing
+	# so bad.
+	local keywords
+	read -ra keywords <<<"${KEYWORDS}"
+	for keyword in "${keywords[@]}"; do
+		[[ ${keyword::1} == - ]] && continue
+
+		local arch=${keyword}
+		[[ ${keyword::1} == "~" ]] && arch=${keyword:1}
+
+		local found=0
+		if [[ ${keyword::1} == "~" ]]; then
+			# An unstable package accepts a stable or an unstable implementation
+			has "${arch}" "${implKeywords[@]}" && found=1
+			has "~${arch}" "${implKeywords[@]}" && found=1
+		else
+			# A stable package accepts only a stable implementation
+			has "${arch}" "${implKeywords[@]}" && found=1
+		fi
+
+		if [[ ${found} == 0 ]]; then
+			result+=( "${arch}" )
+		fi
+	done
+
+	echo "${result[@]}"
+}
+
+# @FUNCTION: _dlang_get_impl_details
+# @USAGE: <impl>
+# @INTERNAL
+# @DESCRIPTION:
+# Print the details of the implementation denoted by <impl>, as they
+# appear in _DLANG_*_FRONTENDS.
+_dlang_get_impl_details() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local impl="${1/_/.}"
+
+	# Yay, optimizations
+	local name=${impl%-*} ver=${impl#*-}
+	local arr=_DLANG_${name^^}_FRONTENDS[@]
+
+	local details
+	for details in "${!arr}"; do
+		if [[ ${details%% *} == ${ver} ]]; then
+			echo "${details}"
+			return
+		fi
+	done
+
+	die "Unknown implementation: ${impl}"
+}
+
+fi


             reply	other threads:[~2024-04-13 23:04 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-13 23:04 Horodniceanu Andrei [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-11-08 14:56 [gentoo-commits] repo/user/dlang:master commit in: eclass/ Horodniceanu Andrei
2024-08-30  7:58 Horodniceanu Andrei
2024-07-14 19:44 Horodniceanu Andrei
2024-07-12 18:59 Horodniceanu Andrei
2024-07-12 18:59 Horodniceanu Andrei
2024-07-12 18:59 Horodniceanu Andrei
2024-04-26 20:25 Horodniceanu Andrei
2024-04-22 20:03 Horodniceanu Andrei
2024-04-13 23:04 Horodniceanu Andrei
2024-04-13 23:04 Horodniceanu Andrei
2024-04-13 23:04 Horodniceanu Andrei
2024-02-20 17:54 Horodniceanu Andrei
2024-02-18 22:49 Horodniceanu Andrei
2024-02-18 22:49 Horodniceanu Andrei
2023-12-17 11:58 Marco Leise
2023-12-17 11:58 Marco Leise
2023-12-17 11:58 Marco Leise
2023-11-17 21:44 Horodniceanu Andrei
2023-11-17 21:44 Horodniceanu Andrei
2023-10-01 14:01 Horodniceanu Andrei
2023-09-28  4:56 Marco Leise
2023-09-28  4:56 Marco Leise
2023-09-28  4:56 Marco Leise
2023-09-04 19:18 Marco Leise
2023-08-15  2:32 Marco Leise
2023-07-22 14:13 Marco Leise
2023-07-22 14:13 Marco Leise
2023-07-22 11:46 Marco Leise
2022-07-23 12:24 Marco Leise
2020-08-15  1:50 Marco Leise

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1713048445.88e2ca3511032435742bd8d7d1c01d8a29588ba3.a.horodniceanu@gentoo \
    --to=a.horodniceanu@proton.me \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox