commit:     d08eb2ce4c8adce01a37688366f4869e273dafc2
Author:     Maciej Barć <xgqt <AT> gentoo <DOT> org>
AuthorDate: Sat Feb  3 13:58:26 2024 +0000
Commit:     Maciej Barć <xgqt <AT> gentoo <DOT> org>
CommitDate: Sat Feb 10 16:24:45 2024 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d08eb2ce

eclass/dotnet-pkg.eclass: add dotnet-pkg_force-compat

add new eclass function "dotnet-pkg_force-compat" that appends special
variables to dotnet command executions to force compability with
a spefified .NET SDK version

Signed-off-by: Maciej Barć <xgqt <AT> gentoo.org>

 eclass/dotnet-pkg.eclass | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/eclass/dotnet-pkg.eclass b/eclass/dotnet-pkg.eclass
index 94f5c5a280f7..eba46c2af2a5 100644
--- a/eclass/dotnet-pkg.eclass
+++ b/eclass/dotnet-pkg.eclass
@@ -156,6 +156,29 @@ DOTNET_PKG_BUILD_EXTRA_ARGS=()
 # For more info see the "DOTNET_PROJECT" variable and "dotnet-pkg_src_test".
 DOTNET_PKG_TEST_EXTRA_ARGS=()
 
+# @FUNCTION: dotnet-pkg_force-compat
+# @DESCRIPTION:
+# This function appends special options to all "DOTNET_PKG_*_EXTRA_ARGS"
+# variables in an attempt to force compatibility to the picked
+# "DOTNET_PKG_COMPAT" .NET SDK version.
+#
+# Call this function post-inherit.
+dotnet-pkg_force-compat() {
+       if [[ -z ${DOTNET_PKG_COMPAT} ]] ; then
+               die "DOTNET_PKG_COMPAT is not set"
+       fi
+
+       local -a force_extra_args=(
+               -p:RollForward=Major
+               -p:TargetFramework="net${DOTNET_PKG_COMPAT}"
+               -p:TargetFrameworks="net${DOTNET_PKG_COMPAT}"
+       )
+
+       DOTNET_PKG_RESTORE_EXTRA_ARGS+=( "${force_extra_args[@]}" )
+       DOTNET_PKG_BUILD_EXTRA_ARGS+=( "${force_extra_args[@]}" )
+       DOTNET_PKG_TEST_EXTRA_ARGS+=( "${force_extra_args[@]}" )
+}
+
 # @FUNCTION: dotnet-pkg_pkg_setup
 # @DESCRIPTION:
 # Default "pkg_setup" for the "dotnet-pkg" eclass.

Reply via email to