[gentoo-dev] [PATCH v2] llvm-r1.eclass: Initial version

2024-02-08 Thread Michał Górny
See-Also: https://bugs.gentoo.org/923228
See-Also: https://bugs.gentoo.org/880671
Closes: https://bugs.gentoo.org/821955
Closes: https://bugs.gentoo.org/919150
Signed-off-by: Michał Górny 
---
 eclass/llvm-r1.eclass   | 225 
 eclass/tests/llvm-r1.sh | 151 +++
 2 files changed, 376 insertions(+)
 create mode 100644 eclass/llvm-r1.eclass
 create mode 100755 eclass/tests/llvm-r1.sh

Changes in v2: docstring fixes.

diff --git a/eclass/llvm-r1.eclass b/eclass/llvm-r1.eclass
new file mode 100644
index ..1b520f05e981
--- /dev/null
+++ b/eclass/llvm-r1.eclass
@@ -0,0 +1,225 @@
+# Copyright 2024 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+# @ECLASS: llvm-r1.eclass
+# @MAINTAINER:
+# Michał Górny 
+# @AUTHOR:
+# Michał Górny 
+# @SUPPORTED_EAPIS: 8
+# @PROVIDES: llvm-utils
+# @BLURB: Provide LLVM_SLOT to build against slotted LLVM
+# @DESCRIPTION:
+# An eclass to reliably depend on a set of LLVM-related packages
+# in a matching slot.  To use the eclass:
+#
+# 1. Set LLVM_COMPAT to the list of supported LLVM slots.
+# 2. Use llvm_gen_dep and/or LLVM_USEDEP to add appropriate
+#dependencies.
+# 3. Use llvm-r1_pkg_setup, get_llvm_prefix or LLVM_SLOT.
+#
+# The eclass sets IUSE and REQUIRED_USE.  The flag corresponding
+# to the newest supported stable LLVM slot (or the newest testing,
+# if no stable slots are supported) is enabled by default.
+#
+# Example:
+# @CODE
+# LLVM_COMPAT=( {16..18} )
+#
+# inherit llvm-r1
+#
+# DEPEND="
+#   dev-libs/libfoo[${LLVM_USEDEP}]
+#   $(llvm_gen_dep '
+# sys-devel/clang:${LLVM_SLOT}
+# sys-devel/llvm:${LLVM_SLOT}
+#   ')
+# "
+# @CODE
+
+case ${EAPI} in
+   8) ;;
+   *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
+esac
+
+if [[ ! ${_LLVM_R1_ECLASS} ]]; then
+_LLVM_R1_ECLASS=1
+
+inherit llvm-utils
+
+# == internal control knobs ==
+
+# @ECLASS_VARIABLE: _LLVM_OLDEST_SLOT
+# @INTERNAL
+# @DESCRIPTION:
+# Oldest supported LLVM slot.  This is used to automatically filter out
+# unsupported LLVM_COMPAT values.
+_LLVM_OLDEST_SLOT=15
+
+# @ECLASS_VARIABLE: _LLVM_NEWEST_STABLE
+# @INTERNAL
+# @DESCRIPTION:
+# The newest stable LLVM version.  Versions newer than that won't
+# be automatically enabled via USE defaults.
+_LLVM_NEWEST_STABLE=17
+
+# == control variables ==
+
+# @ECLASS_VARIABLE: LLVM_COMPAT
+# @PRE_INHERIT
+# @REQUIRED
+# @DESCRIPTION:
+# A list of LLVM slots supported by the package, oldest to newest.
+#
+# Example:
+# @CODE
+# LLVM_COMPAT=( {15..17} )
+# @CODE
+
+# == global metadata ==
+
+# @ECLASS_VARIABLE: LLVM_USEDEP
+# @OUTPUT_VARIABLE
+# @DESCRIPTION:
+# An eclass-generated USE dependency string that can be applied to other
+# packages using the same eclass, to enforce a LLVM slot match.
+
+_llvm_set_globals() {
+   debug-print-function ${FUNCNAME} "${@}"
+
+   if [[ ${LLVM_COMPAT@a} != *a* ]]; then
+   die "LLVM_COMPAT must be set to an array before inheriting 
${ECLASS}"
+   fi
+
+   local stable=() unstable=()
+   local x
+   for x in "${LLVM_COMPAT[@]}"; do
+   if [[ ${x} -gt ${_LLVM_NEWEST_STABLE} ]]; then
+   unstable+=( "${x}" )
+   elif [[ ${x} -ge ${_LLVM_OLDEST_SLOT} ]]; then
+   stable+=( "${x}" )
+   fi
+   done
+
+   _LLVM_SLOTS=( "${stable[@]}" "${unstable[@]}" )
+   if [[ ! ${_LLVM_SLOTS[@]} ]]; then
+   die "LLVM_COMPAT does not contain any valid versions (all older 
than ${_LLVM_OLDEST_SLOT}?)"
+   fi
+
+   if [[ ${stable[@]} ]]; then
+   IUSE="+llvm_slot_${stable[-1]}"
+   unset 'stable[-1]'
+   else
+   IUSE="+llvm_slot_${unstable[-1]}"
+   unset 'unstable[-1]'
+   fi
+   local nondefault=( "${stable[@]}" "${unstable[@]}" )
+   IUSE+=" ${nondefault[*]/#/llvm_slot_}"
+
+   local flags=( "${_LLVM_SLOTS[@]/#/llvm_slot_}" )
+   REQUIRED_USE="^^ ( ${flags[*]} )"
+   local usedep_flags=${flags[*]/%/(-)?}
+   LLVM_USEDEP=${usedep_flags// /,}
+   readonly LLVM_USEDEP
+}
+_llvm_set_globals
+unset -f _llvm_set_globals
+
+# == metadata helpers ==
+
+# @FUNCTION: llvm_gen_dep
+# @USAGE: 
+# @DESCRIPTION:
+# Output a dependency block, repeating "" conditionally
+# to all llvm_slot_* USE flags.  Any occurences of '${LLVM_SLOT}'
+# within the block will be substituted for the respective slot.
+#
+# Example:
+# @CODE
+# DEPEND="
+#   $(llvm_gen_dep '
+# sys-devel/clang:${LLVM_SLOT}
+# sys-devel/llvm:${LLVM_SLOT}
+#   ')
+# "
+# @CODE
+llvm_gen_dep() {
+   debug-print-function ${FUNCNAME} "${@}"
+   
+   [[ ${#} -ne 1 ]] && die "Usage: ${FUNCNAME} "
+
+   local dep=${1}
+
+   local slot
+   for slot in "${_LLVM_SLOTS[@]}"; do
+   echo "llvm_slot_${slot}? ( ${dep//\$\{LLVM_SLOT\}/${slot}} )"
+   done
+}
+
+# == ebuild helpers ==
+
+# @FUNCTION: 

[gentoo-dev] [PATCH] llvm-utils.eclass: Fix llvm_prepend_path to avoid duplicates

2024-02-08 Thread Michał Górny
Fix llvm_prepend_path() not to append the new path multiple times,
if the original PATH variable contained multiple LLVM directories.

Thanks to Alexander Miller who spotted it in:
https://github.com/gentoo/gentoo/pull/35196#discussion_r1480330001

Signed-off-by: Michał Górny 
---
 eclass/llvm-utils.eclass   | 10 ++
 eclass/tests/llvm-utils.sh | 12 
 2 files changed, 18 insertions(+), 4 deletions(-)

Changed in v2: simplified the logic, courtesy of Alexander Miller,
and added more test cases.

diff --git a/eclass/llvm-utils.eclass b/eclass/llvm-utils.eclass
index f308667e3dc2..532e609679b8 100644
--- a/eclass/llvm-utils.eclass
+++ b/eclass/llvm-utils.eclass
@@ -129,16 +129,18 @@ llvm_prepend_path() {
local new_path=()
local x added=
 
-   # prepend new path in front of the first LLVM version found
for x in "${split_path[@]}"; do
if [[ ${x} == */usr/lib/llvm/*/bin ]]; then
-   if [[ ${x} != ${llvm_path} ]]; then
+   # prepend new path in front of the first LLVM version 
found
+   if [[ ! ${added} ]]; then
new_path+=( "${llvm_path}" )
-   elif [[ ${added} && ${x} == ${llvm_path} ]]; then
+   added=1
+   fi
+   # remove duplicate copies of the same path
+   if [[ ${x} == ${llvm_path} ]]; then
# deduplicate
continue
fi
-   added=1
fi
new_path+=( "${x}" )
done
diff --git a/eclass/tests/llvm-utils.sh b/eclass/tests/llvm-utils.sh
index 5a46b25b7ad6..6fe3da3eda13 100755
--- a/eclass/tests/llvm-utils.sh
+++ b/eclass/tests/llvm-utils.sh
@@ -98,9 +98,21 @@ ESYSROOT=
 test_prepend_path 17 /usr/bin /usr/bin:/usr/lib/llvm/17/bin
 test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/bin 
/usr/lib/llvm/17/bin:/usr/bin
 test_prepend_path 17 /usr/bin:/usr/lib/llvm/17/bin 
/usr/bin:/usr/lib/llvm/17/bin
+test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/bin:/usr/lib/llvm/17/bin \
+   /usr/lib/llvm/17/bin:/usr/bin
+test_prepend_path 17 /usr/lib/llvm/17/bin:/usr/lib/llvm/17/bin:/usr/bin \
+   /usr/lib/llvm/17/bin:/usr/bin
+test_prepend_path 17 /usr/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/17/bin \
+   /usr/bin:/usr/lib/llvm/17/bin
 test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/bin \
/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/bin
 test_prepend_path 18 /usr/bin:/usr/lib/llvm/17/bin \
/usr/bin:/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin
+test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin:/usr/bin \
+   /usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin:/usr/bin
+test_prepend_path 18 /usr/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin \
+   /usr/bin:/usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/lib/llvm/16/bin
+test_prepend_path 18 /usr/lib/llvm/17/bin:/usr/bin:/usr/lib/llvm/16/bin \
+   /usr/lib/llvm/18/bin:/usr/lib/llvm/17/bin:/usr/bin:/usr/lib/llvm/16/bin
 
 texit
-- 
2.43.0




Re: [gentoo-dev] [PATCH 6/8] dev-util/intel_clc: Migrate to llvm-r1

2024-02-08 Thread Arsen Arsenović

Sam James  writes:

> Michał Górny  writes:
>
>> Closes: https://bugs.gentoo.org/923228
>> Signed-off-by: Michał Górny 
>> ---
>>  dev-util/intel_clc/intel_clc-24.0.0.ebuild | 48 --
>>  dev-util/intel_clc/intel_clc-.ebuild   | 48 --
>>  2 files changed, 18 insertions(+), 78 deletions(-)
>
> Arsen, could you verify this does solve the problem for you, just to be
> sure?

I've confirmed on the PR before seeing this email - yes, it works :-)
-- 
Arsen Arsenović


signature.asc
Description: PGP signature


Re: [gentoo-dev] [PATCH 1/7] eclass/dotnet-pkg-base.eclass: quotes and style tweaks for edge cases

2024-02-08 Thread Maciej Barć

Thanks Sam, this is what I added:

Subject: [PATCH 1/7] eclass/dotnet-pkg-base.eclass: quotes and style tweaks

format special variables in edge cases section of the dotnet-pkg-base eclass

Signed-off-by: Maciej Barć 


Subject: [PATCH 2/7] eclass/dotnet-pkg-base.eclass: deprecate wrong-style
 names

some functions were written in wrong style by ommission,
deprecate the wrong names (leave them in the elcass for compability)
and add functions with proper names

Signed-off-by: Maciej Barć 


Subject: [PATCH 3/7] eclass/dotnet-pkg-base.eclass: dotnet-pkg-base_test -
 remove directory magic

remove broken directory magic from the "dotnet-pkg-base_test" function,
now the eclass consumers can pass the directory as the last argument and
let the dotnet executable handle arguments instead of putting the weight
on the eclass,
also update the "dotnet-pkg-base_restore_tools" function documentation

Signed-off-by: Maciej Barć 


Subject: [PATCH 4/7] eclass/dotnet-pkg*: add dotnet-pkg_remove-bad

add new eclass feature that allows to remove projects from .NET
solution files,
the functions modified:
dotnet-pkg-base_sln-remove, dotnet-pkg_remove-bad, dotnet-pkg_src_prepare

Signed-off-by: Maciej Barć 


Subject: [PATCH 5/7] eclass/dotnet-pkg.eclass: add dotnet-pkg_force-compat

add new eclass function "dotnet-pkg_force-compat" that appends special
variables to dotnet command executions to force compability with
a spefified .NET SDK version

Signed-off-by: Maciej Barć 


Subject: [PATCH 6/7] eclass/dotnet-pkg-base.eclass: set DOTNET_ROOT

export proper DOTNET_ROOT for wanted DOTNET_PKG_COMPAT

Signed-off-by: Maciej Barć 


Subject: [PATCH 7/7] eclass/dotnet-pkg.eclass: prepare for safely using 
Nuget


prevent NuGet executable (part of "dotnet-sdk") from fetching remote NuGet
package sources,
add two new features to the nuget ecalss:
find and remove all nuget.config files,
add and use "nuget_writeconfig" function that creates a "nuget.config"
file which forces the use of NuGet packages specified in the ebuild file

Signed-off-by: Maciej Barć 



W dniu 8.02.2024 o 08:02, Sam James pisze:


Maciej Barć  writes:


Signed-off-by: Maciej Barć 
---


The series lgtm but please add some commit messages to them explaining
the motivation / why we're doing it now if applicable. No need to
re-send to ML once that's done.

Thanks!


  eclass/dotnet-pkg-base.eclass | 16 +++-
  1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/eclass/dotnet-pkg-base.eclass b/eclass/dotnet-pkg-base.eclass
index 1a9d31120..e7484a6c5 100644
--- a/eclass/dotnet-pkg-base.eclass
+++ b/eclass/dotnet-pkg-base.eclass
@@ -63,18 +63,24 @@ 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 [[ "${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} "
+   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 "
+   if [[ "${CATEGORY}/${PN}" != dev-dotnet/csharp-gentoodotnetinfo ]] ; 
then
+   DOTNET_PKG_BDEPS+="
+   dev-dotnet/csharp-gentoodotnetinfo
+   "
fi
  
  	IUSE+=" debug "




--
Have a great day!

~ Maciej XGQT Barć

x...@gentoo.org
Gentoo Linux developer
(dotnet, emacs, math, ml, nim, scheme, sci)
https://wiki.gentoo.org/wiki/User:Xgqt
9B0A 4C5D 02A3 B43C 9D6F D6B1 14D7 4A1F 43A6 AC3C


OpenPGP_0x14D74A1F43A6AC3C.asc
Description: OpenPGP public key


OpenPGP_signature.asc
Description: OpenPGP digital signature