Sat Apr 18 12:59:43 2020 UTC ()
mk/subst.mk: make error message for filename pattern easier readable


(rillig)
diff -r1.77 -r1.78 pkgsrc/mk/subst.mk
diff -r1.16 -r1.17 pkgsrc/regress/infra-unittests/subst.sh

cvs diff -r1.77 -r1.78 pkgsrc/mk/subst.mk (expand / switch to unified diff)

--- pkgsrc/mk/subst.mk 2020/04/18 12:21:10 1.77
+++ pkgsrc/mk/subst.mk 2020/04/18 12:59:43 1.78
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: subst.mk,v 1.77 2020/04/18 12:21:10 rillig Exp $ 1# $NetBSD: subst.mk,v 1.78 2020/04/18 12:59:43 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
@@ -183,19 +183,19 @@ ${_SUBST_COOKIE.${class}}: @@ -183,19 +183,19 @@ ${_SUBST_COOKIE.${class}}:
183 ${RM} -f "$$tmpfile"; \ 183 ${RM} -f "$$tmpfile"; \
184 else \ 184 else \
185 changed=yes; \ 185 changed=yes; \
186 ${_SUBST_KEEP.${class}}; \ 186 ${_SUBST_KEEP.${class}}; \
187 ${MV} -f "$$tmpfile" "$$file"; \ 187 ${MV} -f "$$tmpfile" "$$file"; \
188 ${ECHO} "$$file" >> ${.TARGET}.tmp; \ 188 ${ECHO} "$$file" >> ${.TARGET}.tmp; \
189 fi; \ 189 fi; \
190 else \ 190 else \
191 ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \ 191 ${_SUBST_WARN.${class}} "Ignoring non-text file \"$$file\"."; \
192 fi; \ 192 fi; \
193 done; \ 193 done; \
194 \ 194 \
195 if ${TEST} "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no; then \ 195 if ${TEST} "$$changed,${SUBST_NOOP_OK.${class}:tl}" = no,no; then \
196 ${FAIL_MSG} "[subst.mk:${class}] The pattern $$pattern has no effect."; \ 196 ${FAIL_MSG} "[subst.mk:${class}] The filename pattern \"$$pattern\" has no effect."; \
197 fi; \ 197 fi; \
198 done; \ 198 done; \
199 cd ${WRKDIR}; ${RMDIR} "$$emptydir" 199 cd ${WRKDIR}; ${RMDIR} "$$emptydir"
200 ${RUN} ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET} 200 ${RUN} ${TOUCH} ${TOUCH_FLAGS} ${.TARGET}.tmp && ${MV} ${.TARGET}.tmp ${.TARGET}
201.endfor 201.endfor

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

--- pkgsrc/regress/infra-unittests/subst.sh 2020/04/18 12:21:10 1.16
+++ pkgsrc/regress/infra-unittests/subst.sh 2020/04/18 12:59:42 1.17
@@ -213,27 +213,27 @@ SUBST_NOOP_OK.class= no @@ -213,27 +213,27 @@ SUBST_NOOP_OK.class= no
213.include "prepare-subst.mk" 213.include "prepare-subst.mk"
214.include "mk/subst.mk" 214.include "mk/subst.mk"
215 215
216all: subst-class 216all: subst-class
217EOF 217EOF
218 218
219 create_file_lines "single" "already an example" 219 create_file_lines "single" "already an example"
220 220
221 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 221 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
222 222
223 create_file_lines "expected-output" \ 223 create_file_lines "expected-output" \
224 '=> Substituting "class" in single' \ 224 '=> Substituting "class" in single' \
225 'warning: [subst.mk:class] Nothing changed in ./single.' \ 225 'warning: [subst.mk:class] Nothing changed in ./single.' \
226 'fail: [subst.mk:class] The pattern single has no effect.' \ 226 'fail: [subst.mk:class] The filename pattern "single" has no effect.' \
227 '*** Error code 1' \ 227 '*** Error code 1' \
228 '' \ 228 '' \
229 'Stop.' \ 229 'Stop.' \
230 "$make: stopped in $PWD" 230 "$make: stopped in $PWD"
231 assert_that "actual-output" --file-equals "expected-output" 231 assert_that "actual-output" --file-equals "expected-output"
232 assert_that "single" --file-contains-exactly "already an example" 232 assert_that "single" --file-contains-exactly "already an example"
233 assert_that "$exitcode" --equals "1" 233 assert_that "$exitcode" --equals "1"
234 234
235 test_case_end 235 test_case_end
236fi 236fi
237 237
238 238
239if test_case_begin "single file nonexistent"; then 239if test_case_begin "single file nonexistent"; then
@@ -246,27 +246,27 @@ SUBST_SED.class= -e 's,file,example,' @@ -246,27 +246,27 @@ SUBST_SED.class= -e 's,file,example,'
246SUBST_NOOP_OK.class= no 246SUBST_NOOP_OK.class= no
247 247
248.include "prepare-subst.mk" 248.include "prepare-subst.mk"
249.include "mk/subst.mk" 249.include "mk/subst.mk"
250 250
251all: subst-class 251all: subst-class
252EOF 252EOF
253 253
254 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 254 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$?
255 255
256 create_file_lines "expected-output" \ 256 create_file_lines "expected-output" \
257 '=> Substituting "class" in nonexistent' \ 257 '=> Substituting "class" in nonexistent' \
258 'warning: [subst.mk:class] Ignoring non-existent file "./nonexistent".' \ 258 'warning: [subst.mk:class] Ignoring non-existent file "./nonexistent".' \
259 'fail: [subst.mk:class] The pattern nonexistent has no effect.' \ 259 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \
260 '*** Error code 1' \ 260 '*** Error code 1' \
261 '' \ 261 '' \
262 'Stop.' \ 262 'Stop.' \
263 "$make: stopped in $PWD" 263 "$make: stopped in $PWD"
264 assert_that "actual-output" --file-equals "expected-output" 264 assert_that "actual-output" --file-equals "expected-output"
265 assert_that "$exitcode" --equals "1" 265 assert_that "$exitcode" --equals "1"
266 266
267 test_case_end 267 test_case_end
268fi 268fi
269 269
270 270
271if test_case_begin "single file nonexistent ok"; then 271if test_case_begin "single file nonexistent ok"; then
272 272
@@ -874,55 +874,51 @@ if test_case_begin "pattern matches dire @@ -874,55 +874,51 @@ if test_case_begin "pattern matches dire
874 assert_that "stdout" --file-is-lines \ 874 assert_that "stdout" --file-is-lines \
875 "=> Substituting \"dir\" in sub*" 875 "=> Substituting \"dir\" in sub*"
876 assert_that "stderr" --file-is-empty 876 assert_that "stderr" --file-is-empty
877 assert_that "$exitcode" --equals 0 877 assert_that "$exitcode" --equals 0
878 878
879 test_case_end 879 test_case_end
880fi 880fi
881 881
882 882
883if test_case_begin "pattern matches only directory"; then 883if test_case_begin "pattern matches only directory"; then
884 884
885 # When a pattern matches a directory, that directory is silently 885 # When a pattern matches a directory, that directory is silently
886 # skipped. 886 # skipped.
887 # 
888 # In this test case, the pattern also matches a regular file that 
889 # is actually modified. Therefore the pattern has an effect, and 
890 # there is no error message. 
891 887
892 create_file_lines "testcase.mk" \ 888 create_file_lines "testcase.mk" \
893 'SUBST_CLASSES+= dir' \ 889 'SUBST_CLASSES+= dir' \
894 'SUBST_STAGE.dir= pre-configure' \ 890 'SUBST_STAGE.dir= pre-configure' \
895 'SUBST_FILES.dir= sub*' \ 891 'SUBST_FILES.dir= sub*' \
896 'SUBST_VARS.dir= VAR' \ 892 'SUBST_VARS.dir= VAR' \
897 'SUBST_NOOP_OK.dir= no' \ 893 'SUBST_NOOP_OK.dir= no' \
898 '' \ 894 '' \
899 'VAR= value' \ 895 'VAR= value' \
900 '' \ 896 '' \
901 '.include "prepare-subst.mk"' \ 897 '.include "prepare-subst.mk"' \
902 '.include "mk/subst.mk"' 898 '.include "mk/subst.mk"'
903 mkdir "$tmpdir/subdir" 899 mkdir "$tmpdir/subdir"
904 create_file_lines "subdir/subfile" \ 900 create_file_lines "subdir/subfile" \
905 "@VAR@" 901 "@VAR@"
906 902
907 run_bmake "testcase.mk" "pre-configure" \ 903 run_bmake "testcase.mk" "pre-configure" \
908 1> "$tmpdir/stdout" \ 904 1> "$tmpdir/stdout" \
909 2> "$tmpdir/stderr" \ 905 2> "$tmpdir/stderr" \
910 && exitcode=0 || exitcode=$? 906 && exitcode=0 || exitcode=$?
911 907
912 assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged 908 assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged
913 assert_that "stdout" --file-is-lines \ 909 assert_that "stdout" --file-is-lines \
914 "=> Substituting \"dir\" in sub*" \ 910 "=> Substituting \"dir\" in sub*" \
915 "fail: [subst.mk:dir] The pattern sub* has no effect." \ 911 'fail: [subst.mk:dir] The filename pattern "sub*" has no effect.' \
916 "*** Error code 1" \ 912 "*** Error code 1" \
917 "" \ 913 "" \
918 "Stop." \ 914 "Stop." \
919 "$make: stopped in $PWD" 915 "$make: stopped in $PWD"
920 assert_that "stderr" --file-is-empty 916 assert_that "stderr" --file-is-empty
921 assert_that "$exitcode" --equals 1 917 assert_that "$exitcode" --equals 1
922 918
923 test_case_end 919 test_case_end
924fi 920fi
925 921
926 922
927if test_case_begin "first filename pattern has no effect"; then 923if test_case_begin "first filename pattern has no effect"; then
928 924
@@ -939,21 +935,21 @@ if test_case_begin "first filename patte @@ -939,21 +935,21 @@ if test_case_begin "first filename patte
939 'B= b-value' \ 935 'B= b-value' \
940 '' \ 936 '' \
941 '.include "prepare-subst.mk"' \ 937 '.include "prepare-subst.mk"' \
942 '.include "mk/subst.mk"' 938 '.include "mk/subst.mk"'
943 create_file_lines "file1" "nothing to replace" 939 create_file_lines "file1" "nothing to replace"
944 create_file_lines "file2" "nothing to replace" 940 create_file_lines "file2" "nothing to replace"
945 941
946 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ 942 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \
947 && exitcode=0 || exitcode=$? 943 && exitcode=0 || exitcode=$?
948 944
949 assert_that "out" --file-is-lines \ 945 assert_that "out" --file-is-lines \
950 '=> Substituting "id" in file1 file2' \ 946 '=> Substituting "id" in file1 file2' \
951 'warning: [subst.mk:id] Nothing changed in ./file1.' \ 947 'warning: [subst.mk:id] Nothing changed in ./file1.' \
952 'fail: [subst.mk:id] The pattern file1 has no effect.' \ 948 'fail: [subst.mk:id] The filename pattern "file1" has no effect.' \
953 '*** Error code 1' \ 949 '*** Error code 1' \
954 '' \ 950 '' \
955 'Stop.' \ 951 'Stop.' \
956 "$make: stopped in $PWD" 952 "$make: stopped in $PWD"
957 953
958 test_case_end 954 test_case_end
959fi 955fi