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 B391E15800A for ; Sun, 16 Jul 2023 12:40:51 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 95FE0E087A; Sun, 16 Jul 2023 12:39:52 +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 089B4E0875 for ; Sun, 16 Jul 2023 12:39:52 +0000 (UTC) From: =?UTF-8?q?Maciej=20Bar=C4=87?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Maciej=20Bar=C4=87?= Subject: [gentoo-dev] [PATCH 3/7] eclass/dotnet-pkg.eclass: introduce new eclass Date: Sun, 16 Jul 2023 14:38:05 +0200 Message-ID: <20230716123830.78932-3-xgqt@gentoo.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230716123830.78932-1-xgqt@gentoo.org> References: <20230716123830.78932-1-xgqt@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: 96fb7d09-ee66-4e2c-9f88-c2da289f102e X-Archives-Hash: 96cceb234605730f3cc177016666137a Bug: https://bugs.gentoo.org/900597 Bug: https://github.com/gentoo/gentoo/pull/29309 Signed-off-by: Maciej Barć --- eclass/dotnet-pkg.eclass | 249 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 eclass/dotnet-pkg.eclass diff --git a/eclass/dotnet-pkg.eclass b/eclass/dotnet-pkg.eclass new file mode 100644 index 0000000000..2b711467f5 --- /dev/null +++ b/eclass/dotnet-pkg.eclass @@ -0,0 +1,249 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: dotnet-pkg.eclass +# @MAINTAINER: +# Gentoo Dotnet project +# @AUTHOR: +# Anna Figueiredo Gomes +# Maciej Barć +# @SUPPORTED_EAPIS: 7 8 +# @PROVIDES: dotnet-pkg-utils nuget +# @BLURB: common functions and variables for .NET packages +# @DESCRIPTION: +# This eclass is designed to help with building and installing packages that +# use the .NET SDK. +# +# .NET SDK is a open-source framework from Microsoft, it is a cross-platform +# successor to .NET Framework. +# +# .NET packages require proper inspection before packaging: +# - the compatible .NET SDK version has to be declared, +# this can be done by inspecting the package's "*proj" files, +# unlike JAVA, .NET packages tend to lock onto one selected .NET SDK +# version, so building with other .NET versions will be mostly unsupported, +# - nugets, which are similar to JAVA's JARs (package .NET dependencies), +# have to be listed using either the "NUGETS" variable or bundled inside +# a "prebuilt" archive, in second case also the "NUGET_PACKAGES" variable +# has to be explicitly set. +# - the main project file (.*proj) that builds the project has to be specified +# by the "DOTNET_PROJECT" variable. + +case "${EAPI}" in + 7 | 8 ) + : + ;; + * ) + die "${ECLASS}: EAPI ${EAPI} unsupported." + ;; +esac + +if [[ -z ${_DOTNET_PKG_ECLASS} ]] ; then +_DOTNET_PKG_ECLASS=1 + +inherit dotnet-pkg-utils + +# @ECLASS_VARIABLE: DOTNET_PROJECTS +# @DEFAULT_UNSET +# @DESCRIPTION: +# Path to the main .NET project files (".csproj", ".fsproj", ".vbproj") +# used by default by "dotnet-pkg_src_compile" phase function. +# +# In .NET version 6.0 and lower it was possible to build a project solution +# (".sln") immediately with output to a specified directory ("--output DIR"), +# but versions >= 7.0 deprecated this behavior. This means that +# "dotnet-pkg-utils_build" will fail when pointed to a solution or a directory +# containing a solution file. +# +# It is up to the maintainer if this variable is set before inheriting +# "dotnet-pkg-utils" eclass, but it is advised that it is set after +# the variable "${S}" is set, it should also integrate with it +# (see the example below). +# +# Example: +# @CODE +# SRC_URI="..." +# S="${S}"/src +# +# LICENSE="MIT" +# SLOT="0" +# KEYWORDS="~amd64" +# +# DOTNET_PROJECTS=( "${S}/DotnetProject" ) +# +# src_prepare() { +# ... +# @CODE + +# @ECLASS_VARIABLE: DOTNET_RESTORE_EXTRA_ARGS +# @DESCRIPTION: +# Extra arguments to pass to the package restore, in the "src_configure" phase. +# +# This is passed only when restoring the specified "DOTNET_PROJECT". +# Other project restorers do not use this variable. +# +# It is up to the maintainer if this variable is set before inheriting +# "dotnet-pkg.eclass", but it is advised that it is set after the variable +# "DOTNET_PROJECT" (from "dotnet-pkg-utils" eclass) is set. +# +# Default value is an empty array. +# +# For more info see the "DOTNET_PROJECT" variable and "dotnet-pkg_src_configure". +DOTNET_RESTORE_EXTRA_ARGS=() + +# @ECLASS_VARIABLE: DOTNET_BUILD_EXTRA_ARGS +# @DESCRIPTION: +# Extra arguments to pass to the package build, in the "src_compile" phase. +# +# This is passed only when building the specified "DOTNET_PROJECT". +# Other project builds do not use this variable. +# +# It is up to the maintainer if this variable is set before inheriting +# "dotnet-pkg.eclass", but it is advised that it is set after the variable +# "DOTNET_PROJECT" (from "dotnet-pkg-utils" eclass) is set. +# +# Default value is an empty array. +# +# Example: +# @CODE +# DOTNET_BUILD_EXTRA_ARGS=( -p:WarningLevel=0 ) +# @CODE +# +# For more info see the "DOTNET_PROJECT" variable and "dotnet-pkg_src_compile". +DOTNET_BUILD_EXTRA_ARGS=() + +# @FUNCTION: dotnet-pkg_pkg_setup +# @DESCRIPTION: +# Default "pkg_setup" for the "dotnet-pkg" eclass. +# Pre-build configuration and checks. +# +# Calls "dotnet-pkg-utils_pkg_setup". +dotnet-pkg_pkg_setup() { + dotnet-pkg-utils_setup +} + +# @FUNCTION: dotnet-pkg_src_unpack +# @DESCRIPTION: +# Default "src_unpack" for the "dotnet-pkg" eclass. +# Unpack the package sources. +# +# Includes a special exception for nugets (".nupkg" files) - they are instead +# copied into the "NUGET_PACKAGES" directory. +dotnet-pkg_src_unpack() { + nuget_link-system-nugets + + local archive + for archive in ${A} ; do + case ${archive} in + *.nupkg ) + nuget_link "${DISTDIR}"/${archive} + ;; + * ) + unpack ${archive} + ;; + esac + done +} + +# @FUNCTION: dotnet-pkg_src_prepare +# @DESCRIPTION: +# Default "src_prepare" for the "dotnet-pkg" eclass. +# Prepare the package sources. +# +# Run "dotnet-pkg-utils_remove-global-json". +dotnet-pkg_src_prepare() { + dotnet-pkg-utils_remove-global-json + + default +} + +# @FUNCTION: dotnet-pkg_foreach-project +# @USAGE: ... +# @DESCRIPTION: +# Run a specified command for each project listed inside the "DOTNET_PROJECTS" +# variable. +# +# Used by "dotnet-pkg_src_configure" and "dotnet-pkg_src_compile". +dotnet-pkg_foreach-project() { + debug-print-function ${FUNCNAME} "${@}" + + local dotnet_project + for dotnet_project in "${DOTNET_PROJECTS[@]}" ; do + einfo "Running \"${@}\" for project: \"$(basename "${dotnet_project}")\"" + "${@}" "${dotnet_project}" + done +} + +# @FUNCTION: dotnet-pkg_src_configure +# @DESCRIPTION: +# Default "src_configure" for the "dotnet-pkg" eclass. +# Configure the package. +# +# First show information about current .NET SDK that is being used, +# then restore the project file specified by "DOTNET_PROJECT", +# afterwards restore any found solutions. +dotnet-pkg_src_configure() { + dotnet-pkg-utils_info + + dotnet-pkg_foreach-project \ + dotnet-pkg-utils_restore "${DOTNET_RESTORE_EXTRA_ARGS[@]}" + + dotnet-pkg-utils_foreach-solution dotnet-pkg-utils_restore "$(pwd)" +} + +# @FUNCTION: dotnet-pkg_src_compile +# @DESCRIPTION: +# Default "src_compile" for the "dotnet-pkg" eclass. +# Build the package. +# +# Build the package using "dotnet build" in the directory specified by either +# "DOTNET_PROJECT" or "S" (temporary build directory) variables. +# +# For more info see: "DOTNET_PROJECT" variable +# and "dotnet-pkg-utils_get-project" function. +dotnet-pkg_src_compile() { + dotnet-pkg_foreach-project \ + dotnet-pkg-utils_build "${DOTNET_BUILD_EXTRA_ARGS[@]}" +} + +# @FUNCTION: dotnet-pkg_src_test +# @DESCRIPTION: +# Default "src_test" for the "dotnet-pkg" eclass. +# Test the package. +# +# Test the package by testing any found solutions. +# +# It is very likely that this function will either not execute any tests or +# will execute wrong or incomplete test suite. Maintainers should inspect if +# any and/or correct tests are ran. +dotnet-pkg_src_test() { + dotnet-pkg-utils_foreach-solution dotnet-pkg-utils_test "$(pwd)" +} + +# @FUNCTION: dotnet-pkg_src_install +# @DESCRIPTION: +# Default "src_install" for the "dotnet-pkg" eclass. +# Install the package. +# +# This is the default package install function for the "dotnet-pkg" eclass. +# +# It is very likely that this function is either insufficient or has to be +# redefined in a ebuild. +dotnet-pkg_src_install() { + # Install the compiled .NET package artifacts, + # for more info see "dotnet-pkg-utils_install" and "DOTNET_OUTPUT". + dotnet-pkg-utils_install + + # Create launcher from the .NET package directory to "/usr/bin". + # For example: /usr/bin/Nake -> /usr/share/nake-3.0.0/Nake + dotnet-pkg-utils_dolauncher /usr/share/${P}/${PN^} + + # Create a compatibility symlink and also for ease of use from CLI. + dosym -r /usr/bin/${PN^} /usr/bin/${PN} + + einstalldocs +} + +EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install + +fi -- 2.41.0