mk/subst.mk: ignore directories in SUBST_FILES Seen in multimedia/libmp4v2, where a pattern also matches the CVS directory from the distfiles.diff -r1.69 -r1.70 pkgsrc/mk/subst.mk
(rillig)
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | # $NetBSD: subst.mk,v 1.69 2020/03/22 12:15:59 rillig Exp $ | 1 | # $NetBSD: subst.mk,v 1.70 2020/03/22 13:19:50 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 | |
@@ -149,27 +149,27 @@ ${_SUBST_COOKIE.${_class_}}: | @@ -149,27 +149,27 @@ ${_SUBST_COOKIE.${_class_}}: | |||
149 | if [ "$$message" ]; then ${ECHO_SUBST_MSG} "$$message"; fi | 149 | if [ "$$message" ]; then ${ECHO_SUBST_MSG} "$$message"; fi | |
150 | ${RUN} \ | 150 | ${RUN} \ | |
151 | basedir=${WRKSRC:Q}; \ | 151 | basedir=${WRKSRC:Q}; \ | |
152 | emptydir="$$basedir/.subst-empty"; \ | 152 | emptydir="$$basedir/.subst-empty"; \ | |
153 | patterns=${SUBST_FILES.${_class_}:Q}; \ | 153 | patterns=${SUBST_FILES.${_class_}:Q}; \ | |
154 | ${MKDIR} "$$emptydir"; cd "$$emptydir"; \ | 154 | ${MKDIR} "$$emptydir"; cd "$$emptydir"; \ | |
155 | for pattern in $$patterns; do \ | 155 | for pattern in $$patterns; do \ | |
156 | changed=no; \ | 156 | changed=no; \ | |
157 | cd "$$basedir"; \ | 157 | cd "$$basedir"; \ | |
158 | for file in $$pattern; do \ | 158 | for file in $$pattern; do \ | |
159 | case $$file in /*) ;; *) file="./$$file";; esac; \ | 159 | case $$file in /*) ;; *) file="./$$file";; esac; \ | |
160 | tmpfile="$$file.subst.sav"; \ | 160 | tmpfile="$$file.subst.sav"; \ | |
161 | if [ ! -f "$$file" ]; then \ | 161 | if [ ! -f "$$file" ]; then \ | |
162 | ${_SUBST_WARN.${_class_}} "Ignoring non-existent file \"$$file\"."; \ | 162 | [ -d "$$file" ] || ${_SUBST_WARN.${_class_}} "Ignoring non-existent file \"$$file\"."; \ | |
163 | elif ${_SUBST_IS_TEXT_FILE_CMD.${_class_}}; then \ | 163 | elif ${_SUBST_IS_TEXT_FILE_CMD.${_class_}}; then \ | |
164 | ${SUBST_FILTER_CMD.${_class_}} \ | 164 | ${SUBST_FILTER_CMD.${_class_}} \ | |
165 | < "$$file" \ | 165 | < "$$file" \ | |
166 | > "$$tmpfile"; \ | 166 | > "$$tmpfile"; \ | |
167 | if ${TEST} -x "$$file"; then \ | 167 | if ${TEST} -x "$$file"; then \ | |
168 | ${CHMOD} +x "$$tmpfile"; \ | 168 | ${CHMOD} +x "$$tmpfile"; \ | |
169 | fi; \ | 169 | fi; \ | |
170 | if ${CMP} -s "$$tmpfile" "$$file"; then \ | 170 | if ${CMP} -s "$$tmpfile" "$$file"; then \ | |
171 | ${_SUBST_WARN.${_class_}} "Nothing changed in $$file."; \ | 171 | ${_SUBST_WARN.${_class_}} "Nothing changed in $$file."; \ | |
172 | ${RM} -f "$$tmpfile"; \ | 172 | ${RM} -f "$$tmpfile"; \ | |
173 | else \ | 173 | else \ | |
174 | changed=yes; \ | 174 | changed=yes; \ | |
175 | ${_SUBST_KEEP.${_class_}}; \ | 175 | ${_SUBST_KEEP.${_class_}}; \ |
@@ -828,13 +828,98 @@ if test_case_begin "SUBST_VARS for varia | @@ -828,13 +828,98 @@ if test_case_begin "SUBST_VARS for varia | |||
828 | assert_that "vars.txt" --file-is-lines \ | 828 | assert_that "vars.txt" --file-is-lines \ | |
829 | "dots" \ | 829 | "dots" \ | |
830 | "letters" \ | 830 | "letters" \ | |
831 | "@VAR.()@" \ | 831 | "@VAR.()@" \ | |
832 | "angle brackets" \ | 832 | "angle brackets" \ | |
833 | "@VAR.[]@" | 833 | "@VAR.[]@" | |
834 | assert_that "stdout" --file-is-lines \ | 834 | assert_that "stdout" --file-is-lines \ | |
835 | "=> Substituting \"vars\" in vars.txt" | 835 | "=> Substituting \"vars\" in vars.txt" | |
836 | assert_that "stderr" --file-is-empty | 836 | assert_that "stderr" --file-is-empty | |
837 | assert_that "$exitcode" --equals 0 | 837 | assert_that "$exitcode" --equals 0 | |
838 | 838 | |||
839 | test_case_end | 839 | test_case_end | |
840 | fi | 840 | fi | |
841 | ||||
842 | if test_case_begin "pattern matches directory"; then | |||
843 | ||||
844 | # When a pattern matches a directory, that directory is silently | |||
845 | # skipped. | |||
846 | # | |||
847 | # In this test case, the pattern also matches a regular file that | |||
848 | # is actually modified. Therefore the pattern has an effect, and | |||
849 | # there is no error message. | |||
850 | ||||
851 | create_file_lines "testcase.mk" \ | |||
852 | 'SUBST_CLASSES+= dir' \ | |||
853 | 'SUBST_STAGE.dir= pre-configure' \ | |||
854 | 'SUBST_FILES.dir= sub*' \ | |||
855 | 'SUBST_VARS.dir= VAR' \ | |||
856 | 'SUBST_NOOP_OK.dir= no' \ | |||
857 | '' \ | |||
858 | 'VAR= value' \ | |||
859 | '' \ | |||
860 | '.include "prepare-subst.mk"' \ | |||
861 | '.include "mk/subst.mk"' | |||
862 | mkdir "$tmpdir/subdir" | |||
863 | create_file_lines "subdir/subfile" \ | |||
864 | "@VAR@" | |||
865 | create_file_lines "subst-file" \ | |||
866 | "@VAR@" | |||
867 | ||||
868 | test_file "testcase.mk" "pre-configure" \ | |||
869 | 1> "$tmpdir/stdout" \ | |||
870 | 2> "$tmpdir/stderr" \ | |||
871 | && exitcode=0 || exitcode=$? | |||
872 | ||||
873 | assert_that "subst-file" --file-is-lines "value" | |||
874 | assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged | |||
875 | assert_that "stdout" --file-is-lines \ | |||
876 | "=> Substituting \"dir\" in sub*" | |||
877 | assert_that "stderr" --file-is-empty | |||
878 | assert_that "$exitcode" --equals 0 | |||
879 | ||||
880 | test_case_end | |||
881 | fi | |||
882 | ||||
883 | ||||
884 | if test_case_begin "pattern matches only directory"; then | |||
885 | ||||
886 | # When a pattern matches a directory, that directory is silently | |||
887 | # skipped. | |||
888 | # | |||
889 | # In this test case, the pattern also matches a regular file that | |||
890 | # is actually modified. Therefore the pattern has an effect, and | |||
891 | # there is no error message. | |||
892 | ||||
893 | create_file_lines "testcase.mk" \ | |||
894 | 'SUBST_CLASSES+= dir' \ | |||
895 | 'SUBST_STAGE.dir= pre-configure' \ | |||
896 | 'SUBST_FILES.dir= sub*' \ | |||
897 | 'SUBST_VARS.dir= VAR' \ | |||
898 | 'SUBST_NOOP_OK.dir= no' \ | |||
899 | '' \ | |||
900 | 'VAR= value' \ | |||
901 | '' \ | |||
902 | '.include "prepare-subst.mk"' \ | |||
903 | '.include "mk/subst.mk"' | |||
904 | mkdir "$tmpdir/subdir" | |||
905 | create_file_lines "subdir/subfile" \ | |||
906 | "@VAR@" | |||
907 | ||||
908 | test_file "testcase.mk" "pre-configure" \ | |||
909 | 1> "$tmpdir/stdout" \ | |||
910 | 2> "$tmpdir/stderr" \ | |||
911 | && exitcode=0 || exitcode=$? | |||
912 | ||||
913 | assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged | |||
914 | assert_that "stdout" --file-is-lines \ | |||
915 | "=> Substituting \"dir\" in sub*" \ | |||
916 | "fail: [subst.mk:dir] The pattern sub* has no effect." \ | |||
917 | "*** Error code 1" \ | |||
918 | "" \ | |||
919 | "Stop." \ | |||
920 | "$make: stopped in $PWD" | |||
921 | assert_that "stderr" --file-is-empty | |||
922 | assert_that "$exitcode" --equals 1 | |||
923 | ||||
924 | test_case_end | |||
925 | fi |