pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc mk/misc: in show-all, list values of *_ENV and *_ARGS ...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/d829db425303
branches:  trunk
changeset: 325145:d829db425303
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Nov 10 10:40:55 2018 +0000

description:
mk/misc: in show-all, list values of *_ENV and *_ARGS in separate lines

The *_ENV and *_ARG values are typically very long, and reading them in
a single line is unnecessarily difficult. Therefore, each of their
values is listed on a separate line, for example:

fetch:
  usr   DIST_PATH (undefined)
  pkg   MASTER_SITES = \
                http://ftp.gnome.org/pub/GNOME/sources/glib/2.56/ \
                ftp://ftp.gnome.org/pub/GNOME/sources/glib/2.56/ \
                ftp://ftp.cse.buffalo.edu/pub/Gnome/sources/glib/2.56/ \
                https://download.gnome.org/sources/glib/2.56/ \
                # end of MASTER_SITES
  pkg   DIST_SUBDIR (undefined)

diffstat:

 mk/misc/show.mk           |  72 +++++++++++++++++++++++++++++++++++++---------
 regress/Makefile          |   3 +-
 regress/show-all/DESCR    |   5 +++
 regress/show-all/Makefile |  35 ++++++++++++++++++++++
 regress/show-all/PLIST    |   2 +
 regress/show-all/spec     |  70 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 171 insertions(+), 16 deletions(-)

diffs (241 lines):

diff -r 232cd96f976a -r d829db425303 mk/misc/show.mk
--- a/mk/misc/show.mk   Sat Nov 10 10:01:21 2018 +0000
+++ b/mk/misc/show.mk   Sat Nov 10 10:40:55 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: show.mk,v 1.14 2018/05/28 22:34:47 rillig Exp $
+# $NetBSD: show.mk,v 1.15 2018/11/10 10:40:55 rillig Exp $
 #
 # This file contains some targets that print information gathered from
 # variables. They do not modify any variables.
@@ -136,30 +136,72 @@
 
 show-all: show-all-${g}
 
+# In the following code, the variables are evaluated as late as possible.
+# This is especially important for variables that use the :sh modifier,
+# like SUBST_FILES.pkglocaledir from mk/configure/replace-localedir.mk.
+#
+# When finally showing the variables, it is unavoidable that variables
+# using the :sh modifier may show warnings, for example because ${WRKDIR}
+# doesn't exist.
+
 show-all-${g}: .PHONY
        @echo "${g}:"
 .  for c in ${_SHOW_ALL_CATEGORIES}
 .    for v in ${${c}.${g}}
-.      if defined(${v})
-# Be careful not to evaluate variables too early. Some may use the :sh
-# modifier, which can end up taking much time and issuing unexpected
-# warnings and error messages.
-#
-# When finally showing the variables, it is unavoidable that those
-# variables requiring ${WRKDIR} to exist will show a warning.
-#
-       @value=${${v}:M*:Q};                                            \
-       if [ "$$value" ]; then                                          \
-         echo "  ${_LABEL.${c}}        ${v} = $$value";                \
+.      if (${v:M*_ENV}                 \
+       || ${v:M*_ENV.*})
+
+# multi-valued variables, values are sorted
+       ${RUN}                                                          \
+       if ${!defined(${v}) :? true : false}; then                      \
+         printf '  %s\t%s (undefined)\n' ${_LABEL.${c}} ${v:Q};        \
+       elif value=${${v}:U:M*:Q} && test "x$$value" = "x"; then        \
+         printf '  %s\t%s = # empty\n' ${_LABEL.${c}} ${v:Q};          \
        else                                                            \
-         echo "  ${_LABEL.${c}}        ${v} (defined, but empty)";     \
+         printf '  %s\t%s (sorted) = \\\n' ${_LABEL.${c}} ${v:Q};      \
+         printf '  \t\t%s \\\n' ${${v}:O:@x@${x:Q}@};                  \
+         printf '  \t\t# end of %s\n' ${v:Q};                          \
        fi
+
+.      elif (${v:M*_ARGS}              \
+       || ${v:M*_ARGS.*}               \
+       || ${v:M*_CMD}                  \
+       || ${v:M*_CMD_DEFAULT}          \
+       || ${v:M*_SKIP}                 \
+       || ${v:MMASTER_SITE*}           \
+       || ${v:MSUBST_FILES.*}          \
+       || ${v:MSUBST_SED.*}            \
+       || ${v:MSUBST_FILTER_CMD.*}     \
+       || ${v:M*_SUBST})
+
+# multi-valued variables, preserving original order
+       ${RUN}                                                          \
+       if ${!defined(${v}) :? true : false}; then                      \
+         printf '  %s\t%s (undefined)\n' ${_LABEL.${c}} ${v:Q};        \
+       elif value=${${v}:U:M*:Q} && test "x$$value" = "x"; then        \
+         printf '  %s\t%s = # empty\n' ${_LABEL.${c}} ${v:Q};          \
+       else                                                            \
+         printf '  %s\t%s = \\\n' ${_LABEL.${c}} ${v:Q};               \
+         printf '  \t\t%s \\\n' ${${v}:@x@${x:Q}@};                    \
+         printf '  \t\t# end of %s\n' ${v:Q};                          \
+       fi
+
 .      else
-       @echo "  ${_LABEL.${c}} ${v} (undefined)"
+
+# single-valued variables
+       ${RUN}                                                          \
+       if ${!defined(${v}) :? true : false}; then                      \
+         printf '  %s\t%s (undefined)\n' ${_LABEL.${c}} ${v:Q};        \
+       elif value=${${v}:U:Q} && test "x$$value" = "x"; then           \
+         printf '  %s\t%s = # empty\n' ${_LABEL.${c}} ${v:Q};          \
+       else                                                            \
+         printf '  %s\t%s = %s\n' ${_LABEL.${c}} ${v:Q} "$$value";     \
+       fi
+
 .      endif
 .    endfor
 .  endfor
-       @echo ""
+       ${RUN} printf '\n'
 .endfor
 
 .PHONY: show-depends-options
diff -r 232cd96f976a -r d829db425303 regress/Makefile
--- a/regress/Makefile  Sat Nov 10 10:01:21 2018 +0000
+++ b/regress/Makefile  Sat Nov 10 10:40:55 2018 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.20 2018/11/09 06:48:27 rillig Exp $
+# $NetBSD: Makefile,v 1.21 2018/11/10 10:40:55 rillig Exp $
 #
 # See https://www.netbsd.org/docs/pkgsrc/regression.html for more
 # information about these tests.
@@ -20,6 +20,7 @@
 SUBDIR+=       pkg-options
 SUBDIR+=       pkgfail
 SUBDIR+=       print-plist
+SUBDIR+=       show-all
 SUBDIR+=       subst
 SUBDIR+=       tools
 
diff -r 232cd96f976a -r d829db425303 regress/show-all/DESCR
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/show-all/DESCR    Sat Nov 10 10:40:55 2018 +0000
@@ -0,0 +1,5 @@
+Ensures that the show-all target prints all variants of variable values
+as intended. This involves sorted multi-valued variables (like
+CONFIGURE_ENV), other multi-valued variables (like CONFIGURE_ARGS),
+variables containing special characters that need to be escaped, and
+various other edge cases.
diff -r 232cd96f976a -r d829db425303 regress/show-all/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/show-all/Makefile Sat Nov 10 10:40:55 2018 +0000
@@ -0,0 +1,35 @@
+# $NetBSD: Makefile,v 1.1 2018/11/10 10:40:56 rillig Exp $
+
+DISTNAME=      show-all-1.0
+CATEGORIES=    regress
+MASTER_SITES=  # none
+DISTFILES=     # none
+
+MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
+COMMENT=       Demonstrates the show-all target
+LICENSE=       2-clause-bsd
+
+REGRESS.empty=         # empty
+REGRESS.value=         All * kinds of `strange' \escape $$characters
+
+REGRESS_ENV.empty=     # empty
+REGRESS_ENV.space=     # initially empty
+REGRESS_ENV.space+=    # now it contains a single space
+REGRESS_ENV.value=     VAR1=value1 VAR2=`command execution via backticks` *=all
+
+REGRESS_ARGS.empty=    # empty
+REGRESS_ARGS.space=    # initially empty
+REGRESS_ARGS.space+=   # now it contains a single space
+REGRESS_ARGS.value=    VAR1=value1 VAR2=`command execution via backticks` *=all
+
+# Variable names may also contain special characters that must be escaped.
+*=                     bmake built-in
+**=                    asterisk
+
+_VARGROUPS+=           regress
+_PKG_VARS.regress+=    REGRESS.undefined REGRESS.empty REGRESS.value
+_PKG_VARS.regress+=    REGRESS_ENV.undefined REGRESS_ENV.empty REGRESS_ENV.space REGRESS_ENV.value
+_PKG_VARS.regress+=    REGRESS_ARGS.undefined REGRESS_ARGS.empty REGRESS_ARGS.space REGRESS_ARGS.value
+_PKG_VARS.regress+=    * **
+
+.include "../../mk/bsd.pkg.mk"
diff -r 232cd96f976a -r d829db425303 regress/show-all/PLIST
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/show-all/PLIST    Sat Nov 10 10:40:55 2018 +0000
@@ -0,0 +1,2 @@
+@comment $NetBSD: PLIST,v 1.1 2018/11/10 10:40:56 rillig Exp $
+@comment intentionally empty
diff -r 232cd96f976a -r d829db425303 regress/show-all/spec
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/show-all/spec     Sat Nov 10 10:40:55 2018 +0000
@@ -0,0 +1,70 @@
+# $NetBSD: spec,v 1.1 2018/11/10 10:40:56 rillig Exp $
+
+tmpdir=${TMPDIR:-/tmp}/pkgsrc-show-all
+rm -rf "$tmpdir"
+mkdir -p "$tmpdir"
+
+require_file() {
+       if diff -u "$3" "$1" > /dev/null; then
+               :
+       else
+               regress_fail "Expected files to be equal."
+               diff -u "$3" "$1" || true
+       fi
+}
+
+
+do_test() {
+       $TEST_MAKE show-all-regress > "$tmpdir/show-all-regress.out"
+}
+
+check_result() {
+       exit_status 0
+
+       cat <<'EOF' > "$tmpdir/expected"
+regress:
+  pkg  REGRESS.undefined (undefined)
+  pkg  REGRESS.empty = # empty
+  pkg  REGRESS.value = All * kinds of `strange' \escape $characters
+  pkg  REGRESS_ENV.undefined (undefined)
+  pkg  REGRESS_ENV.empty = # empty
+  pkg  REGRESS_ENV.space = # empty
+  pkg  REGRESS_ENV.value (sorted) = \
+               *=all \
+               VAR1=value1 \
+               VAR2=`command \
+               backticks` \
+               execution \
+               via \
+               # end of REGRESS_ENV.value
+  pkg  REGRESS_ARGS.undefined (undefined)
+  pkg  REGRESS_ARGS.empty = # empty
+  pkg  REGRESS_ARGS.space = # empty
+  pkg  REGRESS_ARGS.value = \
+               VAR1=value1 \
+               VAR2=`command \
+               execution \
+               via \
+               backticks` \
+               *=all \
+               # end of REGRESS_ARGS.value
+  pkg  * = show-all-regress
+  pkg  ** = asterisk
+
+EOF
+
+       # The "*" variable is built-in into bmake and expands to the current
+       # make target, which in this case is "show-all-regress".
+
+       # The "**" variable ensures that show-all doesn't accidentally expand
+       # filenames.
+
+       # It's a bit strange that bmake doesn't handle the backticks command
+       # as a single word. Luckily, this is a rare case.
+       #
+       # On the other hand, if it did, bmake would also have to handle
+       # variable expansion and all the other syntactic difficulties from
+       # parsing shell commands, and that would be just too much.
+
+       require_file "$tmpdir/show-all-regress.out" --equals "$tmpdir/expected"
+}



Home | Main Index | Thread Index | Old Index