Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc mk/subst.mk: fix wrong SUBST failure in mail/policyd-w...
details: https://anonhg.NetBSD.org/pkgsrc/rev/d0d4e399acf6
branches: trunk
changeset: 433648:d0d4e399acf6
user: rillig <rillig%pkgsrc.org@localhost>
date: Sat Jun 06 13:17:34 2020 +0000
description:
mk/subst.mk: fix wrong SUBST failure in mail/policyd-weight
The general rule is that a SUBST_SED that contains _any_ identity
substitution may leave files unmodified, no matter if there are other
substitutions as well.
diffstat:
mk/scripts/subst-identity.awk | 23 +++++++++++++++--------
regress/infra-unittests/subst.sh | 33 +++++++++++----------------------
2 files changed, 26 insertions(+), 30 deletions(-)
diffs (105 lines):
diff -r 5bb131fa988b -r d0d4e399acf6 mk/scripts/subst-identity.awk
--- a/mk/scripts/subst-identity.awk Sat Jun 06 13:00:52 2020 +0000
+++ b/mk/scripts/subst-identity.awk Sat Jun 06 13:17:34 2020 +0000
@@ -1,12 +1,19 @@
#! /usr/bin/awk -f
-# $NetBSD: subst-identity.awk,v 1.4 2020/05/16 12:43:10 rillig Exp $
+# $NetBSD: subst-identity.awk,v 1.5 2020/06/06 13:17:34 rillig Exp $
#
-# Tests whether a sed(1) command line consists of only identity substitutions
-# like s,id,id,.
+# Tests whether a sed(1) command line contains an identity substitution
+# like s,id,id,. When used in a SUBST block, these commands may leave a
+# file unmodified, which is ok since such an identity substitution
+# typically looks like s,/var,${VARBASE},.
#
# See SUBST_NOOP_OK and regress/infra-unittests/subst.sh.
#
+BEGIN {
+ false = 0;
+ true = 1;
+}
+
# Returns the first character of the given regular expression,
# if it is a single-character regular expression.
function identity_char(s, sep, i) {
@@ -48,13 +55,13 @@
return s == subst || s == subst "g" || s == subst "1";
}
-function main( i) {
+function contains_identity_subst( i) {
for (i = 1; i + 1 < ARGC; i += 2)
- if (ARGV[i] != "-e" || !is_identity_subst(ARGV[i + 1]))
- return 0;
- return i == ARGC && ARGC > 1;
+ if (ARGV[i] == "-e" && is_identity_subst(ARGV[i + 1]))
+ return true;
+ return false;
}
BEGIN {
- exit(main() ? 0 : 1);
+ exit(contains_identity_subst() ? 0 : 1);
}
diff -r 5bb131fa988b -r d0d4e399acf6 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh Sat Jun 06 13:00:52 2020 +0000
+++ b/regress/infra-unittests/subst.sh Sat Jun 06 13:17:34 2020 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: subst.sh,v 1.44 2020/06/06 13:00:52 rillig Exp $
+# $NetBSD: subst.sh,v 1.45 2020/06/06 13:17:34 rillig Exp $
#
# Tests for mk/subst.mk.
#
@@ -1265,12 +1265,14 @@
assert_identity 'yes' -e 's!/dev/audio!/dev/audio!'
# There may be several identity substitutions in the same
- # SUBST_SED. As long as all these substitutions are identity
- # substitutions, they may be skipped. As soon as there is one
- # other substitution, the whole SUBST_SED is treated as usual.
+ # SUBST_SED. As long as any of these substitutions is an
+ # identity substitution, it can happen that a file stays the
+ # same. It still might be modified in a different pkgsrc
+ # configuration.
assert_identity 'yes' -e 's;from;from;' -e 's!second!second!'
- assert_identity 'no' -e 's,changing,x,' -e 's,id,id,'
- assert_identity 'no' -e 's,id,id,' -e 's,changing,x,'
+ assert_identity 'yes' -e 's,changing,x,' -e 's,id,id,'
+ assert_identity 'yes' -e 's,id,id,' -e 's,changing,x,'
+ assert_identity 'no' -e 's,changing,x,' -e 's,changing,x,'
# A demonstration of all ASCII characters that may appear in an
# identity substitution.
@@ -1656,26 +1658,13 @@
run_bmake 'testcase.mk' 'subst-id' 1> "$tmpdir/output" 2>&1 \
&& exitcode=0 || exitcode=$?
- # FIXME: This is not the intended behavior.
# Each of the files contains at least one of the sed patterns,
# therefore the substitutions _could_ have an effect, depending
# on the pkgsrc configuration.
- #
- # Instead of testing whether the sed command is an identity
- # substitution, the original idea was to find files that contain
- # _none_ of the patterns.
- #
- # The proper fix might be as simple as replacing the "all" with an
- # "any" in mk/scripts/subst-identity.awk. This would also nicely
- # remove the special handling of an empty command line.
assert_that "$tmpdir/output" --file-is-lines \
- '=> Substituting "id" in first second' \
- 'warning: [subst.mk:id] Nothing changed in "second".' \
- 'fail: [subst.mk:id] The filename pattern "second" has no effect.' \
- '*** Error code 1' \
- '' \
- 'Stop.' \
- "$make: stopped in $PWD"
+ '=> Substituting "id" in first second'
+ assert_that 'first' --file-contains-exactly 'first-modified'
+ assert_that 'second' --file-contains-exactly 'second'
test_case_end
fi
Home |
Main Index |
Thread Index |
Old Index