Sat Mar 21 13:30:35 2020 UTC ()
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.


(rillig)
diff -r1.66 -r1.67 pkgsrc/mk/subst.mk
diff -r1.9 -r1.10 pkgsrc/regress/infra-unittests/subst.sh

cvs diff -r1.66 -r1.67 pkgsrc/mk/subst.mk (expand / switch to unified diff)

--- pkgsrc/mk/subst.mk 2020/03/21 12:22:31 1.66
+++ pkgsrc/mk/subst.mk 2020/03/21 13:30:35 1.67
@@ -1,30 +1,36 @@ @@ -1,30 +1,36 @@
1# $NetBSD: subst.mk,v 1.66 2020/03/21 12:22:31 rillig Exp $ 1# $NetBSD: subst.mk,v 1.67 2020/03/21 13:30:35 rillig Exp $
2# 2#
3# The subst framework replaces text in one or more files in the WRKSRC 3# The subst framework replaces text in one or more files in the WRKSRC
4# directory. Packages can define several ``classes'' of replacements. 4# directory. Packages can define several ``classes'' of replacements.
5# Each such class defines: 5# Each such class defines:
6# 6#
7# - in which stage of the build process the replacement happens 7# - in which stage of the build process the replacement happens
8# - which files are affected by the replacement 8# - which files are affected by the replacement
9# - which text or pattern is replaced by which replacement text 9# - which text or pattern is replaced by which replacement text
10# 10#
11# A typical example is: 11# A typical example is:
12# 12#
13# SUBST_CLASSES+= prefix 13# SUBST_CLASSES+= prefix
14# SUBST_STAGE.prefix= pre-configure 14# SUBST_STAGE.prefix= pre-configure
15# SUBST_FILES.prefix= ./configure doc/*.html 15# SUBST_FILES.prefix= ./configure doc/*.html
16# SUBST_SED.prefix= -e 's,/usr/local,${PREFIX},g' 16# SUBST_SED.prefix= -e 's,/usr/local,${PREFIX},g'
17# 17#
 18# User-settable variables:
 19#
 20# SUBST_SHOW_DIFF
 21# Whether to log each changed file as a unified diff, for all
 22# SUBST classes. Defaults to "no".
 23#
18# Package-settable variables: 24# Package-settable variables:
19# 25#
20# SUBST_CLASSES 26# SUBST_CLASSES
21# A list of class names. When adding new classes to this list, be 27# A list of class names. When adding new classes to this list, be
22# sure to append them (+=) instead of overriding them (=). 28# sure to append them (+=) instead of overriding them (=).
23# 29#
24# SUBST_STAGE.<class> 30# SUBST_STAGE.<class>
25# "stage" at which we do the text replacement. Should be one of 31# "stage" at which we do the text replacement. Should be one of
26# {pre,do,post}-{extract,patch,configure,build,install}. 32# {pre,do,post}-{extract,patch,configure,build,install}.
27# 33#
28# SUBST_MESSAGE.<class> 34# SUBST_MESSAGE.<class>
29# The message to display before doing the substitution. 35# The message to display before doing the substitution.
30# 36#
@@ -72,26 +78,27 @@ @@ -72,26 +78,27 @@
72# In most cases, "yes" is appropriate, to catch typos and outdated 78# In most cases, "yes" is appropriate, to catch typos and outdated
73# definitions. 79# definitions.
74# 80#
75# Default: no (up to 2019Q4), yes (starting with 2020Q1) 81# Default: no (up to 2019Q4), yes (starting with 2020Q1)
76# 82#
77# See also: 83# See also:
78# PLIST_SUBST 84# PLIST_SUBST
79# 85#
80# Keywords: subst 86# Keywords: subst
81# 87#
82 88
83_VARGROUPS+= subst 89_VARGROUPS+= subst
84_PKG_VARS.subst= SUBST_CLASSES 90_PKG_VARS.subst= SUBST_CLASSES
 91SUBST_SHOW_DIFF?= no
85.for c in ${SUBST_CLASSES} 92.for c in ${SUBST_CLASSES}
86. for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \ 93. for pv in SUBST_STAGE SUBST_MESSAGE SUBST_FILES SUBST_SED SUBST_VARS \
87 SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK 94 SUBST_FILTER_CMD SUBST_SKIP_TEXT_CHECK SUBST_NOOP_OK
88_PKG_VARS.subst+= ${pv}.${c} 95_PKG_VARS.subst+= ${pv}.${c}
89. endfor 96. endfor
90.endfor 97.endfor
91_DEF_VARS.subst= ECHO_SUBST_MSG 98_DEF_VARS.subst= ECHO_SUBST_MSG
92_USE_VARS.subst= WRKDIR WRKSRC 99_USE_VARS.subst= WRKDIR WRKSRC
93_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD 100_IGN_VARS.subst= _SUBST_IS_TEXT_FILE_CMD
94_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.* 101_SORTED_VARS.subst= SUBST_CLASSES SUBST_FILES.* SUBST_VARS.*
95_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.* 102_LISTED_VARS.subst= SUBST_SED.* SUBST_FILTER_CMD.*
96 103
97ECHO_SUBST_MSG?= ${STEP_MSG} 104ECHO_SUBST_MSG?= ${STEP_MSG}
@@ -103,27 +110,27 @@ _SUBST_IS_TEXT_FILE_CMD?= \ @@ -103,27 +110,27 @@ _SUBST_IS_TEXT_FILE_CMD?= \
103.if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u} 110.if ${SUBST_CLASSES:U:O} != ${SUBST_CLASSES:U:O:u}
104PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}" 111PKG_FAIL_REASON+= "[subst.mk] duplicate SUBST class in: ${SUBST_CLASSES:O}"
105.endif 112.endif
106 113
107.for _class_ in ${SUBST_CLASSES:O:u} 114.for _class_ in ${SUBST_CLASSES:O:u}
108_SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done 115_SUBST_COOKIE.${_class_}= ${WRKDIR}/.subst_${_class_}_done
109 116
110SUBST_FILTER_CMD.${_class_}?= LC_ALL=C ${SED} ${SUBST_SED.${_class_}} 117SUBST_FILTER_CMD.${_class_}?= LC_ALL=C ${SED} ${SUBST_SED.${_class_}}
111SUBST_VARS.${_class_}?= # none 118SUBST_VARS.${_class_}?= # none
112SUBST_MESSAGE.${_class_}?= Substituting "${_class_}" in ${SUBST_FILES.${_class_}} 119SUBST_MESSAGE.${_class_}?= Substituting "${_class_}" in ${SUBST_FILES.${_class_}}
113. for v in ${SUBST_VARS.${_class_}} 120. for v in ${SUBST_VARS.${_class_}}
114SUBST_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 121SUBST_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
115. endfor 122. endfor
116. if !empty(SUBST_SHOW_DIFF.${_class_}:Uno:M[Yy][Ee][Ss]) 123. if ${SUBST_SHOW_DIFF.${_class_}:U${SUBST_SHOW_DIFF}:tl} == yes
117_SUBST_KEEP.${_class_}?= ${DIFF} -u "$$file" "$$tmpfile" || true 124_SUBST_KEEP.${_class_}?= ${DIFF} -u "$$file" "$$tmpfile" || true
118. endif 125. endif
119_SUBST_KEEP.${_class_}?= ${DO_NADA} 126_SUBST_KEEP.${_class_}?= ${DO_NADA}
120SUBST_SKIP_TEXT_CHECK.${_class_}?= no 127SUBST_SKIP_TEXT_CHECK.${_class_}?= no
121SUBST_NOOP_OK.${_class_}?= yes # TODO: change to no after 2020Q1 128SUBST_NOOP_OK.${_class_}?= yes # TODO: change to no after 2020Q1
122 129
123.if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss]) 130.if !empty(SUBST_SKIP_TEXT_CHECK.${_class_}:M[Yy][Ee][Ss])
124_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${TRUE} 131_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${TRUE}
125.else 132.else
126_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${_SUBST_IS_TEXT_FILE_CMD} 133_SUBST_IS_TEXT_FILE_CMD.${_class_}= ${_SUBST_IS_TEXT_FILE_CMD}
127.endif 134.endif
128 135
129. if defined(SUBST_STAGE.${_class_}) 136. if defined(SUBST_STAGE.${_class_})

cvs diff -r1.9 -r1.10 pkgsrc/regress/infra-unittests/subst.sh (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/subst.sh 2020/03/21 12:47:13 1.9
+++ pkgsrc/regress/infra-unittests/subst.sh 2020/03/21 13:30:35 1.10
@@ -617,13 +617,54 @@ EOF @@ -617,13 +617,54 @@ EOF
617 "=> Substituting \"two\" in file" \ 617 "=> Substituting \"two\" in file" \
618 "--- ./file (filtered timestamp)" \ 618 "--- ./file (filtered timestamp)" \
619 "+++ ./file.subst.sav (filtered timestamp)" \ 619 "+++ ./file.subst.sav (filtered timestamp)" \
620 "@@ -1,3 +1,3 @@" \ 620 "@@ -1,3 +1,3 @@" \
621 " one" \ 621 " one" \
622 "-two" \ 622 "-two" \
623 "+II" \ 623 "+II" \
624 " three" 624 " three"
625 assert_that "stderr" --file-is-empty 625 assert_that "stderr" --file-is-empty
626 assert_that "$exitcode" --equals 0 626 assert_that "$exitcode" --equals 0
627 627
628 test_case_end 628 test_case_end
629fi 629fi
 630
 631
 632if test_case_begin "global show diff"; then
 633
 634 create_file_lines "file" "one" "two" "three"
 635
 636 create_file "testcase.mk" <<EOF
 637SUBST_CLASSES+= two
 638SUBST_STAGE.two= pre-configure
 639SUBST_FILES.two= file
 640SUBST_SED.two= -e 's,two,II,'
 641SUBST_SHOW_DIFF= yes
 642
 643.include "prepare-subst.mk"
 644.include "mk/subst.mk"
 645EOF
 646
 647 LC_ALL=C \
 648 test_file "testcase.mk" "pre-configure" \
 649 1> "$tmpdir/stdout" \
 650 2> "$tmpdir/stderr" \
 651 && exitcode=0 || exitcode=$?
 652
 653 awk '{ if (/^... \.\/.*/) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \
 654 < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
 655
 656 assert_that "file" --file-is-lines "one" "II" "three"
 657 assert_that "stdout-filtered" --file-is-lines \
 658 "=> Substituting \"two\" in file" \
 659 "--- ./file (filtered timestamp)" \
 660 "+++ ./file.subst.sav (filtered timestamp)" \
 661 "@@ -1,3 +1,3 @@" \
 662 " one" \
 663 "-two" \
 664 "+II" \
 665 " three"
 666 assert_that "stderr" --file-is-empty
 667 assert_that "$exitcode" --equals 0
 668
 669 test_case_end
 670fi