From c748acf4192a1e08c9feb2d5f0004937a4869639 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Sat, 16 Sep 2023 04:59:22 +0100 Subject: gentoo auto-resync : 16:09:2023 - 04:59:22 --- eclass/nuget.eclass | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 eclass/nuget.eclass (limited to 'eclass/nuget.eclass') diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass new file mode 100644 index 000000000000..8ac81497f523 --- /dev/null +++ b/eclass/nuget.eclass @@ -0,0 +1,197 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: nuget.eclass +# @MAINTAINER: +# Gentoo Dotnet project +# @AUTHOR: +# Anna Figueiredo Gomes +# Maciej Barć +# @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. +# It is used to handle NuGets installation and usage. +# "dotnet-pkg" and "dotnet-pkg-utils" inherit this eclass. +# +# 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: NUGET_SYSTEM_NUGETS +# @DESCRIPTION: +# Location of the system NuGet packages directory. +readonly NUGET_SYSTEM_NUGETS=/opt/dotnet-nugets + +# @ECLASS_VARIABLE: NUGET_APIS +# @PRE_INHERIT +# @DESCRIPTION: +# NuGet API URLs to use for precompiled NuGet package ".nupkg" downloads. +# Set this variable pre-inherit. +# +# Defaults to an array of one item: +# "https://api.nuget.org/v3-flatcontainer" +# +# Example: +# @CODE +# NUGET_APIS+=( "https://api.nuget.org/v3-flatcontainer" ) +# inherit nuget +# SRC_URI="https://example.com/example.tar.xz" +# SRC_URI+=" ${NUGET_URIS} " +# @CODE +if [[ -z "${NUGET_APIS}" ]] ; then + NUGET_APIS=( "https://api.nuget.org/v3-flatcontainer" ) +fi + +# @ECLASS_VARIABLE: NUGET_PACKAGES +# @DEFAULT_UNSET +# @PRE_INHERIT +# @DESCRIPTION: +# Path from where NuGets will be restored from. +# This is a special variable that modifies the behavior of "dotnet". +# +# Defaults to ${T}/nugets for use with "NUGETS" but may be set to a custom +# location to, for example, restore NuGets extracted from a prepared archive. +# Do not set this variable in conjunction with non-empty "NUGETS". +if [[ -n "${NUGETS}" || -z "${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 + +# @ECLASS_VARIABLE: NUGET_URIS +# @OUTPUT_VARIABLE +# @DESCRIPTION: +# List of URIs to put in SRC_URI created from NUGETS variable. + +# @FUNCTION: _nuget_set_nuget_uris +# @USAGE: +# @DESCRIPTION: +# Generates the URIs to put in SRC_URI to help fetch dependencies. +# Constructs a list of NuGets from its arguments. +# The value is set as "NUGET_URIS". +_nuget_set_nuget_uris() { + local nugets="${1}" + + NUGET_URIS="" + + local nuget + local name version + local nuget_api url + for nuget in ${nugets} ; do + name="${nuget%@*}" + version="${nuget##*@}" + + for nuget_api in "${NUGET_APIS[@]}" ; do + case ${nuget_api%/} in + */v2 ) + url="${nuget_api}/package/${name}/${version} + -> ${name}.${version}.nupkg" + ;; + * ) + url="${nuget_api}/${name}/${version}/${name}.${version}.nupkg" + ;; + esac + + NUGET_URIS+="${url} " + done + done +} + +_nuget_set_nuget_uris "${NUGETS}" + +# @FUNCTION: nuget_link +# @USAGE: +# @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() { + [[ -z "${1}" ]] && die "${FUNCNAME[0]}: no nuget path given" + + mkdir -p "${NUGET_PACKAGES}" || die + + local nuget_name="${1##*/}" + + if [[ -f "${NUGET_PACKAGES}/${nuget_name}" ]] ; then + eqawarn "QA Notice: \"${nuget_name}\" already exists, not linking it" + 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}${NUGET_SYSTEM_NUGETS}"/*.nupkg ; do + if [[ -f "${runtime_nuget}" ]] ; then + nuget_link "${runtime_nuget}" + fi + done +} + +# @FUNCTION: nuget_donuget +# @USAGE: ... +# @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 "${NUGET_SYSTEM_NUGETS}" + doins "${@}" +} + +fi -- cgit v1.2.3