Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc mk/subst.mk: switch command substitution back to backt...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/10846c4e59b5
branches:  trunk
changeset: 430489:10846c4e59b5
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri May 01 06:42:32 2020 +0000

description:
mk/subst.mk: switch command substitution back to backticks

To work properly, the $(...) should have been $$(...).

In pkgsrc the command substitution is usually done via `backticks`, for
compatibility with /bin/sh from Solaris.  To fix the shell parse errors,
the special characters are properly escaped inside the command
substitution.

diffstat:

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

diffs (55 lines):

diff -r 233f7458e8cb -r 10846c4e59b5 mk/subst.mk
--- a/mk/subst.mk       Fri May 01 04:56:48 2020 +0000
+++ b/mk/subst.mk       Fri May 01 06:42:32 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: subst.mk,v 1.89 2020/04/30 23:52:30 joerg Exp $
+# $NetBSD: subst.mk,v 1.90 2020/05/01 06:42:32 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,} "$$file") \
+                               && found=`LC_ALL=C ${SED} -n ${SUBST_SED.${class}:C,^['"]?s.*,&p,:C,[\\`"],\\\\&,g} "$$file"` \
                                && [ -n "$$found" ] && {                \
                                        changed=yes;                    \
                                        continue;                       \
diff -r 233f7458e8cb -r 10846c4e59b5 regress/infra-unittests/subst.sh
--- a/regress/infra-unittests/subst.sh  Fri May 01 04:56:48 2020 +0000
+++ b/regress/infra-unittests/subst.sh  Fri May 01 06:42:32 2020 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: subst.sh,v 1.27 2020/04/29 22:46:42 rillig Exp $
+# $NetBSD: subst.sh,v 1.28 2020/05/01 06:42:32 rillig Exp $
 #
 # Tests for mk/subst.mk.
 #
@@ -1425,3 +1425,26 @@
 
        test_case_end
 fi
+
+
+if test_case_begin "backtick in SUBST_SED"; then
+
+       create_file_lines "testcase.mk" \
+               'SUBST_CLASSES+=        id' \
+               'SUBST_FILES.id=        file' \
+               "SUBST_SED.id=          -e 's,\"\\\\\`,\"\\\\\`,'" \
+               '' \
+               '.include "prepare-subst.mk"' \
+               '.include "mk/subst.mk"'
+       create_file_lines "file" \
+               'from`'
+
+       run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \
+       && exitcode=0 || exitcode=$?
+
+       assert_that "out" --file-is-lines \
+               '=> Substituting "id" in file' \
+               'info: [subst.mk:id] Nothing changed in "file".'
+
+       test_case_end
+fi



Home | Main Index | Thread Index | Old Index