diff options
author | V3n3RiX <venerix@koprulu.sector> | 2023-09-16 04:59:22 +0100 |
---|---|---|
committer | V3n3RiX <venerix@koprulu.sector> | 2023-09-16 04:59:22 +0100 |
commit | c748acf4192a1e08c9feb2d5f0004937a4869639 (patch) | |
tree | 3d3802bdd2770dc25d23a317afd0149df5a53cb2 /eclass | |
parent | d458376753e8fa261bdf469a99543577fb8d95a0 (diff) |
gentoo auto-resync : 16:09:2023 - 04:59:22
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/Manifest.gz | bin | 38670 -> 39165 bytes | |||
-rw-r--r-- | eclass/dotnet-pkg-base.eclass | 628 | ||||
-rw-r--r-- | eclass/dotnet-pkg.eclass | 263 | ||||
-rw-r--r-- | eclass/nuget.eclass | 197 |
4 files changed, 1088 insertions, 0 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz Binary files differindex 2422993bfd75..3bd1910ddaad 100644 --- a/eclass/Manifest.gz +++ b/eclass/Manifest.gz diff --git a/eclass/dotnet-pkg-base.eclass b/eclass/dotnet-pkg-base.eclass new file mode 100644 index 000000000000..c7f2e031daec --- /dev/null +++ b/eclass/dotnet-pkg-base.eclass @@ -0,0 +1,628 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: dotnet-pkg-base.eclass +# @MAINTAINER: +# Gentoo Dotnet project <dotnet@gentoo.org> +# @AUTHOR: +# Anna Figueiredo Gomes <navi@vlhl.dev> +# Maciej Barć <xgqt@gentoo.org> +# @SUPPORTED_EAPIS: 8 +# @PROVIDES: nuget +# @BLURB: common functions and variables for builds using .NET SDK +# @DESCRIPTION: +# This eclass is designed to provide required ebuild definitions for .NET +# packages. Beware that in addition to Gentoo-specific concepts also terms that +# should be known to people familiar with the .NET ecosystem are used through +# this one and similar eclasses. +# +# In ebuilds for software that only utilizes the .NET SDK, without special +# cases, the "dotnet-pkg.eclass" is probably better suited. +# +# 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 ${_DOTNET_PKG_BASE_ECLASS} ]] ; then +_DOTNET_PKG_BASE_ECLASS=1 + +inherit edo multiprocessing nuget + +# @ECLASS_VARIABLE: DOTNET_PKG_COMPAT +# @REQUIRED +# @PRE_INHERIT +# @DESCRIPTION: +# Allows to choose a slot for dotnet. +# +# Most .NET packages will lock onto one supported .NET major version. +# DOTNET_PKG_COMPAT should specify which version was chosen by package upstream. +# In case multiple .NET versions are specified in the project, then the highest +# should be picked by the maintainer. + +# @ECLASS_VARIABLE: DOTNET_PKG_RDEPS +# @DESCRIPTION: +# Populated with important dependencies on .NET ecosystem packages for running +# .NET packages. +# +# "DOTNET_PKG_RDEPS" should appear (or conditionally appear) in "RDEPEND". +DOTNET_PKG_RDEPS="" + +# @ECLASS_VARIABLE: DOTNET_PKG_BDEPS +# @DESCRIPTION: +# Populated with important dependencies on .NET ecosystem packages for building +# .NET packages. +# +# "DOTNET_PKG_BDEPS" should appear (or conditionally appear) in "BDEPEND". +DOTNET_PKG_BDEPS="" + +# Have this guard to be sure that *DEPS are not added to +# the "dev-dotnet/dotnet-runtime-nugets" package dependencies. +if [[ ${CATEGORY}/${PN} != dev-dotnet/dotnet-runtime-nugets ]] ; then + if [[ -z ${DOTNET_PKG_COMPAT} ]] ; then + die "${ECLASS}: DOTNET_PKG_COMPAT not set" + fi + + DOTNET_PKG_RDEPS+=" virtual/dotnet-sdk:${DOTNET_PKG_COMPAT} " + DOTNET_PKG_BDEPS+=" ${DOTNET_PKG_RDEPS} " + + # Special package "dev-dotnet/csharp-gentoodotnetinfo" used for information + # gathering, example for usage see the "dotnet-pkg-base_info" function. + if [[ ${CATEGORY}/${PN} != dev-dotnet/csharp-gentoodotnetinfo ]] ; then + DOTNET_PKG_BDEPS+=" dev-dotnet/csharp-gentoodotnetinfo " + fi + + IUSE+=" debug " +fi + +# Needed otherwise the binaries may break. +RESTRICT+=" strip " + +# Everything is built by "dotnet". +QA_PREBUILT=".*" + +# Special .NET SDK environment variables. +# Setting them either prevents annoying information from being generated +# or stops services that may interfere with a clean package build. +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_NOLOGO=1 +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export MSBUILDDISABLENODEREUSE=1 +export POWERSHELL_TELEMETRY_OPTOUT=1 +export POWERSHELL_UPDATECHECK=0 +# Overwrite selected MSBuild properties ("-p:XYZ"). +export UseSharedCompilation=false + +# @ECLASS_VARIABLE: DOTNET_PKG_RUNTIME +# @DEFAULT_UNSET +# @DESCRIPTION: +# Sets the runtime used to build a package. +# +# This variable is set automatically by the "dotnet-pkg-base_setup" function. + +# @ECLASS_VARIABLE: DOTNET_PKG_EXECUTABLE +# @DEFAULT_UNSET +# @DESCRIPTION: +# Sets path of a "dotnet" executable. +# +# This variable is set automatically by the "dotnet-pkg-base_setup" function. + +# @ECLASS_VARIABLE: DOTNET_PKG_CONFIGURATION +# @DEFAULT_UNSET +# @DESCRIPTION: +# Configuration value passed to "dotnet" in the compile phase. +# Is either Debug or Release, depending on the "debug" USE flag. +# +# This variable is set automatically by the "dotnet-pkg-base_setup" function. + +# @ECLASS_VARIABLE: DOTNET_PKG_OUTPUT +# @DEFAULT_UNSET +# @DESCRIPTION: +# Path of the output directory, where the package artifacts are placed during +# the building of packages with "dotnet-pkg-base_build" function. +# +# This variable is set automatically by the "dotnet-pkg-base_setup" function. + +# @VARIABLE: _DOTNET_PKG_LAUNCHERDEST +# @INTERNAL +# @DESCRIPTION: +# Sets the path that .NET launchers are installed into by +# the "dotnet-pkg-base_dolauncher" function. +# +# The function "dotnet-pkg-base_launcherinto" is able to manipulate this +# variable. +# +# Defaults to "/usr/bin". +_DOTNET_PKG_LAUNCHERDEST=/usr/bin + +# @VARIABLE: _DOTNET_PKG_LAUNCHERVARS +# @INTERNAL +# @DESCRIPTION: +# Sets additional variables for .NET launchers created by +# the "dotnet-pkg-base_dolauncher" function. +# +# The function "dotnet-pkg-base_append_launchervar" is able to manipulate this +# variable. +# +# Defaults to a empty array. +_DOTNET_PKG_LAUNCHERVARS=() + +# @FUNCTION: dotnet-pkg-base_get-configuration +# @DESCRIPTION: +# Return .NET configuration type of the current package. +# +# It is advised to refer to the "DOTNET_PKG_CONFIGURATION" variable instead of +# calling this function if necessary. +# +# Used by "dotnet-pkg-base_setup". +dotnet-pkg-base_get-configuration() { + if in_iuse debug && use debug ; then + echo Debug + else + echo Release + fi +} + +# @FUNCTION: dotnet-pkg-base_get-output +# @USAGE: <name> +# @DESCRIPTION: +# Return a specially constructed name of a directory for output of +# "dotnet build" artifacts ("--output" flag, see "dotnet-pkg-base_build"). +# +# It is very rare that a maintainer would use this function in an ebuild. +# +# This function is used inside "dotnet-pkg-base_setup". +dotnet-pkg-base_get-output() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + [[ -z ${DOTNET_PKG_CONFIGURATION} ]] && + die "${FUNCNAME[0]}: DOTNET_PKG_CONFIGURATION is not set." + + echo "${WORKDIR}/${1}_net${DOTNET_PKG_COMPAT}_${DOTNET_PKG_CONFIGURATION}" +} + +# @FUNCTION: dotnet-pkg-base_get-runtime +# @DESCRIPTION: +# Return the .NET runtime used for the current package. +# +# Used by "dotnet-pkg-base_setup". +dotnet-pkg-base_get-runtime() { + local libc + libc="$(usex elibc_musl "-musl" "")" + + if use amd64 ; then + echo "linux${libc}-x64" + elif use x86 ; then + echo "linux${libc}-x86" + elif use arm ; then + echo "linux${libc}-arm" + elif use arm64 ; then + echo "linux${libc}-arm64" + else + die "${FUNCNAME[0]}: Unsupported architecture: ${ARCH}" + fi +} + +# @FUNCTION: dotnet-pkg-base_setup +# @DESCRIPTION: +# Sets up "DOTNET_PKG_EXECUTABLE" variable for later use in "edotnet". +# Also sets up "DOTNET_PKG_CONFIGURATION" and "DOTNET_PKG_OUTPUT" +# for "dotnet-pkg_src_configure" and "dotnet-pkg_src_compile". +# +# This functions should be called by "pkg_setup". +# +# Used by "dotnet-pkg_pkg_setup" from the "dotnet-pkg" eclass. +dotnet-pkg-base_setup() { + local dotnet_compat_impl + local dotnet_compat_impl_path + for dotnet_compat_impl in dotnet{,-bin}-${DOTNET_PKG_COMPAT} ; do + dotnet_compat_impl_path="$(type -P "${dotnet_compat_impl}")" + + if [[ -n ${dotnet_compat_impl_path} ]] ; then + DOTNET_PKG_EXECUTABLE=${dotnet_compat_impl} + DOTNET_PKG_EXECUTABLE_PATH="${dotnet_compat_impl_path}" + + break + fi + done + + # Link "DOTNET_PKG_EXECUTABLE" to "dotnet" only for the package build. + local dotnet_spoof_path="${T}"/dotnet_spoof/${DOTNET_PKG_COMPAT} + mkdir -p "${dotnet_spoof_path}" || die + ln -s "${DOTNET_PKG_EXECUTABLE_PATH}" "${dotnet_spoof_path}"/dotnet || die + export PATH="${dotnet_spoof_path}:${PATH}" + + einfo "Using dotnet SDK \"${DOTNET_PKG_EXECUTABLE}\" from \"${DOTNET_PKG_EXECUTABLE_PATH}\"." + + # The picked "DOTNET_PKG_EXECUTABLE" should set "DOTNET_ROOT" internally + # and not rely upon this environment variable. + unset DOTNET_ROOT + + # Unset .NET and NuGet directories. + unset DOTNET_DATA + unset NUGET_DATA + + DOTNET_PKG_RUNTIME="$(dotnet-pkg-base_get-runtime)" + DOTNET_PKG_CONFIGURATION="$(dotnet-pkg-base_get-configuration)" + DOTNET_PKG_OUTPUT="$(dotnet-pkg-base_get-output "${P}")" +} + +# @FUNCTION: dotnet-pkg-base_remove-global-json +# @USAGE: [directory] +# @DESCRIPTION: +# Remove the "global.json" if it exists. +# The file in question might lock target package to a specified .NET +# version, which might be unnecessary (as it is in most cases). +# +# Optional "directory" argument defaults to the current directory path. +# +# Used by "dotnet-pkg_src_prepare" from the "dotnet-pkg" eclass. +dotnet-pkg-base_remove-global-json() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local file="${1:-.}"/global.json + + if [[ -f "${file}" ]] ; then + ebegin "Removing the global.json file" + rm "${file}" + eend ${?} || die "${FUNCNAME[0]}: failed to remove ${file}" + fi +} + +# @FUNCTION: edotnet +# @USAGE: <command> [args...] +# @DESCRIPTION: +# Call dotnet, passing the supplied arguments. +edotnet() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + if [[ -z ${DOTNET_PKG_EXECUTABLE} ]] ; then + die "${FUNCNAME[0]}: DOTNET_PKG_EXECUTABLE not set. Was dotnet-pkg-base_setup called?" + fi + + edo "${DOTNET_PKG_EXECUTABLE}" "${@}" +} + +# @FUNCTION: dotnet-pkg-base_info +# @DESCRIPTION: +# Show information about current .NET SDK that is being used. +# +# Depends upon the "gentoo-dotnet-info" program installed by +# the "dev-dotnet/csharp-gentoodotnetinfo" package. +# +# Used by "dotnet-pkg_src_configure" from the "dotnet-pkg" eclass. +dotnet-pkg-base_info() { + if [[ ${CATEGORY}/${PN} == dev-dotnet/csharp-gentoodotnetinfo ]] ; then + debug-print-function "${FUNCNAME[0]}: ${P} is a special package, skipping dotnet-pkg-base_info" + elif command -v gentoo-dotnet-info >/dev/null ; then + gentoo-dotnet-info || die "${FUNCNAME[0]}: failed to execute gentoo-dotnet-info" + else + ewarn "${FUNCNAME[0]}: gentoo-dotnet-info not available" + fi +} + +# @FUNCTION: dotnet-pkg-base_foreach-solution +# @USAGE: <function> [directory] +# @DESCRIPTION: +# Execute a function for each solution file (.sln) in a specified directory. +# This function may yield no real results because solutions are discovered +# automatically. +# +# Optional "directory" argument defaults to the current directory path. +# +# Used by "dotnet-pkg_src_configure" from the "dotnet-pkg" eclass. +dotnet-pkg-base_foreach-solution() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local dotnet_solution + local dotnet_solution_name + while read -r dotnet_solution ; do + dotnet_solution_name="$(basename "${dotnet_solution}")" + + ebegin "Running \"${1}\" for solution: \"${dotnet_solution_name}\"" + "${1}" "${dotnet_solution}" + eend $? "${FUNCNAME[0]}: failed for solution: \"${dotnet_solution}\"" || die + done < <(find "${2:-.}" -maxdepth 1 -type f -name "*.sln") +} + +# @FUNCTION: dotnet-pkg-base_restore +# @USAGE: [directory] [args] ... +# @DESCRIPTION: +# Restore the package using "dotnet restore" in a specified directory. +# +# Optional "directory" argument defaults to the current directory path. +# +# Additionally any number of "args" maybe be given, they are appended to +# the "dotnet" command invocation. +# +# Used by "dotnet-pkg_src_configure" from the "dotnet-pkg" eclass. +dotnet-pkg-base_restore() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local directory + if [[ "${1}" ]] ; then + directory="${1}" + shift + else + directory="$(pwd)" + fi + + local -a restore_args=( + --runtime "${DOTNET_PKG_RUNTIME}" + --source "${NUGET_PACKAGES}" + -maxCpuCount:$(makeopts_jobs) + "${@}" + ) + + edotnet restore "${restore_args[@]}" "${directory}" +} + +# @FUNCTION: dotnet-pkg-base_restore_tools +# @USAGE: [config-file] [args] ... +# @DESCRIPTION: +# Restore dotnet tools for a project in the current directory. +# +# Optional "config-file" argument is used to specify a file for the +# "--configfile" option which records what tools should be restored. +# +# Additionally any number of "args" maybe be given, they are appended to +# the "dotnet" command invocation. +dotnet-pkg-base_restore_tools() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local -a tool_restore_args=( + --add-source "${NUGET_PACKAGES}" + ) + + if [[ "${1}" ]] ; then + tool_restore_args+=( --configfile "${1}" ) + shift + fi + + tool_restore_args+=( "${@}" ) + + edotnet tool restore "${tool_restore_args[@]}" +} + +# @FUNCTION: dotnet-pkg-base_build +# @USAGE: [directory] [args] ... +# @DESCRIPTION: +# Build the package using "dotnet build" in a specified directory. +# +# Optional "directory" argument defaults to the current directory path. +# +# Additionally any number of "args" maybe be given, they are appended to +# the "dotnet" command invocation. +# +# Used by "dotnet-pkg_src_compile" from the "dotnet-pkg" eclass. +dotnet-pkg-base_build() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local directory + if [[ "${1}" ]] ; then + directory="${1}" + shift + else + directory="$(pwd)" + fi + + local -a build_args=( + --configuration "${DOTNET_PKG_CONFIGURATION}" + --no-restore + --no-self-contained + --output "${DOTNET_PKG_OUTPUT}" + --runtime "${DOTNET_PKG_RUNTIME}" + -maxCpuCount:$(makeopts_jobs) + "${@}" + ) + + if ! use debug ; then + build_args+=( + -p:StripSymbols=true + -p:NativeDebugSymbols=false + ) + fi + + edotnet build "${build_args[@]}" "${directory}" +} + +# @FUNCTION: dotnet-pkg-base_test +# @USAGE: [directory] [args] ... +# @DESCRIPTION: +# Test the package using "dotnet test" in a specified directory. +# +# Optional "directory" argument defaults to the current directory path. +# +# Additionally any number of "args" maybe be given, they are appended to +# the "dotnet" command invocation. +# +# Used by "dotnet-pkg_src_test" from the "dotnet-pkg" eclass. +dotnet-pkg-base_test() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local directory + if [[ "${1}" ]] ; then + directory="${1}" + shift + else + directory="$(pwd)" + fi + + local -a test_args=( + --configuration "${DOTNET_PKG_CONFIGURATION}" + --no-restore + -maxCpuCount:$(makeopts_jobs) + "${@}" + ) + + edotnet test "${test_args[@]}" "${directory}" +} + +# @FUNCTION: dotnet-pkg-base_install +# @USAGE: [directory] +# @DESCRIPTION: +# Install the contents of "DOTNET_PKG_OUTPUT" into a directory, defaults to +# "/usr/share/${P}". +# +# Installation directory is relative to "ED". +dotnet-pkg-base_install() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local installation_directory="${1:-/usr/share/${P}}" + + dodir "${installation_directory}" + cp -r "${DOTNET_PKG_OUTPUT}"/* "${ED}/${installation_directory}/" || die +} + +# @FUNCTION: dotnet-pkg-base_launcherinto +# @USAGE: <directory> +# @DESCRIPTION: +# Changes the path .NET launchers are installed into via subsequent +# "dotnet-pkg-base_dolauncher" calls. +# +# For more info see the "_DOTNET_PKG_LAUNCHERDEST" variable. +dotnet-pkg-base_launcherinto() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + [[ -z ${1} ]] && die "${FUNCNAME[0]}: no directory specified" + + _DOTNET_PKG_LAUNCHERDEST="${1}" +} + +# @FUNCTION: dotnet-pkg-base_append_launchervar +# @USAGE: <variable-setting> +# @DESCRIPTION: +# Appends a given variable setting to the "_DOTNET_PKG_LAUNCHERVARS". +# +# WARNING: This functions modifies a global variable permanently! +# This means that all launchers created in subsequent +# "dotnet-pkg-base_dolauncher" calls of a given package will have +# the given variable set. +# +# Example: +# @CODE +# dotnet-pkg-base_append_launchervar "DOTNET_EnableAlternateStackCheck=1" +# @CODE +# +# For more info see the "_DOTNET_PKG_LAUNCHERVARS" variable. +dotnet-pkg-base_append_launchervar() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + [[ -z ${1} ]] && die "${FUNCNAME[0]}: no variable setting specified" + + _DOTNET_PKG_LAUNCHERVARS+=( "${1}" ) +} + +# @FUNCTION: dotnet-pkg-base_dolauncher +# @USAGE: <executable-path> [filename] +# @DESCRIPTION: +# Make a wrapper script to launch an executable built from a .NET package. +# +# If no file name is given, the `basename` of the executable is used. +# +# Parameters: +# ${1} - path of the executable to launch, +# ${2} - filename of launcher to create (optional). +# +# Example: +# @CODE +# dotnet-pkg-base_install +# dotnet-pkg-base_dolauncher /usr/share/${P}/${PN^} +# @CODE +# +# The path is prepended by "EPREFIX". +dotnet-pkg-base_dolauncher() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local executable_path executable_name + + if [[ "${1}" ]] ; then + local executable_path="${1}" + shift + else + die "${FUNCNAME[0]}: No executable path given." + fi + + if [[ ${#} -eq 0 ]] ; then + executable_name="$(basename "${executable_path}")" + else + executable_name="${1}" + shift + fi + + local executable_target="${T}/${executable_name}" + + cat <<-EOF > "${executable_target}" || die + #!/bin/sh + + # Launcher script for ${executable_path} (${executable_name}), + # created from package "${CATEGORY}/${P}", + # compatible with dotnet version ${DOTNET_PKG_COMPAT}. + + for __dotnet_root in \\ + ${EPREFIX}/usr/$(get_libdir)/dotnet-sdk-${DOTNET_PKG_COMPAT} \\ + ${EPREFIX}/opt/dotnet-sdk-bin-${DOTNET_PKG_COMPAT} ; do + [ -d \${__dotnet_root} ] && break + done + + DOTNET_ROOT="\${__dotnet_root}" + export DOTNET_ROOT + + $(for var in "${_DOTNET_PKG_LAUNCHERVARS[@]}" ; do + echo "${var}" + echo "export ${var%%=*}" + done) + + exec "${EPREFIX}${executable_path}" "\${@}" + EOF + + exeinto "${_DOTNET_PKG_LAUNCHERDEST}" + doexe "${executable_target}" +} + +# @FUNCTION: dotnet-pkg-base_dolauncher_portable +# @USAGE: <dll-path> <filename> +# @DESCRIPTION: +# Make a wrapper script to launch a .NET DLL file built from a .NET package. +# +# Parameters: +# ${1} - path of the DLL to launch, +# ${2} - filename of launcher to create. +# +# Example: +# @CODE +# dotnet-pkg-base_dolauncher_portable \ +# /usr/share/${P}/GentooDotnetInfo.dll gentoo-dotnet-info +# @CODE +# +# The path is prepended by "EPREFIX". +dotnet-pkg-base_dolauncher_portable() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local dll_path="${1}" + local executable_name="${2}" + local executable_target="${T}/${executable_name}" + + cat <<-EOF > "${executable_target}" || die + #!/bin/sh + + # Launcher script for ${dll_path} (${executable_name}), + # created from package "${CATEGORY}/${P}", + # compatible with any dotnet version, built on ${DOTNET_PKG_COMPAT}. + + $(for var in "${_DOTNET_PKG_LAUNCHERVARS[@]}" ; do + echo "${var}" + echo "export ${var%%=*}" + done) + + exec dotnet exec "${EPREFIX}${dll_path}" "\${@}" + EOF + + exeinto "${_DOTNET_PKG_LAUNCHERDEST}" + doexe "${executable_target}" +} + +fi diff --git a/eclass/dotnet-pkg.eclass b/eclass/dotnet-pkg.eclass new file mode 100644 index 000000000000..05886af8554f --- /dev/null +++ b/eclass/dotnet-pkg.eclass @@ -0,0 +1,263 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: dotnet-pkg.eclass +# @MAINTAINER: +# Gentoo Dotnet project <dotnet@gentoo.org> +# @AUTHOR: +# Anna Figueiredo Gomes <navi@vlhl.dev> +# Maciej Barć <xgqt@gentoo.org> +# @SUPPORTED_EAPIS: 8 +# @PROVIDES: dotnet-pkg-base 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. +# It provides the required phase functions and special variables that make +# it easier to write ebuilds for .NET packages. +# If you do not use the exported phase functions, then consider using +# the "dotnet-pkg-base.eclass" instead. +# +# .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 exact selected .NET SDK +# version, so building with other .NET versions will be mostly unsupported, +# - Nugets, packages' .NET dependencies, which are similar to JAVA's JARs, +# 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 + 8) ;; + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; +esac + +if [[ -z ${_DOTNET_PKG_ECLASS} ]] ; then +_DOTNET_PKG_ECLASS=1 + +inherit dotnet-pkg-base + +# Append to "RDEPEND" and "BDEPEND" "DOTNET_PKG_RDEPS" and "DOTNET_PKG_BDEPS" +# generated by "dotnet-pkg-base" eclass. +RDEPEND+=" ${DOTNET_PKG_RDEPS} " +BDEPEND+=" ${DOTNET_PKG_BDEPS} " + +# @ECLASS_VARIABLE: DOTNET_PKG_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-base_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-base" 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="${WORKDIR}/${P}/src" +# +# LICENSE="MIT" +# SLOT="0" +# KEYWORDS="~amd64" +# +# DOTNET_PKG_PROJECTS=( "${S}/DotnetProject" ) +# +# src_prepare() { +# ... +# @CODE + +# @ECLASS_VARIABLE: DOTNET_PKG_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-base" eclass) is set. +# +# Default value is an empty array. +# +# For more info see the "DOTNET_PROJECT" variable and "dotnet-pkg_src_configure". +DOTNET_PKG_RESTORE_EXTRA_ARGS=() + +# @ECLASS_VARIABLE: DOTNET_PKG_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-base" eclass) is set. +# +# Default value is an empty array. +# +# Example: +# @CODE +# DOTNET_PKG_BUILD_EXTRA_ARGS=( -p:WarningLevel=0 ) +# @CODE +# +# For more info see the "DOTNET_PROJECT" variable and "dotnet-pkg_src_compile". +DOTNET_PKG_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-base_pkg_setup". +dotnet-pkg_pkg_setup() { + [[ ${MERGE_TYPE} != binary ]] && dotnet-pkg-base_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-base_remove-global-json". +dotnet-pkg_src_prepare() { + dotnet-pkg-base_remove-global-json + + default +} + +# @FUNCTION: dotnet-pkg_foreach-project +# @USAGE: <args> ... +# @DESCRIPTION: +# Run a specified command for each project listed inside the "DOTNET_PKG_PROJECTS" +# variable. +# +# Used by "dotnet-pkg_src_configure" and "dotnet-pkg_src_compile". +dotnet-pkg_foreach-project() { + debug-print-function "${FUNCNAME[0]}" "${@}" + + local dotnet_project + for dotnet_project in "${DOTNET_PKG_PROJECTS[@]}" ; do + ebegin "Running \"${*}\" for project: \"${dotnet_project##*/}\"" + "${@}" "${dotnet_project}" + eend $? "${FUNCNAME[0]}: failed for project: \"${dotnet_project}\"" || die + 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-base_info + + dotnet-pkg_foreach-project \ + dotnet-pkg-base_restore "${DOTNET_PKG_RESTORE_EXTRA_ARGS[@]}" + + dotnet-pkg-base_foreach-solution dotnet-pkg-base_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-base_get-project" function. +dotnet-pkg_src_compile() { + dotnet-pkg_foreach-project \ + dotnet-pkg-base_build "${DOTNET_PKG_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-base_foreach-solution dotnet-pkg-base_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: +# - install the compiled .NET package artifacts, +# for more info see "dotnet-pkg-base_install" and "DOTNET_PKG_OUTPUT", +# - create launcher from the .NET package directory to "/usr/bin", +# phase will detect to choose either executable with capital letter +# (common among .NET packages) or not, +# - call "einstalldocs". +# +# It is very likely that this function is either insufficient or has to be +# redefined in a ebuild. +dotnet-pkg_src_install() { + dotnet-pkg-base_install + + # /usr/bin/Nake -> /usr/share/nake-3.0.0/Nake + if [[ -f "${D}/usr/share/${P}/${PN^}" ]] ; then + dotnet-pkg-base_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}" + + elif [[ -f "${D}/usr/share/${P}/${PN}" ]] ; then + dotnet-pkg-base_dolauncher "/usr/share/${P}/${PN}" + fi + + einstalldocs +} + +fi + +EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install 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 <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. +# 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: <nugets> +# @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: <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() { + [[ -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: <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 "${NUGET_SYSTEM_NUGETS}" + doins "${@}" +} + +fi |