pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc mk/subst.mk: use the same severity for all messages



details:   https://anonhg.NetBSD.org/pkgsrc/rev/949d554e1190
branches:  trunk
changeset: 413789:949d554e1190
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sun Mar 22 12:15:59 2020 +0000

description:
mk/subst.mk: use the same severity for all messages

The severity now depends only on the setting of SUBST_NOOP_OK. Right now
this means that some former warnings will be reported as info only, but
that will change after switching the default of SUBST_NOOP_OK after
2020Q1. Then they will all be reported as warnings, followed by the final
error saying that the pattern has no effect.

This change makes it easier to detect inconsistencies and outdated
definitions, for example by setting the global SUBST_NOOP_OK=no and
redefining WARNING_MSG to actuall fail.

diffstat:

 mk/subst.mk                       |   9 +++++----
 regress/infra-unittests/subst.sh  |  12 ++++++------
 regress/infra-unittests/test.subr |  34 ++++++++++++++++++++++------------
 3 files changed, 33 insertions(+), 22 deletions(-)

diffs (170 lines):

diff -r b5b616e0a045 -r 949d554e1190 mk/subst.mk
--- a/mk/subst.mk       Sun Mar 22 11:41:19 2020 +0000
+++ b/mk/subst.mk       Sun Mar 22 12:15:59 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.68 2020/03/21 19:26:12 rillig Exp $
+# $NetBSD: subst.mk,v 1.69 2020/03/22 12:15:59 rillig Exp $
 #
 # The subst framework replaces text in one or more files in the WRKSRC
 # directory. Packages can define several ``classes'' of replacements.
@@ -126,6 +126,7 @@
 _SUBST_KEEP.${_class_}?=       ${DO_NADA}
 SUBST_SKIP_TEXT_CHECK.${_class_}?=     no
 SUBST_NOOP_OK.${_class_}?=     yes # TODO: change to no after 2020Q1
+_SUBST_WARN.${_class_}=                ${${SUBST_NOOP_OK.${_class_}:tl} == yes:?${INFO_MSG}:${WARNING_MSG}} "[subst.mk:${_class_}]"
 
 .if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss])
 _SUBST_IS_TEXT_FILE_CMD.${_class_}=    ${TRUE}
@@ -158,7 +159,7 @@
                case $$file in /*) ;; *) file="./$$file";; esac;        \
                tmpfile="$$file.subst.sav";                             \
                if [ ! -f "$$file" ]; then                              \
-                       ${WARNING_MSG} "[subst.mk:${_class_}] Ignoring non-existent file \"$$file\"."; \
+                       ${_SUBST_WARN.${_class_}} "Ignoring non-existent file \"$$file\"."; \
                elif ${_SUBST_IS_TEXT_FILE_CMD.${_class_}}; then        \
                        ${SUBST_FILTER_CMD.${_class_}}                  \
                        < "$$file"                                      \
@@ -167,7 +168,7 @@
                                ${CHMOD} +x "$$tmpfile";                \
                        fi;                                             \
                        if ${CMP} -s "$$tmpfile" "$$file"; then         \
-                               ${INFO_MSG} "[subst.mk:${_class_}] Nothing changed in $$file."; \
+                               ${_SUBST_WARN.${_class_}} "Nothing changed in $$file."; \
                                ${RM} -f "$$tmpfile";                   \
                        else                                            \
                                changed=yes;                            \
@@ -176,7 +177,7 @@
                                ${ECHO} "$$file" >> ${.TARGET};         \
                        fi;                                             \
                else                                                    \
-                       ${WARNING_MSG} "[subst.mk:${_class_}] Ignoring non-text file \"$$file\"."; \
+                       ${_SUBST_WARN.${_class_}} "Ignoring non-text file \"$$file\"."; \
                fi;                                                     \
        done;                                                           \
        \
diff -r b5b616e0a045 -r 949d554e1190 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Sun Mar 22 11:41:19 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Sun Mar 22 12:15:59 2020 +0000
@@ -222,7 +222,7 @@
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in single' \
-               'info: [subst.mk:class] Nothing changed in ./single.' \
+               'warning: [subst.mk:class] Nothing changed in ./single.' \
                'fail: [subst.mk:class] The pattern single has no effect.' \
                '*** Error code 1' \
                '' \
@@ -287,7 +287,7 @@
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in nonexistent' \
-               'warning: [subst.mk:class] Ignoring non-existent file "./nonexistent".'
+               'info: [subst.mk:class] Ignoring non-existent file "./nonexistent".'
        assert_that "actual-output" --file-equals "expected-output"
        assert_that "$exitcode" --equals "0"
 
@@ -315,7 +315,7 @@
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in *exist* *not-found*' \
-               'warning: [subst.mk:class] Ignoring non-existent file "./*not-found*".'
+               'info: [subst.mk:class] Ignoring non-existent file "./*not-found*".'
        assert_that "actual-output" --file-equals "expected-output"
        assert_that "exists" --file-contains-exactly "this example exists"
        assert_that "$exitcode" --equals "0"
@@ -340,9 +340,9 @@
 
        create_file_lines "expected-output" \
                '=> Substituting "class" in does not exist' \
-               'warning: [subst.mk:class] Ignoring non-existent file "./does".' \
-               'warning: [subst.mk:class] Ignoring non-existent file "./not".' \
-               'warning: [subst.mk:class] Ignoring non-existent file "./exist".'
+               'info: [subst.mk:class] Ignoring non-existent file "./does".' \
+               'info: [subst.mk:class] Ignoring non-existent file "./not".' \
+               'info: [subst.mk:class] Ignoring non-existent file "./exist".'
        assert_that "actual-output" --file-equals "expected-output"
        assert_that "$exitcode" --equals "0"
 
diff -r b5b616e0a045 -r 949d554e1190 regress/infra-unittests/test.subr
--- a/regress/infra-unittests/test.subr Sun Mar 22 11:41:19 2020 +0000
+++ b/regress/infra-unittests/test.subr Sun Mar 22 12:15:59 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: test.subr,v 1.6 2020/03/21 18:43:02 rillig Exp $
+# $NetBSD: test.subr,v 1.7 2020/03/22 12:15:59 rillig Exp $
 set -eu
 
 # This file defines utilities for testing Makefile fragments in a mocked
@@ -206,6 +206,17 @@
        assert_failed=`expr "$assert_failed" + 1`
 }
 
+tmpdir_equal() {
+       (cd "$tmpdir" && diff -u -- "$@" >/dev/null) || return 1
+}
+
+tmpdir_diff() {
+       # removes the timestamps from the diff files since these are not
+       # useful in tests.
+       (cd "$tmpdir" && diff -u -- "$@" || true) \
+       | awk '/^(---|[+][+][+]) / { print($1, $2); next } { print }' 1>&2
+}
+
 assert_that() {
        case "$2" in
        (--equals)
@@ -218,44 +229,43 @@
 
        (--file-contains-exactly)
                printf '%s\n' "$3" > "$tmpdir/expected"
-               if diff -u "$tmpdir/expected" "$tmpdir/$1" > /dev/null; then
+               if tmpdir_equal "expected" "$1"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'file "%s" has unexpected content:\n' "$1"
-               diff -u "$tmpdir/expected" "$tmpdir/$1" 1>&2 || true
+               tmpdir_diff "expected" "$1"
                ;;
 
        (--file-equals)
-               if diff -u "$tmpdir/$3" "$tmpdir/$1" > /dev/null; then
+               if tmpdir_equal "$3" "$1"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'files "%s" and "%s" differ:\n' "$1" "$3"
-               diff -u "$tmpdir/$3" "$tmpdir/$1" 1>&2 || true
+               tmpdir_diff "$3" "$1"
                ;;
 
        (--file-is-empty)
-               if diff -u "/dev/null" "$tmpdir/$1" > /dev/null; then
+               if tmpdir_equal "/dev/null" "$1"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'file "%s" is not empty:\n' "$1"
-               diff -u "/dev/null" "$tmpdir/$1" 1>&2 || true
+               tmpdir_diff "/dev/null" "$1"
                ;;
 
        (--file-is-lines)
-               _assert_that_tmp_actual="$tmpdir/$1"
-               _assert_that_tmp_expected="$tmpdir/expected"
+               _assert_that_tmp_actual="$1"
                _assert_that_filename="$1"; shift 2
 
-               printf '%s\n' "$@" > "$_assert_that_tmp_expected"
-               if diff -u "$_assert_that_tmp_expected" "$_assert_that_tmp_actual" > /dev/null; then
+               printf '%s\n' "$@" > "$tmpdir/expected"
+               if tmpdir_equal "expected" "$_assert_that_tmp_actual"; then
                        assert_succeed
                        return 0
                fi
                assert_fail 'file "%s" has unexpected content:\n' "$_assert_that_filename"
-               diff -u "$_assert_that_tmp_expected" "$_assert_that_tmp_actual" 1>&2 || true
+               tmpdir_diff "expected" "$_assert_that_tmp_actual"
                ;;
 
        (*)



Home | Main Index | Thread Index | Old Index