pkgsrc-Changes archive

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

CVS commit: pkgsrc



Module Name:    pkgsrc
Committed By:   rillig
Date:           Sat May  2 05:52:10 UTC 2020

Modified Files:
        pkgsrc/mk: subst.mk
        pkgsrc/regress/infra-unittests: subst.sh

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 pkgsrc/mk/subst.mk
cvs rdiff -u -r1.29 -r1.30 pkgsrc/regress/infra-unittests/subst.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: pkgsrc/mk/subst.mk
diff -u pkgsrc/mk/subst.mk:1.91 pkgsrc/mk/subst.mk:1.92
--- pkgsrc/mk/subst.mk:1.91     Fri May  1 19:53:48 2020
+++ pkgsrc/mk/subst.mk  Sat May  2 05:52:09 2020
@@ -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_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,:C,[\\`"],\\\\&,g} "$$file"` \
+                               && found=$$(LC_ALL=C ${SED} -n ${SUBST_SED.${class}:C,^['"]?s.*,&p,} "$$file") \
                                && [ -n "$$found" ] && {                \
                                        changed=yes;                    \
                                        continue;                       \

Index: pkgsrc/regress/infra-unittests/subst.sh
diff -u pkgsrc/regress/infra-unittests/subst.sh:1.29 pkgsrc/regress/infra-unittests/subst.sh:1.30
--- pkgsrc/regress/infra-unittests/subst.sh:1.29        Fri May  1 19:53:48 2020
+++ pkgsrc/regress/infra-unittests/subst.sh     Sat May  2 05:52:09 2020
@@ -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 @@ if test_case_begin "backtick in SUBST_SE
 
        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