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)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id D6425158020 for ; Thu, 10 Nov 2022 00:50:13 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id E906BE0905; Thu, 10 Nov 2022 00:50:12 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (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 C606EE0905 for ; Thu, 10 Nov 2022 00:50:12 +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 BE6873406DD for ; Thu, 10 Nov 2022 00:50:11 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2D89655B for ; Thu, 10 Nov 2022 00:50:10 +0000 (UTC) From: "Anna Figueiredo Gomes" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anna Figueiredo Gomes" Message-ID: <1668040973.bff17eaa33fa048bf6eca18d658b2cf5bea8d375.anna-cli@gentoo> Subject: [gentoo-commits] repo/proj/guru:dev commit in: eclass/ X-VCS-Repository: repo/proj/guru X-VCS-Files: eclass/dotnet-utils.eclass X-VCS-Directories: eclass/ X-VCS-Committer: anna-cli X-VCS-Committer-Name: Anna Figueiredo Gomes X-VCS-Revision: bff17eaa33fa048bf6eca18d658b2cf5bea8d375 X-VCS-Branch: dev Date: Thu, 10 Nov 2022 00:50:10 +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: fcefcc7c-6d39-49a7-bf5d-e4e647b8d866 X-Archives-Hash: 41509a8301926d86adcd59b3181d84ce commit: bff17eaa33fa048bf6eca18d658b2cf5bea8d375 Author: Anna Figueiredo Gomes tutanota com> AuthorDate: Thu Nov 10 00:41:49 2022 +0000 Commit: Anna Figueiredo Gomes tutanota com> CommitDate: Thu Nov 10 00:42:53 2022 +0000 URL: https://gitweb.gentoo.org/repo/proj/guru.git/commit/?id=bff17eaa dotnet-utils.eclass: Utilities for net6.0 packages Functions for generating nuget uris and restoring them in dotnet. Signed-off-by: Anna Figueiredo Gomes tutanota.com> eclass/dotnet-utils.eclass | 154 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/eclass/dotnet-utils.eclass b/eclass/dotnet-utils.eclass new file mode 100644 index 000000000..26a968035 --- /dev/null +++ b/eclass/dotnet-utils.eclass @@ -0,0 +1,154 @@ +# Copyright 1999-2022 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: dotnet-utils.eclass +# @MAINTAINER: +# anna-cli@tutanota.com +# @AUTHOR: +# Anna Figueiredo Gomes +# @SUPPORTED_EAPIS: 7 8 +# @BLURB: common functions and variables for dotnet builds + +case "${EAPI:-0}" in + 7|8) + ;; + *) + die "Unsupported EAPI=${EAPI} for ${ECLASS}" + ;; +esac + +inherit multiprocessing + +BDEPEND=">=virtual/dotnet-sdk-6.0" +EXPORT_FUNCTIONS src_unpack src_prepare src_compile + +# @ECLASS_VARIABLE: DOTNET_CLI_TELEMETRY_OPTOUT +# @DESCRIPTION: +# Disables telemetry on dotnet. +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +# @ECLASS_VARIABLE: MSBUILDDISABLENODEREUSE +# @DESCRIPTION: +# Stops the dotnet node from not stopping after the build is done. +export MSBUILDDISABLENODEREUSE=1 +# @ECLASS_VARIABLE: DOTNET_NOLOGO +# @DESCRIPTION: +# Disables the header logo when running dotnet commands. +export DOTNET_NOLOGO=1 + +# Needed otherwise the binaries break +RESTRICT="strip" + +# @ECLASS_VARIABLE: NUGETS +# @DEFAULT_UNSET +# @PRE_INHERIT +# @DESCRIPTION: +# bash string containing all nuget package wants to download +# used by nuget_uris() +# Example: +# @CODE +# NUGETS=" +# ImGui.NET-1.87.2 +# Config.Net-4.19.0 +# " +# inherit nuget +# ... +# SRC_URI="$(nuget_uris)" +# @CODE + +# @FUNCTION: nuget_uris +# @DESCRIPTION: +# Generates the URIs to put in SRC_URI to help fetch dependencies. +# Uses first argument as nuget list. +# If no argument provided, uses NUGETS variable. +nuget_uris() { + local -r regex='^([a-zA-Z0-9_.-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$' + local nuget nugets + + if [[ -n ${@} ]]; then + nugets="$@" + elif [[ -n ${NUGETS} ]]; then + nugets="${NUGETS}" + else + eerror "NUGETS variable is not defined and nothing passed as argument" + die "Can't generate SRC_URI from empty input" + fi + + for nuget in ${nugets}; do + local name version url + [[ $nuget =~ $regex ]] || die "Could not parse name and version from nuget: $nuget" + name="${BASH_REMATCH[1]}" + version="${BASH_REMATCH[2]}" + url="https://api.nuget.org/v3-flatcontainer/${name}/${version}/${name}.${version}.nupkg" + echo "${url}" + done +} + +# @FUNCTION: edotnet +# @USAGE: [[command] ...] +# @DESCRIPTION: +# Call dotnet, passing the supplied arguments. +# @RETURN: dotnet exit code +edotnet() { + debug-print-function ${FUNCNAME} "$@" + + local ret + + set -- dotnet "${@}" -maxcpucount:$(makeopts_jobs) + echo "${@}" >&2 + "${@}" + ret=${?} + + if [[ ${ret} -ne 0 ]]; then + die -n "edotnet failed" + fi + + return ${ret} +} + +# @FUNCTION: dotnet-utils_src_unpack +# @DESCRIPTION: +# Unpacks the package +dotnet-utils_src_unpack() { + debug-print-function ${FUNCNAME} "$@" + + local archive + for archive in ${A}; do + case "${archive}" in + *.nupkg) + ;; + *) + unpack ${archive} + ;; + esac + done +} + +# @FUNCTION: dotnet-utils_src_prepare +# @DESCRIPTION: +# Restores the packages + +dotnet-utils_src_prepare() { + debug-print-function ${FUNCNAME} "$@" + edotnet restore \ + --runtime linux-x64 \ + --source "${DISTDIR}" || die + default +} + +# @FUNCTION: dotnet-utils_src_compile +# @DESCRIPTION: +# Build the package using dotnet publish +dotnet-utils_src_compile() { + debug-print-function ${FUNCNAME} "$@" + + addpredict /opt/dotnet-sdk-bin-6.0/metadata + + edotnet publish \ + --nologo \ + --no-restore \ + --configuration Release \ + --runtime linux-x64 \ + "-p:Version=${PV}" \ + -p:DebugType=embedded \ + --self-contained || die +}