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 shell parse error for special sed exp...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/541bf00afb40
branches:  trunk
changeset: 430579:541bf00afb40
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Sat May 02 05:52:09 2020 +0000

description:
mk/subst.mk: fix shell parse error for special sed expressions

The escaping inside the backticks had been wrong.  Because of this,
parentheses and semicolons were interpreted as shell syntax.

Switching to $(...) command substitution removes the need for quoting
some of the characters and makes the whole command simpler to understand.
Doing the escaping for the backticks command properly would have involved
lots of special cases.

The $(...) command substitution was used sparingly in pkgsrc up to now
because some older or broken shells do not support it.  Since these
shells do not end up as the shell that runs the commands from Makefiles,
that's not a problem.

diffstat:

 mk/subst.mk                      |   4 ++--
 regress/infra-unittests/subst.sh |  35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 3 deletions(-)

diffs (65 lines):

diff -r d21f29d7a248 -r 541bf00afb40 mk/subst.mk
--- a/mk/subst.mk       Sat May 02 03:15:56 2020 +0000
+++ b/mk/subst.mk       Sat May 02 05:52:09 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.91 2020/05/01 19:53:48 rillig Exp $
+# $NetBSD: subst.mk,v 1.92 2020/05/02 05:52:09 rillig Exp $
 #
 # The subst framework replaces text in one or more files in the WRKSRC
 # directory. Packages can define several ``classes'' of replacements.
@@ -200,7 +200,7 @@
                        ${SUBST_FILTER_CMD.${class}} < "$$file" > "$$tmpfile";  \
                        ${CMP} -s "$$tmpfile" "$$file" && {             \
                                ${AWK} -f ${PKGSRCDIR}/mk/scripts/subst-identity.awk -- ${SUBST_SED.${class}} \
-                               && found=`LC_ALL=C ${SED} -n ${SUBST_SED.${class}:C,^['"]?s.*,&p,:C,[\\`"],\\\\&,g} "$$file"` \
+                               && found=$$(LC_ALL=C ${SED} -n ${SUBST_SED.${class}:C,^['"]?s.*,&p,} "$$file") \
                                && [ -n "$$found" ] && {                \
                                        changed=yes;                    \
                                        continue;                       \
diff -r d21f29d7a248 -r 541bf00afb40 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Sat May 02 03:15:56 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Sat May 02 05:52:09 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: subst.sh,v 1.29 2020/05/01 19:53:48 rillig Exp $
+# $NetBSD: subst.sh,v 1.30 2020/05/02 05:52:09 rillig Exp $
 #
 # Tests for mk/subst.mk.
 #
@@ -1448,3 +1448,36 @@
 
        test_case_end
 fi
+
+
+if test_case_begin "multiple sed commands with semicolon"; then
+
+       # From PR pkg/55226:
+       #  ===> Configuring for perl-5.30.2
+       # sh: 1: Syntax error: Word "/d"p" unexpected (expecting ")")
+
+       create_file_lines "testcase.mk" \
+               'SUBST_CLASSES+=        id' \
+               'SUBST_FILES.id=        file' \
+               'SUBST_SED.id=          -e "s/755/755/g;/umask(/d"' \
+               'SUBST_NOOP_OK.id=      no' \
+               '' \
+               '.include "prepare-subst.mk"' \
+               '.include "mk/subst.mk"'
+       create_file_lines "file" \
+               '$mode = 755;'
+
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       && exitcode=0 || exitcode=$?
+
+       assert_that "out" --file-is-lines \
+               '=> Substituting "id" in file' \
+               'warning: [subst.mk:id] Nothing changed in "file".' \
+               'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
+               '*** Error code 1' \
+               '' \
+               'Stop.' \
+               "$make: stopped in $PWD"
+
+       test_case_end
+fi



Home | Main Index | Thread Index | Old Index