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.
This commit is contained in:
parent
f475294eb1
commit
8e82112864
2 changed files with 50 additions and 2 deletions
11
mk/subst.mk
11
mk/subst.mk
|
@ -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 @@ SUBST_MESSAGE.${_class_}?= Substituting "${_class_}" in ${SUBST_FILES.${_class_}
|
|||
. 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}
|
||||
|
|
|
@ -627,3 +627,44 @@ EOF
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue