diff options
author | rillig <rillig@pkgsrc.org> | 2020-05-01 06:42:32 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2020-05-01 06:42:32 +0000 |
commit | 5a0a1754339f313834f2eb581a8a3a65a8e5ba65 (patch) | |
tree | 4c9c0b08697901569916bb455d89eb778a22635e | |
parent | 9ceee6cc4c07cf20c7865420fa5527d8f99eea26 (diff) | |
download | pkgsrc-5a0a1754339f313834f2eb581a8a3a65a8e5ba65.tar.gz |
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.
-rw-r--r-- | mk/subst.mk | 4 | ||||
-rw-r--r-- | regress/infra-unittests/subst.sh | 25 |
2 files changed, 26 insertions, 3 deletions
diff --git a/mk/subst.mk b/mk/subst.mk index 403c9416c9e..c5d62eaa901 100644 --- a/mk/subst.mk +++ b/mk/subst.mk @@ -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_COOKIE.${class}}: ${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 --git a/regress/infra-unittests/subst.sh b/regress/infra-unittests/subst.sh index 8e7de065189..1535d6e77ad 100644 --- a/regress/infra-unittests/subst.sh +++ b/regress/infra-unittests/subst.sh @@ -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 @@ if test_case_begin "no-op SUBST_FILTER_CMD in NOOP_OK=no mode"; then 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 |