pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc show-all: fix output for list variables containing dol...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0d611da7f7ee
branches:  trunk
changeset: 413512:0d611da7f7ee
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri Mar 20 16:39:03 2020 +0000

description:
show-all: fix output for list variables containing dollar characters

Before, variables containing dollar characters displayed so wrong that it
was hard to explain.

To fix the problem, I typed almost random characters into the code until
the output was exactly as expected. I still do not understand:

* why the list variables need 8 dollars to survive the @x@ loop,
* why the code only works if the dollars come from an external variable
  instead of being written inline,
* why the backslash in the :C modifier needs to be doubled.

Anyway, the output of "bmake show-all-extract" now contains the shell
variable $${extract_file}, just as it should. The dollars are now doubled
in the output and thereby match the source code from the Makefile
exactly.

diffstat:

 mk/misc/show.mk           |  11 +++++++----
 regress/show-all/Makefile |   8 ++++----
 regress/show-all/spec     |  14 +++++++-------
 3 files changed, 18 insertions(+), 15 deletions(-)

diffs (109 lines):

diff -r c6ae5ddbc567 -r 0d611da7f7ee mk/misc/show.mk
--- a/mk/misc/show.mk   Fri Mar 20 16:32:11 2020 +0000
+++ b/mk/misc/show.mk   Fri Mar 20 16:39:03 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: show.mk,v 1.18 2019/09/08 09:01:04 rillig Exp $
+# $NetBSD: show.mk,v 1.19 2020/03/20 16:39:03 rillig Exp $
 #
 # This file contains some targets that print information gathered from
 # variables. They do not modify any variables.
@@ -165,6 +165,9 @@
 # using the :sh modifier may show warnings, for example because ${WRKDIR}
 # doesn't exist.
 
+_SHOW_ALL.d4=  $$$$            # see regress/show-all
+_SHOW_ALL.d8=  $$$$$$$$        # see regress/show-all
+
 show-all-${g}: .PHONY
        @${RUN} printf '%s:\n' ${g:Q}
 
@@ -181,7 +184,7 @@
          printf '  %s\t%-23s # empty\n' ${_LABEL.${c}} ${v:Q}=;        \
        else                                                            \
          printf '  %s\t%-23s \\\n' ${_LABEL.${c}} ${v:Q}=;             \
-         printf '\t\t\t\t%s \\\n' ${${v}:O:@x@${x:Q}@};                \
+         printf '\t\t\t\t%s \\\n' ${${v}:O:C,\\$$,${_SHOW_ALL.d8},g:@x@${x:Q}@}; \
          printf '\t\t\t\t# end of %s (sorted)\n' ${v:Q};               \
        fi
 
@@ -195,7 +198,7 @@
          printf '  %s\t%-23s # empty\n' ${_LABEL.${c}} ${v:Q}=;        \
        else                                                            \
          printf '  %s\t%-23s \\\n' ${_LABEL.${c}} ${v:Q}=;             \
-         printf '\t\t\t\t%s \\\n' ${${v}:@x@${x:Q}@};                  \
+         printf '\t\t\t\t%s \\\n' ${${v}:C,\\$$,${_SHOW_ALL.d8},g:@x@${x:Q}@}; \
          printf '\t\t\t\t# end of %s\n' ${v:Q};                        \
        fi
 
@@ -205,7 +208,7 @@
        ${RUN}                                                          \
        if ${!defined(${v}) :? true : false}; then                      \
          printf '  %s\t%-23s # undefined\n' ${_LABEL.${c}} ${v:Q};     \
-       elif value=${${v}:U:Q} && test "x$$value" = "x"; then           \
+       elif value=${${v}:U:C,\\$$,${_SHOW_ALL.d4},gW:Q} && test "x$$value" = "x"; then \
          printf '  %s\t%-23s # empty\n' ${_LABEL.${c}} ${v:Q}=;        \
        else                                                            \
          case "$$value" in (*[\        \ ]) eol="# ends with space";; (*) eol=""; esac; \
diff -r c6ae5ddbc567 -r 0d611da7f7ee regress/show-all/Makefile
--- a/regress/show-all/Makefile Fri Mar 20 16:32:11 2020 +0000
+++ b/regress/show-all/Makefile Fri Mar 20 16:39:03 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2020/03/20 15:45:12 rillig Exp $
+# $NetBSD: Makefile,v 1.5 2020/03/20 16:39:03 rillig Exp $
 
 DISTNAME=      show-all-1.0
 CATEGORIES=    regress
@@ -33,9 +33,9 @@
 _SORTED_VARS.regress=  *_ENV.*
 _LISTED_VARS.regress=  *_ARGS.*
 
-SHELLVAR_PLAIN=                "$$var $${var} $$other"
-SHELLVAR_ENV=          "$$var $${var} $$other"
-SHELLVAR_ARGS=         "$$var $${var} $$other"
+SHELLVAR_PLAIN=                "$$var $${var} $$other $$$$"
+SHELLVAR_ENV=          "$$var $${var} $$other $$$$"
+SHELLVAR_ARGS=         "$$var $${var} $$other $$$$"
 
 _VARGROUPS+=           shellvar
 _PKG_VARS.shellvar=    SHELLVAR_PLAIN SHELLVAR_ENV SHELLVAR_ARGS
diff -r c6ae5ddbc567 -r 0d611da7f7ee regress/show-all/spec
--- a/regress/show-all/spec     Fri Mar 20 16:32:11 2020 +0000
+++ b/regress/show-all/spec     Fri Mar 20 16:39:03 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: spec,v 1.3 2020/03/20 15:45:12 rillig Exp $
+# $NetBSD: spec,v 1.4 2020/03/20 16:39:03 rillig Exp $
 
 tmpdir=${TMPDIR:-/tmp}/pkgsrc-show-all
 rm -rf "$tmpdir"
@@ -49,7 +49,7 @@
   pkg  REGRESS.undefined       # undefined
   pkg  REGRESS.empty=          # empty
   pkg  REGRESS.space=           # ends with space
-  pkg  REGRESS.value=          All * kinds of `strange' \escape $characters
+  pkg  REGRESS.value=          All * kinds of `strange' \escape $$characters
   pkg  *=                      show-all-regress
   pkg  **=                     asterisk
 
@@ -71,17 +71,17 @@
        require_file "$tmpdir/show-all-regress.out" --equals "$tmpdir/expected"
 
 
-       # TODO: What the heck is going on here?
-       # The output of the ENV and ARGS cases should be the same as in PLAIN.
+       # Up to 2020-03-20, the output of the ENV and ARGS variables differed
+       # a lot from the PLAIN variable.
        #
        cat <<'EOF' > "$tmpdir/expected"
 shellvar:
-  pkg  SHELLVAR_PLAIN=         "$var ${var} $other"
+  pkg  SHELLVAR_PLAIN=         "$$var $${var} $$other $$$$"
   pkg  SHELLVAR_ENV=           \
-                               ".MAKE.LEVEL.ENVar  ther" \
+                               "$$var $${var} $$other $$$$" \
                                # end of SHELLVAR_ENV (sorted)
   pkg  SHELLVAR_ARGS=          \
-                               ".MAKE.LEVEL.ENVar  ther" \
+                               "$$var $${var} $$other $$$$" \
                                # end of SHELLVAR_ARGS
 
 EOF



Home | Main Index | Thread Index | Old Index