pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc mk/subst.mk: add global SUBST_SHOW_DIFF variable



details:   https://anonhg.NetBSD.org/pkgsrc/rev/0210d992d7fa
branches:  trunk
changeset: 413606:0210d992d7fa
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat Mar 21 13:30:35 2020 +0000

description:
mk/subst.mk: add global SUBST_SHOW_DIFF variable

This is useful in bulk builds or when trying to understand what happens
under the hood, since the SUBST code leaves no .orig files around.

diffstat:

 mk/subst.mk                      |  11 ++++++++-
 regress/infra-unittests/subst.sh |  41 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 2 deletions(-)

diffs (87 lines):

diff -r b2b2e52bf3b0 -r 0210d992d7fa mk/subst.mk
--- a/mk/subst.mk       Sat Mar 21 13:24:06 2020 +0000
+++ b/mk/subst.mk       Sat Mar 21 13:30:35 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.66 2020/03/21 12:22:31 rillig Exp $
+# $NetBSD: subst.mk,v 1.67 2020/03/21 13:30:35 rillig Exp $
 #
 # The subst framework replaces text in one or more files in the WRKSRC
 # directory. Packages can define several ``classes'' of replacements.
@@ -15,6 +15,12 @@
 #      SUBST_FILES.prefix=     ./configure doc/*.html
 #      SUBST_SED.prefix=       -e 's,/usr/local,${PREFIX},g'
 #
+# User-settable variables:
+#
+# SUBST_SHOW_DIFF
+#      Whether to log each changed file as a unified diff, for all
+#      SUBST classes. Defaults to "no".
+#
 # Package-settable variables:
 #
 # SUBST_CLASSES
@@ -82,6 +88,7 @@
 
 _VARGROUPS+=           subst
 _PKG_VARS.subst=       SUBST_CLASSES
+SUBST_SHOW_DIFF?=      no
 .for c in ${SUBST_CLASSES}
 .  for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS        \
        SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK
@@ -113,7 +120,7 @@
 .  for v in ${SUBST_VARS.${_class_}}
 SUBST_FILTER_CMD.${_class_}+=  -e s,@${v:C|[^A-Za-z0-9_]|\\\\&|gW:Q}@,${${v}:S|\\|\\\\|gW:S|,|\\,|gW:S|&|\\\&|gW:S|${.newline}|\\${.newline}|gW:Q},g
 .  endfor
-.  if !empty(SUBST_SHOW_DIFF.${_class_}:Uno:M[Yy][Ee][Ss])
+.  if ${SUBST_SHOW_DIFF.${_class_}:U${SUBST_SHOW_DIFF}:tl} == yes
 _SUBST_KEEP.${_class_}?=       ${DIFF} -u "$$file" "$$tmpfile" || true
 .  endif
 _SUBST_KEEP.${_class_}?=       ${DO_NADA}
diff -r b2b2e52bf3b0 -r 0210d992d7fa regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Sat Mar 21 13:24:06 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Sat Mar 21 13:30:35 2020 +0000
@@ -627,3 +627,44 @@
 
        test_case_end
 fi
+
+
+if test_case_begin "global show diff"; then
+
+       create_file_lines "file" "one" "two" "three"
+
+       create_file "testcase.mk" <<EOF
+SUBST_CLASSES+=                two
+SUBST_STAGE.two=       pre-configure
+SUBST_FILES.two=       file
+SUBST_SED.two=         -e 's,two,II,'
+SUBST_SHOW_DIFF=       yes
+
+.include "prepare-subst.mk"
+.include "mk/subst.mk"
+EOF
+
+       LC_ALL=C \
+       test_file "testcase.mk" "pre-configure" \
+               1> "$tmpdir/stdout" \
+               2> "$tmpdir/stderr" \
+       && exitcode=0 || exitcode=$?
+
+       awk '{ if (/^... \.\/.*/) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \
+       < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
+
+       assert_that "file" --file-is-lines "one" "II" "three"
+       assert_that "stdout-filtered" --file-is-lines \
+               "=> Substituting \"two\" in file" \
+               "--- ./file (filtered timestamp)" \
+               "+++ ./file.subst.sav (filtered timestamp)" \
+               "@@ -1,3 +1,3 @@" \
+               " one" \
+               "-two" \
+               "+II" \
+               " three"
+       assert_that "stderr" --file-is-empty
+       assert_that "$exitcode" --equals 0
+
+       test_case_end
+fi



Home | Main Index | Thread Index | Old Index