Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/nuget.eclass | 192 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 192 insertions(+)
create mode 100644 eclass/nuget.eclass
diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass
new file mode 100644
index 0000000000..cbc9bae4a1
--- /dev/null
+++ b/eclass/nuget.eclass
@@ -0,0 +1,192 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: nuget.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @SUPPORTED_EAPIS: 7 8
+# @BLURB: common functions and variables for handling .NET NuGets
+# @DESCRIPTION:
+# This eclass is designed to provide support for .NET NuGet's ".nupkg" files.
+#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
+
+case "${EAPI}" in
+ 7 | 8 )
+ :
+ ;;
+ * )
+ die "${ECLASS}: EAPI ${EAPI} unsupported."
+ ;;
+esac
+
+if [[ -z ${_NUGET_ECLASS} ]] ; then
+_NUGET_ECLASS=1
+
+# @ECLASS_VARIABLE: SYSTEM_NUGETS
+# @DESCRIPTION:
+# Location of the system NuGet packages directory. +SYSTEM_NUGETS=/opt/dotnet-nugets
+
+# @ECLASS_VARIABLE: NUGET_APIS
+# @DESCRIPTION:
+# NuGet API URLs to use for precompiled NuGet package ".nupkg" downloads.
+# Set or append to this variable post-inherit, but before calling
+# the "nuget_uris" function, preferably just before "SRC_URI".
+#
+# Example:
+# @CODE
+# SRC_URI="https://example.com/example.tar.xz"
+# NUGET_APIS+=( "https://api.nuget.org/v3-flatcontainer" )
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+NUGET_APIS=( "https://api.nuget.org/v3-flatcontainer" )
+
+# @ECLASS_VARIABLE: NUGET_PACKAGES
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Path from where NuGets will be restored from.
+# Defaults to ${T}/nugets for use with "nuget_uris" but may be set to a custom
+# location to, for example, restore NuGets extracted form a prepared archive.
+# Do not set this variable in conjunction with non-empty "NUGETS".
+if [[ "${NUGETS}" ]] || [[ ! "${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
[...]
+# @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() {
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no nuget path given"
+
+ mkdir -p "${NUGET_PACKAGES}" || die
+
+ local nuget_name="$(basename "${1}")"
[...]
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
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 <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @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: <args> ...
+# @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
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/dotnet-pkg-utils.eclass | 598 +++++++++++++++++++++++++++++++++
1 file changed, 598 insertions(+)
create mode 100644 eclass/dotnet-pkg-utils.eclass
diff --git a/eclass/dotnet-pkg-utils.eclass b/eclass/dotnet-pkg-utils.eclass new file mode 100644
index 0000000000..aeabebc92d
--- /dev/null
+++ b/eclass/dotnet-pkg-utils.eclass
@@ -0,0 +1,598 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dotnet-pkg-utils.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @SUPPORTED_EAPIS: 7 8
+# @PROVIDES: nuget
+# @BLURB: common functions and variables for builds using .NET SDK
+# @DESCRIPTION:
+# This eclass is designed to provide common definitions for .NET packages. +#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
+
+case "${EAPI}" in
+ 7 | 8 )
+ :
+ ;;
+ * )
+ die "${ECLASS}: EAPI ${EAPI} unsupported."
+ ;;
+esac
+
+if [[ -z ${_DOTNET_PKG_UTILS_ECLASS} ]] ; then
+_DOTNET_PKG_UTILS_ECLASS=1
+
+inherit edo multiprocessing nuget
+
+# @ECLASS_VARIABLE: DOTNET_COMPAT
+# @REQUIRED
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Allows to choose a slot for dotnet.
+#
+# Most .NET packages will lock onto one supported .NET major version.
+# DOTNET_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.
+if [[ ${CATEGORY}/${PN} != dev-dotnet/dotnet-runtime-nugets ]] ; then
+ if [[ ! ${DOTNET_COMPAT} ]] ; then
+ die "${ECLASS}: DOTNET_COMPAT not set"
+ fi
+
+ RDEPEND+=" virtual/dotnet-sdk:${DOTNET_COMPAT} "
+ BDEPEND+=" ${RDEPEND} "
+
+ if [[ ${CATEGORY}/${PN} != dev-dotnet/csharp-gentoodotnetinfo ]] ; then + BDEPEND+=" 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_RUNTIME
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Sets the runtime used to build a package.
+#
+# This variable is set automatically by the "dotnet-pkg-utils_setup" function.
+
+# @ECLASS_VARIABLE: DOTNET_EXECUTABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Sets path of a "dotnet" executable.
+#
+# This variable is set automatically by the "dotnet-pkg-utils_setup" function.
+
+# @ECLASS_VARIABLE: DOTNET_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-utils_setup" function.
+
+# @ECLASS_VARIABLE: DOTNET_OUTPUT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Path of the output directory, where the package artifacts are placed during
+# the building of packages with "dotnet-pkg-utils_build" function.
+#
+# This variable is set automatically by the "dotnet-pkg-utils_setup" function.
+
+# @VARIABLE: DOTNET_LAUNCHERDEST
+# @INTERNAL
+# @DESCRIPTION:
+# Sets the path that .NET launchers are installed into by
+# the "dotnet-pkg-utils_dolauncher" function.
+#
+# The function "dotnet-pkg-utils_launcherinto" is able to manipulate this
+# variable.
+#
+# Defaults to "/usr/bin".
+DOTNET_LAUNCHERDEST=/usr/bin
+
+# @VARIABLE: DOTNET_LAUNCHERVARS
+# @INTERNAL
+# @DESCRIPTION:
+# Sets additional variables for .NET launchers created by
+# the "dotnet-pkg-utils_dolauncher" function.
+#
+# The function "dotnet-pkg-utils_append_launchervar" is able to manipulate this
+# variable.
+#
+# Defaults to a empty array.
+DOTNET_LAUNCHERVARS=()
+
+# @FUNCTION: dotnet-pkg-utils_get-configuration
+# @DESCRIPTION:
+# Return .NET configuration type of the current package.
+#
+# It is advised to refer to the "DOTNET_CONFIGURATION" variable instead of +# calling this function if necessary.
+#
+# Used by "dotnet-pkg-utils_setup".
+dotnet-pkg-utils_get-configuration() {
+ if in_iuse debug && use debug ; then
+ echo Debug
+ else
+ echo Release
+ fi
+}
+
+# @FUNCTION: dotnet-pkg-utils_get-output
+# @USAGE: <name>
+# @DESCRIPTION:
+# Return a specially constructed name of a directory for output of
+# "dotnet build" artifacts ("--output" flag, see "dotnet-pkg-utils_build"). +#
+# It is very rare that a maintainer would use this function in an ebuild.
+#
+# This function is used inside "dotnet-pkg-utils_setup". +dotnet-pkg-utils_get-output() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ! ${DOTNET_CONFIGURATION} ]] &&
+ die "${FUNCNAME}: DOTNET_CONFIGURATION is not set."
+
+ echo "${WORKDIR}"/${1}_net${DOTNET_COMPAT}_${DOTNET_CONFIGURATION}
+}
+
+# @FUNCTION: dotnet-pkg-utils_get-runtime
+# @DESCRIPTION:
+# Return the .NET runtime used for the current package.
+#
+# Used by "dotnet-pkg-utils_setup".
+dotnet-pkg-utils_get-runtime() {
+ local 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}: Unsupported architecture: ${ARCH}"
+ fi
+}
+
+# @FUNCTION: dotnet-pkg-utils_setup
+# @DESCRIPTION:
+# Sets up "DOTNET_EXECUTABLE" variable for later use in "edotnet".
+# Also sets up "DOTNET_CONFIGURATION" and "DOTNET_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-utils_setup() {
+ local _dotnet
+ for _dotnet in dotnet{,-bin}-${DOTNET_COMPAT} ; do
+ if type ${_dotnet} >/dev/null 2>&1 ; then
+ DOTNET_EXECUTABLE=${_dotnet}
+ DOTNET_EXECUTABLE_PATH="$(command -v
${_dotnet})"
+ break
+ fi
+ done
+
+ # Link "DOTNET_EXECUTABLE" to "dotnet" only for the package build.
+ local dotnet_spoof_path="${T}"/dotnet_spoof/${DOTNET_COMPAT}
+ mkdir -p "${dotnet_spoof_path}" || die
+ ln -s "${DOTNET_EXECUTABLE_PATH}" "${dotnet_spoof_path}"/dotnet || die + export PATH="${dotnet_spoof_path}:${PATH}"
+
+ einfo "Using dotnet SDK \"${DOTNET_EXECUTABLE}\" from \"${DOTNET_EXECUTABLE_PATH}\"."
+
+ # The picked "DOTNET_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_RUNTIME=$(dotnet-pkg-utils_get-runtime)
+ DOTNET_CONFIGURATION=$(dotnet-pkg-utils_get-configuration)
+ DOTNET_OUTPUT="$(dotnet-pkg-utils_get-output ${P})"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_remove-global-json() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local file="${1:-.}"/global.json
+
+ if [[ -f "${file}" ]] ; then
+ ebegin "Removing the global.json file"
+ rm "${file}"
+ eend ${?} || die "${FUNCNAME}: failed to remove ${file}"
+ fi
+}
+
+# @FUNCTION: edotnet
+# @USAGE: <command> [args...]
+# @DESCRIPTION:
+# Call dotnet, passing the supplied arguments.
+edotnet() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ if [[ ! "${DOTNET_EXECUTABLE}" ]] ; then
+ die "${FUNCNAME}: DOTNET_EXECUTABLE not set. Was dotnet-pkg-utils_setup called?"
+ fi
+
+ edo "${DOTNET_EXECUTABLE}" "${@}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_info() {
+ if [[ ${CATEGORY}/${PN} == dev-dotnet/csharp-gentoodotnetinfo ]] ; then + debug-print-function "${FUNCNAME}: ${P} is a special package, skipping dotnet-pkg-utils_info"
+ elif ! command -v gentoo-dotnet-info >/dev/null ; then
+ ewarn "${FUNCNAME}: gentoo-dotnet-info not available"
+ else
+ gentoo-dotnet-info || die "${FUNCNAME}: failed to execute gentoo-dotnet-info"
+ fi
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_foreach-solution() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local dotnet_solution
+ for dotnet_solution in $(find "${2:-.}" -maxdepth 1 -type f -name "*.sln") ; do
+ einfo "Running \"${1}\" for solution: \"$(basename "${dotnet_solution}")\""
+ "${1}" "${dotnet_solution}"
+ done
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_restore() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local directory
+ if [[ "${1}" ]] ; then
+ directory="${1}"
+ shift
+ else
+ directory="$(pwd)"
+ fi
+
+ local -a restore_args=(
+ --runtime ${DOTNET_RUNTIME}
+ --source "${NUGET_PACKAGES}"
+ -maxCpuCount:$(makeopts_jobs)
+ "${@}"
+ )
+
+ edotnet restore "${restore_args[@]}" "${directory}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_restore_tools() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ 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-utils_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-utils_build() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local directory
+ if [[ "${1}" ]] ; then
+ directory="${1}"
+ shift
+ else
+ directory="$(pwd)"
+ fi
+
+ local -a build_args=(
+ --configuration "${DOTNET_CONFIGURATION}"
+ --no-restore
+ --no-self-contained
+ --output "${DOTNET_OUTPUT}"
+ --runtime ${DOTNET_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-utils_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-utils_test() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local directory
+ if [[ "${1}" ]] ; then
+ directory="${1}"
+ shift
+ else
+ directory="$(pwd)"
+ fi
+
+ local -a test_args=(
+ --configuration "${DOTNET_CONFIGURATION}"
+ --no-restore
+ -maxCpuCount:$(makeopts_jobs)
+ "${@}"
+ )
+
+ edotnet test "${test_args[@]}" "${directory}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_install
+# @USAGE: [directory]
+# @DESCRIPTION:
+# Install the contents of "DOTNET_OUTPUT" into a directory, defaults to
+# "/usr/share/${PN}".
+#
+# Installation directory is relative to "ED".
+dotnet-pkg-utils_install() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local installation_directory="${1:-/usr/share/${P}}"
+
+ dodir "${installation_directory}"
+ cp -r "${DOTNET_OUTPUT}"/* "${ED}"/"${installation_directory}"/ || die
+}
+
+# @FUNCTION: dotnet-pkg-utils_launcherinto
+# @USAGE: <directory>
+# @DESCRIPTION:
+# Changes the path .NET launchers are installed into via subsequent
+# "dotnet-pkg-utils_dolauncher" calls.
+#
+# For more info see the "DOTNET_LAUNCHERDEST" variable. +dotnet-pkg-utils_launcherinto() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no directory specified"
+
+ DOTNET_LAUNCHERDEST="${1}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_append_launchervar
+# @USAGE: <variable-setting>
+# @DESCRIPTION:
+# Appends a given variable setting to the "DOTNET_LAUNCHERVARS".
+#
+# WARNING: This functions modifies a global variable permanently!
+# This means that all launchers created in subsequent
+# "dotnet-pkg-utils_dolauncher" calls of a given package will have
+# the given variable set.
+#
+# Example:
+# @CODE
+# dotnet-pkg-utils_append_launchervar "DOTNET_EnableAlternateStackCheck=1" +# @CODE
+#
+# For more info see the "DOTNET_LAUNCHERVARS" variable. +dotnet-pkg-utils_append_launchervar() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no variable setting specified"
+
+ DOTNET_LAUNCHERVARS+=( "${1}" )
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_install
+# dotnet-pkg-utils_dolauncher /usr/share/${P}/${PN^}
+# @CODE
+#
+# The path is prepended by "EPREFIX".
+dotnet-pkg-utils_dolauncher() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local executable_path executable_name
+
+ if [[ "${1}" ]] ; then
+ local executable_path="${1}"
+ shift
+ else
+ die "${FUNCNAME}: No executable path given."
+ fi
+
+ if [[ ${#} = 0 ]] ; then
+ executable_name="$(basename "${executable_path}")"
+ else
+ executable_name="${1}"
+ shift
+ fi
+
+ local executable_target="${T}/${executable_name}"
+
+ cat > "${executable_target}" <<-EOF
+ #!/bin/sh
+
+ # Lanucher script for ${executable_path} (${executable_name}),
+ # created from package "${CATEGORY}/${P}",
+ # compatible with dotnet version ${DOTNET_COMPAT}.
+
+ for __dotnet_root in \\
+ ${EPREFIX}/usr/$(get_libdir)/dotnet-sdk-${DOTNET_COMPAT} \\
+ ${EPREFIX}/opt/dotnet-sdk-bin-${DOTNET_COMPAT} ; do
+ [ -d \${__dotnet_root} ] && break
+ done
+
+ DOTNET_ROOT="\${__dotnet_root}"
+ export DOTNET_ROOT
+
+ $(for var in "${DOTNET_LAUNCHERVARS[@]}" ; do
+ echo "${var}"
+ echo "export ${var%%=*}"
+ done)
+
+ exec "${EPREFIX}${executable_path}" "\${@}"
+ EOF
+
+ dodir "${DOTNET_LAUNCHERDEST}"
+ exeinto "${DOTNET_LAUNCHERDEST}"
+ doexe "${executable_target}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_dolauncher_portable \
+# /usr/share/${P}/GentooDotnetInfo.dll gentoo-dotnet-info
+# @CODE
+#
+# The path is prepended by "EPREFIX". +dotnet-pkg-utils_dolauncher_portable() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local dll_path="${1}"
+ local executable_name="${2}"
+ local executable_target="${T}/${executable_name}"
+
+ cat > "${executable_target}" <<-EOF
+ #!/bin/sh
+
+ # Lanucher script for ${dll_path} (${executable_name}),
+ # created from package "${CATEGORY}/${P}",
+ # compatible with any dotnet version, built on ${DOTNET_COMPAT}.
+
+ $(for var in "${DOTNET_LAUNCHERVARS[@]}" ; do
+ echo "${var}"
+ echo "export ${var%%=*}"
+ done)
+
+ exec dotnet exec "${EPREFIX}${dll_path}" "\${@}"
+ EOF
+
+ dodir "${DOTNET_LAUNCHERDEST}"
+ exeinto "${DOTNET_LAUNCHERDEST}"
+ doexe "${executable_target}"
+}
+
+fi
+# @FUNCTION: dotnet-pkg-utils_install
+# @USAGE: [directory]
+# @DESCRIPTION:
+# Install the contents of "DOTNET_OUTPUT" into a directory, defaults to
+# "/usr/share/${PN}".
+#
+# Installation directory is relative to "ED".
+dotnet-pkg-utils_install() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local installation_directory="${1:-/usr/share/${P}}"
+
The docstring says it defaults to ${PN}, not ${P}?
Maciej Barć <[email protected]> writes:
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/dotnet-pkg-utils.eclass | 598 +++++++++++++++++++++++++++++++++
1 file changed, 598 insertions(+)
create mode 100644 eclass/dotnet-pkg-utils.eclass
diff --git a/eclass/dotnet-pkg-utils.eclass b/eclass/dotnet-pkg-utils.eclass >> new file mode 100644
index 0000000000..aeabebc92d
--- /dev/null
+++ b/eclass/dotnet-pkg-utils.eclass
@@ -0,0 +1,598 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dotnet-pkg-utils.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @SUPPORTED_EAPIS: 7 8
Let's not add EAPI 7 to a new eclass.
+# @PROVIDES: nuget
+# @BLURB: common functions and variables for builds using .NET SDK
+# @DESCRIPTION:
+# This eclass is designed to provide common definitions for .NET packages. >> +#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
+
+case "${EAPI}" in
+ 7 | 8 )
Per above, drop this, but if keeping it: 7|8). Own style is fine for an eclass ofc, but writing it like this is unconventional.
+ :
+ ;;
+ * )
+ die "${ECLASS}: EAPI ${EAPI} unsupported."
+ ;;
+esac
+
+if [[ -z ${_DOTNET_PKG_UTILS_ECLASS} ]] ; then
+_DOTNET_PKG_UTILS_ECLASS=1
+
+inherit edo multiprocessing nuget
+
+# @ECLASS_VARIABLE: DOTNET_COMPAT
+# @REQUIRED
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Allows to choose a slot for dotnet.
+#
+# Most .NET packages will lock onto one supported .NET major version.
+# DOTNET_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.
+if [[ ${CATEGORY}/${PN} != dev-dotnet/dotnet-runtime-nugets ]] ; then
+ if [[ ! ${DOTNET_COMPAT} ]] ; then
+ die "${ECLASS}: DOTNET_COMPAT not set"
+ fi
+
+ RDEPEND+=" virtual/dotnet-sdk:${DOTNET_COMPAT} "
+ BDEPEND+=" ${RDEPEND} "
+
+ if [[ ${CATEGORY}/${PN} != dev-dotnet/csharp-gentoodotnetinfo ]] ; then >> + BDEPEND+=" 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_RUNTIME
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Sets the runtime used to build a package.
+#
+# This variable is set automatically by the "dotnet-pkg-utils_setup" function.
+
+# @ECLASS_VARIABLE: DOTNET_EXECUTABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Sets path of a "dotnet" executable.
+#
+# This variable is set automatically by the "dotnet-pkg-utils_setup" function.
+
+# @ECLASS_VARIABLE: DOTNET_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-utils_setup" function.
+
+# @ECLASS_VARIABLE: DOTNET_OUTPUT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Path of the output directory, where the package artifacts are placed during
+# the building of packages with "dotnet-pkg-utils_build" function.
+#
+# This variable is set automatically by the "dotnet-pkg-utils_setup" function.
+
+# @VARIABLE: DOTNET_LAUNCHERDEST
+# @INTERNAL
+# @DESCRIPTION:
+# Sets the path that .NET launchers are installed into by
+# the "dotnet-pkg-utils_dolauncher" function.
+#
+# The function "dotnet-pkg-utils_launcherinto" is able to manipulate this >> +# variable.
+#
+# Defaults to "/usr/bin".
+DOTNET_LAUNCHERDEST=/usr/bin
+
+# @VARIABLE: DOTNET_LAUNCHERVARS
+# @INTERNAL
+# @DESCRIPTION:
+# Sets additional variables for .NET launchers created by
+# the "dotnet-pkg-utils_dolauncher" function.
+#
+# The function "dotnet-pkg-utils_append_launchervar" is able to manipulate this
+# variable.
+#
+# Defaults to a empty array.
+DOTNET_LAUNCHERVARS=()
+
+# @FUNCTION: dotnet-pkg-utils_get-configuration
+# @DESCRIPTION:
+# Return .NET configuration type of the current package.
+#
+# It is advised to refer to the "DOTNET_CONFIGURATION" variable instead of >> +# calling this function if necessary.
+#
+# Used by "dotnet-pkg-utils_setup".
+dotnet-pkg-utils_get-configuration() {
+ if in_iuse debug && use debug ; then
+ echo Debug
+ else
+ echo Release
+ fi
+}
+
+# @FUNCTION: dotnet-pkg-utils_get-output
+# @USAGE: <name>
+# @DESCRIPTION:
+# Return a specially constructed name of a directory for output of
+# "dotnet build" artifacts ("--output" flag, see "dotnet-pkg-utils_build"). >> +#
+# It is very rare that a maintainer would use this function in an ebuild. >> +#
+# This function is used inside "dotnet-pkg-utils_setup".
+dotnet-pkg-utils_get-output() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ! ${DOTNET_CONFIGURATION} ]] &&
+ die "${FUNCNAME}: DOTNET_CONFIGURATION is not set."
+
+ echo "${WORKDIR}"/${1}_net${DOTNET_COMPAT}_${DOTNET_CONFIGURATION}
+}
+
+# @FUNCTION: dotnet-pkg-utils_get-runtime
+# @DESCRIPTION:
+# Return the .NET runtime used for the current package.
+#
+# Used by "dotnet-pkg-utils_setup".
+dotnet-pkg-utils_get-runtime() {
+ local 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}: Unsupported architecture: ${ARCH}"
+ fi
+}
+
+# @FUNCTION: dotnet-pkg-utils_setup
+# @DESCRIPTION:
+# Sets up "DOTNET_EXECUTABLE" variable for later use in "edotnet".
+# Also sets up "DOTNET_CONFIGURATION" and "DOTNET_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-utils_setup() {
+ local _dotnet
+ for _dotnet in dotnet{,-bin}-${DOTNET_COMPAT} ; do
+ if type ${_dotnet} >/dev/null 2>&1 ; then
+ DOTNET_EXECUTABLE=${_dotnet}
+ DOTNET_EXECUTABLE_PATH="$(command -v
${_dotnet})"
We can just change the original call to `type -P` (not `type`)
and reuse the result here.
+ break
+ fi
+ done
+
+ # Link "DOTNET_EXECUTABLE" to "dotnet" only for the package build.
+ local dotnet_spoof_path="${T}"/dotnet_spoof/${DOTNET_COMPAT}
+ mkdir -p "${dotnet_spoof_path}" || die
+ ln -s "${DOTNET_EXECUTABLE_PATH}" "${dotnet_spoof_path}"/dotnet || die >> + export PATH="${dotnet_spoof_path}:${PATH}"
+
+ einfo "Using dotnet SDK \"${DOTNET_EXECUTABLE}\" from \"${DOTNET_EXECUTABLE_PATH}\"."
+
+ # The picked "DOTNET_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_RUNTIME=$(dotnet-pkg-utils_get-runtime)
+ DOTNET_CONFIGURATION=$(dotnet-pkg-utils_get-configuration)
+ DOTNET_OUTPUT="$(dotnet-pkg-utils_get-output ${P})"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_remove-global-json() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local file="${1:-.}"/global.json
+
+ if [[ -f "${file}" ]] ; then
+ ebegin "Removing the global.json file"
+ rm "${file}"
+ eend ${?} || die "${FUNCNAME}: failed to remove ${file}"
+ fi
+}
+
+# @FUNCTION: edotnet
+# @USAGE: <command> [args...]
+# @DESCRIPTION:
+# Call dotnet, passing the supplied arguments.
+edotnet() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ if [[ ! "${DOTNET_EXECUTABLE}" ]] ; then
+ die "${FUNCNAME}: DOTNET_EXECUTABLE not set. Was dotnet-pkg-utils_setup called?"
+ fi
+
+ edo "${DOTNET_EXECUTABLE}" "${@}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_info() {
+ if [[ ${CATEGORY}/${PN} == dev-dotnet/csharp-gentoodotnetinfo ]] ; then >> + debug-print-function "${FUNCNAME}: ${P} is a special package, skipping dotnet-pkg-utils_info"
+ elif ! command -v gentoo-dotnet-info >/dev/null ; then
+ ewarn "${FUNCNAME}: gentoo-dotnet-info not available"
+ else
+ gentoo-dotnet-info || die "${FUNCNAME}: failed to execute gentoo-dotnet-info"
+ fi
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_foreach-solution() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local dotnet_solution
+ for dotnet_solution in $(find "${2:-.}" -maxdepth 1 -type f -name "*.sln") ; do
+ einfo "Running \"${1}\" for solution: \"$(basename "${dotnet_solution}")\""
+ "${1}" "${dotnet_solution}"
+ done
Ideally, please change this to:
```
while read ... ; do
done < <( ... )
```
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_restore() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local directory
+ if [[ "${1}" ]] ; then
+ directory="${1}"
+ shift
+ else
+ directory="$(pwd)"
+ fi
+
+ local -a restore_args=(
+ --runtime ${DOTNET_RUNTIME}
+ --source "${NUGET_PACKAGES}"
+ -maxCpuCount:$(makeopts_jobs)
+ "${@}"
+ )
+
+ edotnet restore "${restore_args[@]}" "${directory}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_restore_tools() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ 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-utils_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-utils_build() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local directory
+ if [[ "${1}" ]] ; then
+ directory="${1}"
+ shift
+ else
+ directory="$(pwd)"
+ fi
+
+ local -a build_args=(
+ --configuration "${DOTNET_CONFIGURATION}"
+ --no-restore
+ --no-self-contained
+ --output "${DOTNET_OUTPUT}"
+ --runtime ${DOTNET_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-utils_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-utils_test() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local directory
+ if [[ "${1}" ]] ; then
+ directory="${1}"
+ shift
+ else
+ directory="$(pwd)"
+ fi
+
+ local -a test_args=(
+ --configuration "${DOTNET_CONFIGURATION}"
+ --no-restore
+ -maxCpuCount:$(makeopts_jobs)
+ "${@}"
+ )
+
+ edotnet test "${test_args[@]}" "${directory}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_install
+# @USAGE: [directory]
+# @DESCRIPTION:
+# Install the contents of "DOTNET_OUTPUT" into a directory, defaults to
+# "/usr/share/${PN}".
+#
+# Installation directory is relative to "ED".
+dotnet-pkg-utils_install() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local installation_directory="${1:-/usr/share/${P}}"
+
The docstring says it defaults to ${PN}, not ${P}?
+ dodir "${installation_directory}"
+ cp -r "${DOTNET_OUTPUT}"/* "${ED}"/"${installation_directory}"/ || die
I would just quote the whole second argument instead of selectively
doing it, but up to you.
+}
+
+# @FUNCTION: dotnet-pkg-utils_launcherinto
+# @USAGE: <directory>
+# @DESCRIPTION:
+# Changes the path .NET launchers are installed into via subsequent
+# "dotnet-pkg-utils_dolauncher" calls.
+#
+# For more info see the "DOTNET_LAUNCHERDEST" variable.
+dotnet-pkg-utils_launcherinto() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no directory specified"
+
+ DOTNET_LAUNCHERDEST="${1}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_append_launchervar
+# @USAGE: <variable-setting>
+# @DESCRIPTION:
+# Appends a given variable setting to the "DOTNET_LAUNCHERVARS".
+#
+# WARNING: This functions modifies a global variable permanently!
+# This means that all launchers created in subsequent
+# "dotnet-pkg-utils_dolauncher" calls of a given package will have
+# the given variable set.
+#
+# Example:
+# @CODE
+# dotnet-pkg-utils_append_launchervar "DOTNET_EnableAlternateStackCheck=1" >> +# @CODE
+#
+# For more info see the "DOTNET_LAUNCHERVARS" variable.
+dotnet-pkg-utils_append_launchervar() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no variable setting specified"
+
+ DOTNET_LAUNCHERVARS+=( "${1}" )
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_install
+# dotnet-pkg-utils_dolauncher /usr/share/${P}/${PN^}
+# @CODE
+#
+# The path is prepended by "EPREFIX".
+dotnet-pkg-utils_dolauncher() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local executable_path executable_name
+
+ if [[ "${1}" ]] ; then
+ local executable_path="${1}"
+ shift
+ else
+ die "${FUNCNAME}: No executable path given."
+ fi
+
+ if [[ ${#} = 0 ]] ; then
+ executable_name="$(basename "${executable_path}")"
+ else
+ executable_name="${1}"
+ shift
+ fi
+
+ local executable_target="${T}/${executable_name}"
+
+ cat > "${executable_target}" <<-EOF
Missing die.
+ #!/bin/sh
+
+ # Lanucher script for ${executable_path} (${executable_name}),
+ # created from package "${CATEGORY}/${P}",
+ # compatible with dotnet version ${DOTNET_COMPAT}.
+
+ for __dotnet_root in \\
+ ${EPREFIX}/usr/$(get_libdir)/dotnet-sdk-${DOTNET_COMPAT} \\
+ ${EPREFIX}/opt/dotnet-sdk-bin-${DOTNET_COMPAT} ; do
+ [ -d \${__dotnet_root} ] && break
+ done
+
+ DOTNET_ROOT="\${__dotnet_root}"
+ export DOTNET_ROOT
+
+ $(for var in "${DOTNET_LAUNCHERVARS[@]}" ; do
+ echo "${var}"
+ echo "export ${var%%=*}"
+ done)
+
+ exec "${EPREFIX}${executable_path}" "\${@}"
+ EOF
+
+ dodir "${DOTNET_LAUNCHERDEST}"
+ exeinto "${DOTNET_LAUNCHERDEST}"
+ doexe "${executable_target}"
+}
+
+# @FUNCTION: dotnet-pkg-utils_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-utils_dolauncher_portable \
+# /usr/share/${P}/GentooDotnetInfo.dll gentoo-dotnet-info
+# @CODE
+#
+# The path is prepended by "EPREFIX".
+dotnet-pkg-utils_dolauncher_portable() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local dll_path="${1}"
+ local executable_name="${2}"
+ local executable_target="${T}/${executable_name}"
+
+ cat > "${executable_target}" <<-EOF
Missing die.
+ #!/bin/sh
+
+ # Lanucher script for ${dll_path} (${executable_name}),
+ # created from package "${CATEGORY}/${P}",
+ # compatible with any dotnet version, built on ${DOTNET_COMPAT}.
+
+ $(for var in "${DOTNET_LAUNCHERVARS[@]}" ; do
+ echo "${var}"
+ echo "export ${var%%=*}"
+ done)
+
+ exec dotnet exec "${EPREFIX}${dll_path}" "\${@}"
+ EOF
+
+ dodir "${DOTNET_LAUNCHERDEST}"
+ exeinto "${DOTNET_LAUNCHERDEST}"
+ doexe "${executable_target}"
+}
+
+fi
On Sun, 16 Jul 2023, Maciej Barć wrote:
+case "${EAPI}" in
+ 7 | 8 )
+ :
+ ;;
+ * )
+ die "${ECLASS}: EAPI ${EAPI} unsupported."
+ ;;
+esac
The QA team has invested quite some work to unify that case block
between different eclasses. So, please stay with the standard style:
case ${EAPI} in
7|8) ;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
+ local dotnet_project
+ for dotnet_project in "${DOTNET_PROJECTS[@]}" ; do
+ einfo "Running \"${@}\" for project: \"$(basename "${dotnet_project}")\""
+ "${@}" "${dotnet_project}"
No die?
Maciej Barć <[email protected]> writes:
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
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 <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @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: <args> ...
+# @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}"
No 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-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
On Sun, 16 Jul 2023, Maciej Barć wrote:
+case "${EAPI}" in
+ 7 | 8 )
+ :
+ ;;
+ * )
+ die "${ECLASS}: EAPI ${EAPI} unsupported."
+ ;;
+esac
On Sun, 2023-07-30 at 16:26 +0200, Maciej Barć wrote:
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/dotnet-pkg-utils.eclass | 602 +++++++++++++++++++++++++++++++++
1 file changed, 602 insertions(+)
create mode 100644 eclass/dotnet-pkg-utils.eclass
diff --git a/eclass/dotnet-pkg-utils.eclass b/eclass/dotnet-pkg-utils.eclass >> new file mode 100644
index 000000000..bdde11fe5
--- /dev/null
+++ b/eclass/dotnet-pkg-utils.eclass
@@ -0,0 +1,602 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dotnet-pkg-utils.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: nuget
+# @BLURB: common functions and variables for builds using .NET SDK
+# @DESCRIPTION:
+# This eclass is designed to provide common definitions for .NET packages. >> +#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
Given how intrusive this is, I don't think "-utils" is a correct suffix.
It's for eclasses providing utility functions without affecting packages implicitly.
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/nuget.eclass | 188 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 188 insertions(+)
create mode 100644 eclass/nuget.eclass
diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass
new file mode 100644
index 000000000..320573c53
--- /dev/null
+++ b/eclass/nuget.eclass
@@ -0,0 +1,188 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: nuget.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @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.
+#
+# 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: SYSTEM_NUGETS
+# @DESCRIPTION:
+# Location of the system NuGet packages directory. +SYSTEM_NUGETS=/opt/dotnet-nugets
+
+# @ECLASS_VARIABLE: NUGET_APIS
+# @DESCRIPTION:
+# NuGet API URLs to use for precompiled NuGet package ".nupkg" downloads.
+# Set or append to this variable post-inherit, but before calling
+# the "nuget_uris" function, preferably just before "SRC_URI".
+#
+# Example:
+# @CODE
+# SRC_URI="https://example.com/example.tar.xz"
+# NUGET_APIS+=( "https://api.nuget.org/v3-flatcontainer" )
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+NUGET_APIS=( "https://api.nuget.org/v3-flatcontainer" )
+
+# @ECLASS_VARIABLE: NUGET_PACKAGES
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Path from where NuGets will be restored from.
+# Defaults to ${T}/nugets for use with "nuget_uris" but may be set to a custom
+# location to, for example, restore NuGets extracted form a prepared archive.
+# Do not set this variable in conjunction with non-empty "NUGETS".
+if [[ "${NUGETS}" ]] || [[ ! "${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
+
+# @FUNCTION: nuget_uris
+# @USAGE: <nuget...>
+# @DESCRIPTION:
+# Generates the URIs to put in SRC_URI to help fetch dependencies.
+# If no arguments provided, uses the "NUGETS" variable.
+nuget_uris() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local -r regex='^([a-zA-Z0-9_.-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$'
+ local nugets
+
+ if (( ${#} != 0 )) ; then
+ nugets="${@}"
+ elif [[ ${NUGETS} ]] ; then
+ nugets="${NUGETS}"
+ else
+ eerror "NUGETS variable is not defined and nothing passed as argument"
+ die "${FUNCNAME}: Can't generate SRC_URI from empty input"
+ fi
+
+ local nuget name version nuget_api url
+ for nuget in ${nugets} ; do
+ [[ ${nuget} =~ ${regex} ]] ||
+ die "${FUNCNAME}: Could not parse given nuget: ${nuget}"
+
+ name="${BASH_REMATCH[1]}"
+ version="${BASH_REMATCH[2]}"
+
+ for nuget_api in "${NUGET_APIS[@]}" ; do
+ case "${nuget_api}" in
+ */v2 | */v2/ )
+ url="${nuget_api}/package/${name}/${version}
+ -> ${name}.${version}.nupkg"
+ ;;
+ * )
+ url="${nuget_api}/${name}/${version}/${name}.${version}.nupkg"
+ ;;
+ esac
+ echo "${url}"
+ done
+ done
+}
+
+# @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() {
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no nuget path given"
+
+ mkdir -p "${NUGET_PACKAGES}" || die
+
+ local nuget_name="${1##*/}"
+
+ if [[ -f "${NUGET_PACKAGES}"/${nuget_name} ]] ; then
+ ewarn "${FUNCNAME}: ${nuget_name} already exists"
+ 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}${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 "${SYSTEM_NUGETS}"
+ doins "${@}"
+}
+
+fi
On Sun, 2023-07-30 at 16:26 +0200, Maciej Barć wrote:
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/nuget.eclass | 188 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 188 insertions(+)
create mode 100644 eclass/nuget.eclass
diff --git a/eclass/nuget.eclass b/eclass/nuget.eclass
new file mode 100644
index 000000000..320573c53
--- /dev/null
+++ b/eclass/nuget.eclass
@@ -0,0 +1,188 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: nuget.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @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.
+#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
This doesn't say anything about why or how you'd use the eclass.
+
+case ${EAPI} in
+ 8) ;;
+ *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ -z ${_NUGET_ECLASS} ]] ; then
+_NUGET_ECLASS=1
+
+# @ECLASS_VARIABLE: SYSTEM_NUGETS
+# @DESCRIPTION:
+# Location of the system NuGet packages directory.
+SYSTEM_NUGETS=/opt/dotnet-nugets
What is the usage for this variable? Is it a fixed value or something
to be overriden in ebuilds? Is it private or public?
Also namespace it to NUGET_*.
+
+# @ECLASS_VARIABLE: NUGET_APIS
+# @DESCRIPTION:
+# NuGet API URLs to use for precompiled NuGet package ".nupkg" downloads. >> +# Set or append to this variable post-inherit, but before calling
+# the "nuget_uris" function, preferably just before "SRC_URI".
+#
+# Example:
+# @CODE
+# SRC_URI="https://example.com/example.tar.xz"
+# NUGET_APIS+=( "https://api.nuget.org/v3-flatcontainer" )
+# SRC_URI+=" $(nuget_uris) "
+# @CODE
+NUGET_APIS=( "https://api.nuget.org/v3-flatcontainer" )
I'd be useful to explain what the default is.
+
+# @ECLASS_VARIABLE: NUGET_PACKAGES
+# @DEFAULT_UNSET
+# @PRE_INHERIT
+# @DESCRIPTION:
+# Path from where NuGets will be restored from.
This doesn't say anything to someone who doesn't know deep technical
details.
deep technical details.
+# Defaults to ${T}/nugets for use with "nuget_uris" but may be set to a custom
+# location to, for example, restore NuGets extracted form a prepared archive.
+# Do not set this variable in conjunction with non-empty "NUGETS".
+if [[ "${NUGETS}" ]] || [[ ! "${NUGET_PACKAGES}" ]] ; then
Combine the [[ ]]s.
Also, in general I'd suggest using '-z'/'-n' explicitly when it's
a empty/non-empty string with a meaningful value rather than a boolean.
+ 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
+
+# @FUNCTION: nuget_uris
+# @USAGE: <nuget...>
+# @DESCRIPTION:
+# Generates the URIs to put in SRC_URI to help fetch dependencies.
+# If no arguments provided, uses the "NUGETS" variable.
Sounds like you're copying the old, horribly slow cargo.eclass API.
Don't do that, unless you have to. Prefer variable-setting approach
used by modern cargo.eclass.
+nuget_uris() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ local -r regex='^([a-zA-Z0-9_.-]+)-([0-9]+\.[0-9]+\.[0-9]+.*)$'
Sounds like you're copying the second super-horribly slow approach of cargo.eclass. Don't do that.
+ local nugets
+
+ if (( ${#} != 0 )) ; then
+ nugets="${@}"
+ elif [[ ${NUGETS} ]] ; then
+ nugets="${NUGETS}"
+ else
+ eerror "NUGETS variable is not defined and nothing passed as argument"
+ die "${FUNCNAME}: Can't generate SRC_URI from empty input"
+ fi
+
+ local nuget name version nuget_api url
+ for nuget in ${nugets} ; do
+ [[ ${nuget} =~ ${regex} ]] ||
+ die "${FUNCNAME}: Could not parse given nuget: ${nuget}"
+
+ name="${BASH_REMATCH[1]}"
+ version="${BASH_REMATCH[2]}"
+
+ for nuget_api in "${NUGET_APIS[@]}" ; do
+ case "${nuget_api}" in
+ */v2 | */v2/ )
+ url="${nuget_api}/package/${name}/${version}
+ -> ${name}.${version}.nupkg"
+ ;;
+ * )
+ url="${nuget_api}/${name}/${version}/${name}.${version}.nupkg"
+ ;;
+ esac
+ echo "${url}"
+ done
+ done
+}
+
+# @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() {
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no nuget path given"
+
+ mkdir -p "${NUGET_PACKAGES}" || die
+
+ local nuget_name="${1##*/}"
+
+ if [[ -f "${NUGET_PACKAGES}"/${nuget_name} ]] ; then
+ ewarn "${FUNCNAME}: ${nuget_name} already exists"
What does that mean? What is the user supposed to do about it? Is it normal? If it's normal, then why are you warning about it? If it isn't normal, then why isn't this fatal?
+ 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}${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 "${SYSTEM_NUGETS}"
+ doins "${@}"
+}
+
+fi
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/dotnet-pkg-utils.eclass | 602 +++++++++++++++++++++++++++++++++
1 file changed, 602 insertions(+)
create mode 100644 eclass/dotnet-pkg-utils.eclass
diff --git a/eclass/dotnet-pkg-utils.eclass b/eclass/dotnet-pkg-utils.eclass new file mode 100644
index 000000000..bdde11fe5
--- /dev/null
+++ b/eclass/dotnet-pkg-utils.eclass
@@ -0,0 +1,602 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dotnet-pkg-utils.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: nuget
+# @BLURB: common functions and variables for builds using .NET SDK
+# @DESCRIPTION:
+# This eclass is designed to provide common definitions for .NET packages. +#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
+# @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
+
+# @FUNCTION: nuget_uris
+# @USAGE: <nuget...>
+# @DESCRIPTION:
+# Generates the URIs to put in SRC_URI to help fetch dependencies.
+# If no arguments provided, uses the "NUGETS" variable.
Sounds like you're copying the old, horribly slow cargo.eclass API.
Don't do that, unless you have to. Prefer variable-setting approach
used by modern cargo.eclass.
Please elaborate.
Maybe such mechanisms could be extracted into standalone eclass? I do
not know cargo, rust nor how it is used in Gentoo.
+# @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() {
+ [[ ! "${1}" ]] && die "${FUNCNAME}: no nuget path given"
+
+ mkdir -p "${NUGET_PACKAGES}" || die
+
+ local nuget_name="${1##*/}"
+
+ if [[ -f "${NUGET_PACKAGES}"/${nuget_name} ]] ; then
+ ewarn "${FUNCNAME}: ${nuget_name} already exists"
What does that mean? What is the user supposed to do about it? Is it normal? If it's normal, then why are you warning about it? If it isn't normal, then why isn't this fatal?
This can happen if NuGets copied from SYSTEM_NUGETS are overwritten by
ones specified in ebuild.
This might be desired by ebuild author.
We need to have this logged, I think ewarn is appropriate.
Which problem are we solving by moving away from this towards a slightly more verbose construct?
W dniu 30.07.2023 o 21:34, Michał Górny pisze:
On Sun, 2023-07-30 at 16:26 +0200, Maciej Barć wrote:
Bug: https://bugs.gentoo.org/900597
Bug: https://github.com/gentoo/gentoo/pull/29309
Signed-off-by: Maciej Barć <[email protected]>
---
eclass/dotnet-pkg-utils.eclass | 602 +++++++++++++++++++++++++++++++++
1 file changed, 602 insertions(+)
create mode 100644 eclass/dotnet-pkg-utils.eclass
diff --git a/eclass/dotnet-pkg-utils.eclass b/eclass/dotnet-pkg-utils.eclass
new file mode 100644
index 000000000..bdde11fe5
--- /dev/null
+++ b/eclass/dotnet-pkg-utils.eclass
@@ -0,0 +1,602 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: dotnet-pkg-utils.eclass
+# @MAINTAINER:
+# Gentoo Dotnet project <[email protected]>
+# @AUTHOR:
+# Anna Figueiredo Gomes <[email protected]>
+# Maciej Barć <[email protected]>
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: nuget
+# @BLURB: common functions and variables for builds using .NET SDK
+# @DESCRIPTION:
+# This eclass is designed to provide common definitions for .NET packages.
+#
+# This eclass does not export any phase functions, for that see
+# the "dotnet-pkg" eclass.
Given how intrusive this is, I don't think "-utils" is a correct suffix. It's for eclasses providing utility functions without affecting packages implicitly.
What about "-common", like "elisp-common.eclass" has?
[[PGP Signed Part:Undecided]]
On 31/07/2023 07.02, Michał Górny wrote:
On Sun, 2023-07-30 at 22:19 +0200, Florian Schmaus wrote:
Which problem are we solving by moving away from this towards a slightly >>> more verbose construct?The problem was that cargo.eclass ebuilds were taking significant
time
during cache regeneration and slowing down tools noticeably. No fancy
loops required, contrary to your great theory.
Removing the $()/fork from go-modules.eclass reduced the source time
of a package from 2400 milliseconds to 236 milliseconds.
Changing, for example net-p2p/arti-1.1.6, to use _cargo_set_crate_uris reduces the source time from 44 milliseconds to 24 milliseconds.
That is a win in relative reduction, but absolute its just 20
milliseconds. Cache regeneration is an embarrassingly parallel
problem. Therefore such a reduction should not matter much, assuming
you have some parallelism on the hardware level.
+EXPORT_FUNCTIONS pkg_setup src_unpack src_prepare src_configure src_compile src_test src_install
+
+fi
[[PGP Signed Part:Undecided]]
On 31/07/2023 11.32, Sam James wrote:
Florian Schmaus <[email protected]> writes:
[[PGP Signed Part:Undecided]]Consistency matters
On 31/07/2023 07.02, Michał Górny wrote:
On Sun, 2023-07-30 at 22:19 +0200, Florian Schmaus wrote:
Which problem are we solving by moving away from this towards a slightly >>>>> more verbose construct?The problem was that cargo.eclass ebuilds were taking significant
time
during cache regeneration and slowing down tools noticeably. No fancy >>>> loops required, contrary to your great theory.
Removing the $()/fork from go-modules.eclass reduced the source time
of a package from 2400 milliseconds to 236 milliseconds.
Changing, for example net-p2p/arti-1.1.6, to use _cargo_set_crate_uris
reduces the source time from 44 milliseconds to 24 milliseconds.
That is a win in relative reduction, but absolute its just 20
milliseconds. Cache regeneration is an embarrassingly parallel
problem. Therefore such a reduction should not matter much, assuming
you have some parallelism on the hardware level.
Sure, I would be in favor of consistently using $(foo_uris).
Especially since the performance gains of the variable-setting
approach are even lower than I first assumed. The cargo.eclass runs
the function that computes CARGO_CRATE_URIS now twice, which adds significantly more overhead than the fork of $(foo_uris). See my patch
to the ML.
and I already raised the point last week as well.
Here on the mailing list, or somewhere else?
On 31/07/2023 11.32, Sam James wrote:
Florian Schmaus <[email protected]> writes:
[[PGP Signed Part:Undecided]]
On 31/07/2023 07.02, Michał Górny wrote:
On Sun, 2023-07-30 at 22:19 +0200, Florian Schmaus wrote:
Which problem are we solving by moving away from this towards a slightlyThe problem was that cargo.eclass ebuilds were taking significant
more verbose construct?
time
during cache regeneration and slowing down tools noticeably. No fancy loops required, contrary to your great theory.
Removing the $()/fork from go-modules.eclass reduced the source time
of a package from 2400 milliseconds to 236 milliseconds.
Changing, for example net-p2p/arti-1.1.6, to use _cargo_set_crate_uris reduces the source time from 44 milliseconds to 24 milliseconds.
That is a win in relative reduction, but absolute its just 20 milliseconds. Cache regeneration is an embarrassingly parallel
problem. Therefore such a reduction should not matter much, assuming
you have some parallelism on the hardware level.
Consistency matters
Sure, I would be in favor of consistently using $(foo_uris).
Especially since the performance gains of the variable-setting approach
are even lower than I first assumed. The cargo.eclass runs the function
that computes CARGO_CRATE_URIS now twice, which adds significantly more overhead than the fork of $(foo_uris). See my patch to the ML.
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (1 / 15) |
| Uptime: | 164:48:59 |
| Calls: | 12,096 |
| Calls today: | 4 |
| Files: | 15,001 |
| Messages: | 6,517,803 |