public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/7] eclass/nuget.eclass: introduce new eclass
@ 2023-07-16 12:38 Maciej Barć
  2023-07-16 12:38 ` [gentoo-dev] [PATCH 2/7] eclass/dotnet-pkg-utils.eclass: " Maciej Barć
                   ` (7 more replies)
  0 siblings, 8 replies; 29+ messages in thread
From: Maciej Barć @ 2023-07-16 12:38 UTC (permalink / raw
  To: gentoo-dev; +Cc: Maciej Barć

Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <xgqt@gentoo.org>
---
 eclass/nuget.eclass | 192 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 192 insertions(+)
 create mode 100644 eclass/nuget.eclass

diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass
new file mode 100644
index 0000000000..cbc9bae4a1
--- /dev/null
+++ b/eclass/nuget.eclass
@@ -0,0 +1,192 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: nuget.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <dotnet@gentoo.org>
+# @AUTHOR:
+# Anna Figueiredo Gomes <navi@vlhl.dev>
+# Maciej Barć <xgqt@gentoo.org>
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: common functions and variables for handling .NET NuGets
+# @DESCRIPTION:
+# This eclass is designed to provide support for .NET NuGet's ".nupkg" files.
+#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
+
+case "${EAPI}" in
+	7 | 8 )
+		:
+		;;
+	* )
+		die "${ECLASS}: EAPI ${EAPI} unsupported."
+		;;
+esac
+
+if [[ -z ${_NUGET_ECLASS} ]] ; then
+_NUGET_ECLASS=1
+
+# @ECLASS_VARIABLE: SYSTEM_NUGETS
+# @DESCRIPTION:
+# Location of the system NuGet packages directory.
+SYSTEM_NUGETS=/opt/dotnet-nugets
+
+# @ECLASS_VARIABLE: NUGET_APIS
+# @DESCRIPTION:
+# NuGet API URLs to use for precompiled NuGet package ".nupkg" downloads.
+# Set or append to this variable post-inherit, but before calling
+# the "nuget_uris" function, preferably just before "SRC_URI".
+#
+# Example:
+# @CODE
+# SRC_URI="https://example.com/example.tar.xz"
+# NUGET_APIS+=( "https://api.nuget.org/v3-flatcontainer" )
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+NUGET_APIS=( "https://api.nuget.org/v3-flatcontainer" )
+
+# @ECLASS_VARIABLE: NUGET_PACKAGES
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Path from where NuGets will be restored from.
+# Defaults to ${T}/nugets for use with "nuget_uris" but may be set to a custom
+# location to, for example, restore NuGets extracted form a prepared archive.
+# Do not set this variable in conjunction with non-empty "NUGETS".
+if [[ "${NUGETS}" ]] || [[ ! "${NUGET_PACKAGES}" ]] ; then
+	NUGET_PACKAGES="${T}"/nugets
+fi
+export NUGET_PACKAGES
+
+# @ECLASS_VARIABLE: NUGETS
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# String containing all NuGet packages that need to be downloaded.
+# Used by "nuget_uris".
+#
+# Example:
+# @CODE
+# NUGETS="
+#	ImGui.NET-1.87.2
+#	Config.Net-4.19.0
+# "
+#
+# inherit dotnet-pkg
+#
+# ...
+#
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+
+# @FUNCTION: nuget_uris
+# @USAGE: <nuget...>
+# @DESCRIPTION:
+# Generates the URIs to put in SRC_URI to help fetch dependencies.
+# If no arguments provided, uses the "NUGETS" variable.
+nuget_uris() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local -r regex='^([a-zA-Z0-9_.-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$'
+	local nugets
+
+	if (( ${#} != 0 )) ; then
+		nugets="${@}"
+	elif [[ ${NUGETS} ]] ; then
+		nugets="${NUGETS}"
+	else
+		eerror "NUGETS variable is not defined and nothing passed as argument"
+		die "${FUNCNAME}: Can't generate SRC_URI from empty input"
+	fi
+
+	local nuget name version nuget_api url
+	for nuget in ${nugets} ; do
+		[[ ${nuget} =~ ${regex} ]] ||
+			die "${FUNCNAME}: Could not parse given nuget: ${nuget}"
+
+		name="${BASH_REMATCH[1]}"
+		version="${BASH_REMATCH[2]}"
+
+		for nuget_api in "${NUGET_APIS[@]}" ; do
+			case "${nuget_api}" in
+				*/v2 | */v2/ )
+					url="${nuget_api}/package/${name}/${version}
+							-> ${name}.${version}.nupkg"
+					;;
+				* )
+					url="${nuget_api}/${name}/${version}/${name}.${version}.nupkg"
+					;;
+			esac
+			echo "${url}"
+		done
+	done
+}
+
+# @FUNCTION: nuget_link
+# @USAGE: <nuget-path>
+# @DESCRIPTION:
+# Link a specified NuGet package at "nuget-path" to the "NUGET_PACKAGES"
+# directory.
+#
+# Example:
+# @CODE
+# nuget_link "${DISTDIR}"/pkg.0.nupkg
+# @CODE
+#
+# This function is used inside "dotnet-pkg_src_unpack"
+# from the "dotnet-pkg" eclass.
+nuget_link() {
+	[[ ! "${1}" ]] && die "${FUNCNAME}: no nuget path given"
+
+	mkdir -p "${NUGET_PACKAGES}" || die
+
+	local nuget_name="$(basename "${1}")"
+
+	if [[ -f "${NUGET_PACKAGES}"/${nuget_name} ]] ; then
+		ewarn "${FUNCNAME}: ${nuget_name} already exists"
+	else
+		ln -s "${1}" "${NUGET_PACKAGES}"/${nuget_name} || die
+	fi
+}
+
+# @FUNCTION: nuget_link-system-nugets
+# @DESCRIPTION:
+# Link all system NuGet packages to the "NUGET_PACKAGES" directory.
+#
+# Example:
+# @CODE
+# src_unpack() {
+#     nuget_link-system-nugets
+#     default
+# }
+# @CODE
+#
+# This function is used inside "dotnet-pkg_src_unpack"
+# from the "dotnet-pkg" eclass.
+nuget_link-system-nugets() {
+	local runtime_nuget
+	for runtime_nuget in "${EPREFIX}${SYSTEM_NUGETS}"/*.nupkg ; do
+		if [[ -f "${runtime_nuget}" ]] ; then
+			nuget_link "${runtime_nuget}"
+		fi
+	done
+}
+
+# @FUNCTION: nuget_donuget
+# @USAGE: <nuget-path> ...
+# @DESCRIPTION:
+# Install NuGet package(s) at "nuget-path" to the system nugets directory.
+#
+# Example:
+# @CODE
+# src_install() {
+#     nuget_donuget my-pkg.nupkg
+# }
+# @CODE
+nuget_donuget() {
+	insinto "${SYSTEM_NUGETS}"
+	doins "${@}"
+}
+
+fi
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 29+ messages in thread
* [gentoo-dev] [PATCH 1/7] eclass/nuget.eclass: introduce new eclass
@ 2023-07-30 14:26 Maciej Barć
  2023-07-30 19:30 ` Michał Górny
  0 siblings, 1 reply; 29+ messages in thread
From: Maciej Barć @ 2023-07-30 14:26 UTC (permalink / raw
  To: gentoo-dev; +Cc: Maciej Barć

Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <xgqt@gentoo.org>
---
 eclass/nuget.eclass | 188 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 188 insertions(+)
 create mode 100644 eclass/nuget.eclass

diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass
new file mode 100644
index 000000000..320573c53
--- /dev/null
+++ b/eclass/nuget.eclass
@@ -0,0 +1,188 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: nuget.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <dotnet@gentoo.org>
+# @AUTHOR:
+# Anna Figueiredo Gomes <navi@vlhl.dev>
+# Maciej Barć <xgqt@gentoo.org>
+# @SUPPORTED_EAPIS: 8
+# @BLURB: common functions and variables for handling .NET NuGets
+# @DESCRIPTION:
+# This eclass is designed to provide support for .NET NuGet's ".nupkg" files.
+#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
+
+case ${EAPI} in
+	8) ;;
+	*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ -z ${_NUGET_ECLASS} ]] ; then
+_NUGET_ECLASS=1
+
+# @ECLASS_VARIABLE: SYSTEM_NUGETS
+# @DESCRIPTION:
+# Location of the system NuGet packages directory.
+SYSTEM_NUGETS=/opt/dotnet-nugets
+
+# @ECLASS_VARIABLE: NUGET_APIS
+# @DESCRIPTION:
+# NuGet API URLs to use for precompiled NuGet package ".nupkg" downloads.
+# Set or append to this variable post-inherit, but before calling
+# the "nuget_uris" function, preferably just before "SRC_URI".
+#
+# Example:
+# @CODE
+# SRC_URI="https://example.com/example.tar.xz"
+# NUGET_APIS+=( "https://api.nuget.org/v3-flatcontainer" )
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+NUGET_APIS=( "https://api.nuget.org/v3-flatcontainer" )
+
+# @ECLASS_VARIABLE: NUGET_PACKAGES
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Path from where NuGets will be restored from.
+# Defaults to ${T}/nugets for use with "nuget_uris" but may be set to a custom
+# location to, for example, restore NuGets extracted form a prepared archive.
+# Do not set this variable in conjunction with non-empty "NUGETS".
+if [[ "${NUGETS}" ]] || [[ ! "${NUGET_PACKAGES}" ]] ; then
+	NUGET_PACKAGES="${T}"/nugets
+fi
+export NUGET_PACKAGES
+
+# @ECLASS_VARIABLE: NUGETS
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# String containing all NuGet packages that need to be downloaded.
+# Used by "nuget_uris".
+#
+# Example:
+# @CODE
+# NUGETS="
+#	ImGui.NET-1.87.2
+#	Config.Net-4.19.0
+# "
+#
+# inherit dotnet-pkg
+#
+# ...
+#
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+
+# @FUNCTION: nuget_uris
+# @USAGE: <nuget...>
+# @DESCRIPTION:
+# Generates the URIs to put in SRC_URI to help fetch dependencies.
+# If no arguments provided, uses the "NUGETS" variable.
+nuget_uris() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	local -r regex='^([a-zA-Z0-9_.-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$'
+	local nugets
+
+	if (( ${#} != 0 )) ; then
+		nugets="${@}"
+	elif [[ ${NUGETS} ]] ; then
+		nugets="${NUGETS}"
+	else
+		eerror "NUGETS variable is not defined and nothing passed as argument"
+		die "${FUNCNAME}: Can't generate SRC_URI from empty input"
+	fi
+
+	local nuget name version nuget_api url
+	for nuget in ${nugets} ; do
+		[[ ${nuget} =~ ${regex} ]] ||
+			die "${FUNCNAME}: Could not parse given nuget: ${nuget}"
+
+		name="${BASH_REMATCH[1]}"
+		version="${BASH_REMATCH[2]}"
+
+		for nuget_api in "${NUGET_APIS[@]}" ; do
+			case "${nuget_api}" in
+				*/v2 | */v2/ )
+					url="${nuget_api}/package/${name}/${version}
+							-> ${name}.${version}.nupkg"
+					;;
+				* )
+					url="${nuget_api}/${name}/${version}/${name}.${version}.nupkg"
+					;;
+			esac
+			echo "${url}"
+		done
+	done
+}
+
+# @FUNCTION: nuget_link
+# @USAGE: <nuget-path>
+# @DESCRIPTION:
+# Link a specified NuGet package at "nuget-path" to the "NUGET_PACKAGES"
+# directory.
+#
+# Example:
+# @CODE
+# nuget_link "${DISTDIR}"/pkg.0.nupkg
+# @CODE
+#
+# This function is used inside "dotnet-pkg_src_unpack"
+# from the "dotnet-pkg" eclass.
+nuget_link() {
+	[[ ! "${1}" ]] && die "${FUNCNAME}: no nuget path given"
+
+	mkdir -p "${NUGET_PACKAGES}" || die
+
+	local nuget_name="${1##*/}"
+
+	if [[ -f "${NUGET_PACKAGES}"/${nuget_name} ]] ; then
+		ewarn "${FUNCNAME}: ${nuget_name} already exists"
+	else
+		ln -s "${1}" "${NUGET_PACKAGES}"/${nuget_name} || die
+	fi
+}
+
+# @FUNCTION: nuget_link-system-nugets
+# @DESCRIPTION:
+# Link all system NuGet packages to the "NUGET_PACKAGES" directory.
+#
+# Example:
+# @CODE
+# src_unpack() {
+#     nuget_link-system-nugets
+#     default
+# }
+# @CODE
+#
+# This function is used inside "dotnet-pkg_src_unpack"
+# from the "dotnet-pkg" eclass.
+nuget_link-system-nugets() {
+	local runtime_nuget
+	for runtime_nuget in "${EPREFIX}${SYSTEM_NUGETS}"/*.nupkg ; do
+		if [[ -f "${runtime_nuget}" ]] ; then
+			nuget_link "${runtime_nuget}"
+		fi
+	done
+}
+
+# @FUNCTION: nuget_donuget
+# @USAGE: <nuget-path> ...
+# @DESCRIPTION:
+# Install NuGet package(s) at "nuget-path" to the system nugets directory.
+#
+# Example:
+# @CODE
+# src_install() {
+#     nuget_donuget my-pkg.nupkg
+# }
+# @CODE
+nuget_donuget() {
+	insinto "${SYSTEM_NUGETS}"
+	doins "${@}"
+}
+
+fi
-- 
2.41.0



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

end of thread, other threads:[~2023-07-31 14:20 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-16 12:38 [gentoo-dev] [PATCH 1/7] eclass/nuget.eclass: introduce new eclass Maciej Barć
2023-07-16 12:38 ` [gentoo-dev] [PATCH 2/7] eclass/dotnet-pkg-utils.eclass: " Maciej Barć
2023-07-16 12:48   ` Sam James
2023-07-16 13:35     ` Maciej Barć
2023-07-16 12:38 ` [gentoo-dev] [PATCH 3/7] eclass/dotnet-pkg.eclass: " Maciej Barć
2023-07-16 12:56   ` Sam James
2023-07-16 13:38     ` Maciej Barć
2023-07-16 12:38 ` [gentoo-dev] [PATCH 4/7] dev-dotnet/dotnet-runtime-nugets: new package Maciej Barć
2023-07-16 12:38 ` [gentoo-dev] [PATCH 5/7] app-eselect/eselect-dotnet: " Maciej Barć
2023-07-16 12:38 ` [gentoo-dev] [PATCH 6/7] dev-dotnet/dotnet-sdk-bin: update packaging mechanism Maciej Barć
2023-07-16 12:58   ` Sam James
2023-07-16 13:31     ` Maciej Barć
2023-07-16 12:38 ` [gentoo-dev] [PATCH 7/7] dev-dotnet/dotnet-sdk-bin: drop old Maciej Barć
2023-07-16 12:43 ` [gentoo-dev] [PATCH 1/7] eclass/nuget.eclass: introduce new eclass Sam James
2023-07-16 13:44   ` Maciej Barć
2023-07-16 13:40 ` Ulrich Mueller
2023-07-16 13:47   ` Maciej Barć
  -- strict thread matches above, loose matches on Subject: below --
2023-07-30 14:26 Maciej Barć
2023-07-30 19:30 ` Michał Górny
2023-07-30 20:01   ` Maciej Barć
2023-07-31  5:08     ` Michał Górny
2023-07-30 20:19   ` Florian Schmaus
2023-07-31  5:02     ` Michał Górny
2023-07-31  7:53       ` Florian Schmaus
2023-07-31  9:32         ` Sam James
2023-07-31 10:49           ` Florian Schmaus
2023-07-31 11:39             ` Sam James
2023-07-31 13:53             ` Michał Górny
2023-07-31 14:20               ` Florian Schmaus

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