From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C9AEE158089 for ; Fri, 15 Sep 2023 20:49:07 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 1AF912BC022; Fri, 15 Sep 2023 20:49:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id F04CD2BC022 for ; Fri, 15 Sep 2023 20:49:06 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2A3FA335D1C for ; Fri, 15 Sep 2023 20:49:06 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A288911A9 for ; Fri, 15 Sep 2023 20:49:04 +0000 (UTC) From: "Maciej Barć" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Maciej Barć" Message-ID: <1694810819.a87a7aaecdff4dd41209ec2e467ebd5aab61494e.xgqt@gentoo> Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/ X-VCS-Repository: repo/gentoo X-VCS-Files: eclass/nuget.eclass X-VCS-Directories: eclass/ X-VCS-Committer: xgqt X-VCS-Committer-Name: Maciej Barć X-VCS-Revision: a87a7aaecdff4dd41209ec2e467ebd5aab61494e X-VCS-Branch: master Date: Fri, 15 Sep 2023 20:49:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 124b0d4a-d074-40b2-923f-00e58521ea2e X-Archives-Hash: 4613a093c553718687c81ca096f03fd0 commit: a87a7aaecdff4dd41209ec2e467ebd5aab61494e Author: Maciej Barć gentoo org> AuthorDate: Fri Sep 15 14:32:25 2023 +0000 Commit: Maciej Barć gentoo org> CommitDate: Fri Sep 15 20:46:59 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a87a7aae eclass/nuget.eclass: add new nuget eclass common functions and variables for handling .NET NuGets Bug: https://bugs.gentoo.org/900597 Bug: https://github.com/gentoo/gentoo/pull/32109 Signed-off-by: Maciej Barć gentoo.org> eclass/nuget.eclass | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) 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