commit:     b10a9a5a8c8a532911f2396472ad8af94d93bc3f
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Jun  3 17:43:42 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jun  3 20:49:53 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=b10a9a5a

estrip: track issued warnings context-sensitively

Presently, estrip will raise warnings in the event that is tasked with
doing something that requires for a given tool to be available, yet is
unable to find it. It endeavours never to print the same warning twice
and accomplishes this by unsetting the applicable key of the 'path_of'
map, whose empty value will have conveyed the absence of the tool.

Such is all well and good. However, my attention was drawn to a
still-open GitHub PR which demonstrates a need for tracking whether
warnings have already been issued for a tool in a given context. For
example, there may be a need to warn of the absence of debugedit(1) on
account of needing it to fulfil the behaviour of the "splitdebug"
feature, whereas there may also be a need to warn on account of needing
to fulfil the behaviour of the "installsources" feature.

One way to address this would to go back to using individual scalar
variables to track whether a given warning has been issued. Rather than
do that, this commit introduces an associative array by the name of
'warned_for', whose keys are expected to be the name of a given tool,
and its values, strings comprised by space-separated warning categories.
The code beneath demonstrates how it is intended to be used in practice.

if [[ ! ${path_of[brush]} ]]; then
    # The brush tool is missing but needed for detangling.
    if ! contains_word "hair-detangle" "${warned_for[brush]}"; then
        # No warning yet issued. Go ahead and issue one now.
        warned_for[brush]+=" hair-detangle"
        ewarn "The hair-detangle feature requires the brush tool"
    fi
    return 0
fi

Link: https://github.com/gentoo/portage/pull/1436
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/estrip | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/bin/estrip b/bin/estrip
index 211aece3a3..1f4cfceb27 100755
--- a/bin/estrip
+++ b/bin/estrip
@@ -166,6 +166,10 @@ for bin in strip objcopy readelf ranlib; do
         path_of[$bin]=$bin
 done
 
+# Declare a map to keep track of whether warnings in certain categories have
+# been issued for a missing tool.
+declare -A warned_for
+
 # Figure out what tool set we're using to strip stuff
 unset SAFE_STRIP_FLAGS DEF_STRIP_FLAGS SPLIT_STRIP_FLAGS
 case $("${path_of[strip]}" --version 2>/dev/null) in
@@ -214,8 +218,8 @@ save_elf_sources() {
        if (( ! has_feature[installsources] || has_restriction[installsources] 
)); then
                return
        elif [[ ! ${path_of[debugedit]} ]]; then
-               if [[ -v 'path_of[debugedit]' ]]; then
-                       unset -v 'path_of[debugedit]'
+               if ! contains_word installsources "${warned_for[debugedit]}"; 
then
+                       warned_for[debugedit]+=" installsources"
                        ewarn "FEATURES=installsources is enabled but the 
debugedit binary could not be"
                        ewarn "found. This feature will not work unless 
debugedit is installed!"
                fi
@@ -257,8 +261,8 @@ dedup_elf_debug() {
        debug-print-function "${FUNCNAME}" "$@"
 
        if [[ ! ${path_of[dwz]} ]]; then
-               if [[ -v 'path_of[dwz]' ]]; then
-                       unset -v 'path_of[dwz]'
+               if ! contains_word dedupdebug "${warned_for[dwz]}"; then
+                       warned_for[dwz]+=" dedupdebug"
                        ewarn "FEATURES=dedupdebug is enabled but the dwz 
binary could not be"
                        ewarn "found. This feature will not work unless dwz is 
installed!"
                fi

Reply via email to