Sat May 16 12:43:10 2020 UTC ()
mk/subst.mk: properly detect s,a,a,1 as identity substitution

Seen in games/bastet.  The 1 is not necessary though since it only
repeats the default behavior of sed.


(rillig)
diff -r1.23 -r1.24 pkgsrc/games/bastet/Makefile
diff -r1.3 -r1.4 pkgsrc/mk/scripts/subst-identity.awk
diff -r1.40 -r1.41 pkgsrc/regress/infra-unittests/subst.sh

cvs diff -r1.23 -r1.24 pkgsrc/games/bastet/Makefile (expand / switch to unified diff)

--- pkgsrc/games/bastet/Makefile 2020/05/06 14:04:31 1.23
+++ pkgsrc/games/bastet/Makefile 2020/05/16 12:43:10 1.24
@@ -1,36 +1,36 @@ @@ -1,36 +1,36 @@
1# $NetBSD: Makefile,v 1.23 2020/05/06 14:04:31 adam Exp $ 1# $NetBSD: Makefile,v 1.24 2020/05/16 12:43:10 rillig Exp $
2 2
3DISTNAME= bastet-0.43.2 3DISTNAME= bastet-0.43.2
4PKGREVISION= 2 4PKGREVISION= 2
5CATEGORIES= games 5CATEGORIES= games
6MASTER_SITES= ${MASTER_SITE_GITHUB:=fph/} 6MASTER_SITES= ${MASTER_SITE_GITHUB:=fph/}
7 7
8MAINTAINER= pkgsrc-users@NetBSD.org 8MAINTAINER= pkgsrc-users@NetBSD.org
9HOMEPAGE= https://fph.altervista.org/prog/bastet.html 9HOMEPAGE= https://fph.altervista.org/prog/bastet.html
10COMMENT= Bastard Tetris 10COMMENT= Bastard Tetris
11LICENSE= gnu-gpl-v3 11LICENSE= gnu-gpl-v3
12 12
13USE_LANGUAGES= c c++ 13USE_LANGUAGES= c c++
14USE_TOOLS+= gmake 14USE_TOOLS+= gmake
15BUILD_DEFS+= VARBASE 15BUILD_DEFS+= VARBASE
16 16
17USE_GAMESGROUP= yes 17USE_GAMESGROUP= yes
18SPECIAL_PERMS= bin/bastet ${SETGID_GAMES_PERMS} 18SPECIAL_PERMS= bin/bastet ${SETGID_GAMES_PERMS}
19INSTALLATION_DIRS= bin ${PKGMANDIR}/man6 19INSTALLATION_DIRS= bin ${PKGMANDIR}/man6
20 20
21SUBST_CLASSES+= vardir 21SUBST_CLASSES+= vardir
22SUBST_STAGE.vardir= pre-configure 22SUBST_STAGE.vardir= pre-configure
23SUBST_FILES.vardir= Config.cpp 23SUBST_FILES.vardir= Config.cpp
24SUBST_MESSAGE.vardir= Fixing VARBASE. 24SUBST_MESSAGE.vardir= Fixing VARBASE.
25SUBST_SED.vardir= -e "s|/var/games|${VARBASE}/games|1" 25SUBST_SED.vardir= -e "s|/var/games|${VARBASE}/games|"
26 26
27REQD_FILES_PERMS+= /dev/null ${VARBASE}/games/bastet.scores2 ${GAMEDATA_PERMS} 27REQD_FILES_PERMS+= /dev/null ${VARBASE}/games/bastet.scores2 ${GAMEDATA_PERMS}
28 28
29do-install: 29do-install:
30 ${INSTALL_PROGRAM} ${WRKSRC}/bastet ${DESTDIR}${PREFIX}/bin/ 30 ${INSTALL_PROGRAM} ${WRKSRC}/bastet ${DESTDIR}${PREFIX}/bin/
31 ${INSTALL_MAN} ${WRKSRC}/bastet.6 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man6/ 31 ${INSTALL_MAN} ${WRKSRC}/bastet.6 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man6/
32 32
33.include "../../devel/boost-headers/buildlink3.mk" 33.include "../../devel/boost-headers/buildlink3.mk"
34.include "../../devel/boost-libs/buildlink3.mk" 34.include "../../devel/boost-libs/buildlink3.mk"
35.include "../../mk/curses.buildlink3.mk" 35.include "../../mk/curses.buildlink3.mk"
36.include "../../mk/bsd.pkg.mk" 36.include "../../mk/bsd.pkg.mk"

cvs diff -r1.3 -r1.4 pkgsrc/mk/scripts/subst-identity.awk (expand / switch to unified diff)

--- pkgsrc/mk/scripts/subst-identity.awk 2020/05/11 19:52:14 1.3
+++ pkgsrc/mk/scripts/subst-identity.awk 2020/05/16 12:43:10 1.4
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /usr/bin/awk -f 1#! /usr/bin/awk -f
2# $NetBSD: subst-identity.awk,v 1.3 2020/05/11 19:52:14 rillig Exp $ 2# $NetBSD: subst-identity.awk,v 1.4 2020/05/16 12:43:10 rillig Exp $
3# 3#
4# Tests whether a sed(1) command line consists of only identity substitutions 4# Tests whether a sed(1) command line consists of only identity substitutions
5# like s,id,id,. 5# like s,id,id,.
6# 6#
7# See SUBST_NOOP_OK and regress/infra-unittests/subst.sh. 7# See SUBST_NOOP_OK and regress/infra-unittests/subst.sh.
8# 8#
9 9
10# Returns the first character of the given regular expression, 10# Returns the first character of the given regular expression,
11# if it is a single-character regular expression. 11# if it is a single-character regular expression.
12function identity_char(s, sep, i) { 12function identity_char(s, sep, i) {
13 if (s ~ /^[\t -~]/ && s !~ /^[$&*.\[\\\]^]/) 13 if (s ~ /^[\t -~]/ && s !~ /^[$&*.\[\\\]^]/)
14 return substr(s, 1, 1); 14 return substr(s, 1, 1);
15 if (s ~ /^\\[$*.\[\]^]/) 15 if (s ~ /^\\[$*.\[\]^]/)
@@ -35,26 +35,26 @@ function is_identity_subst(s, len, i,  @@ -35,26 +35,26 @@ function is_identity_subst(s, len, i,
35 while (i < len && substr(s, i, 1) != sep) { 35 while (i < len && substr(s, i, 1) != sep) {
36 ch = identity_char(substr(s, i), sep, i); 36 ch = identity_char(substr(s, i), sep, i);
37 if (ch == "") 37 if (ch == "")
38 break; 38 break;
39 pat_to = pat_to substr(ch, 1, 1); 39 pat_to = pat_to substr(ch, 1, 1);
40 i += length(ch); 40 i += length(ch);
41 } 41 }
42 42
43 if (pat_to == "") 43 if (pat_to == "")
44 return 0; # only for GNU Awk 5.0.1 in -Lfatal mode 44 return 0; # only for GNU Awk 5.0.1 in -Lfatal mode
45 pat_from = substr(s, 3, i - 3); 45 pat_from = substr(s, 3, i - 3);
46 46
47 subst = "s" sep pat_from sep pat_to sep; 47 subst = "s" sep pat_from sep pat_to sep;
48 return s == subst || s == subst "g"; 48 return s == subst || s == subst "g" || s == subst "1";
49} 49}
50 50
51function main( i) { 51function main( i) {
52 for (i = 1; i + 1 < ARGC; i += 2) 52 for (i = 1; i + 1 < ARGC; i += 2)
53 if (ARGV[i] != "-e" || !is_identity_subst(ARGV[i + 1])) 53 if (ARGV[i] != "-e" || !is_identity_subst(ARGV[i + 1]))
54 return 0; 54 return 0;
55 return i == ARGC && ARGC > 1; 55 return i == ARGC && ARGC > 1;
56} 56}
57 57
58BEGIN { 58BEGIN {
59 exit(main() ? 0 : 1); 59 exit(main() ? 0 : 1);
60} 60}

cvs diff -r1.40 -r1.41 pkgsrc/regress/infra-unittests/subst.sh (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/subst.sh 2020/05/12 05:34:04 1.40
+++ pkgsrc/regress/infra-unittests/subst.sh 2020/05/16 12:43:10 1.41
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: subst.sh,v 1.40 2020/05/12 05:34:04 rillig Exp $ 2# $NetBSD: subst.sh,v 1.41 2020/05/16 12:43:10 rillig Exp $
3# 3#
4# Tests for mk/subst.mk. 4# Tests for mk/subst.mk.
5# 5#
6 6
7set -eu 7set -eu
8 8
9. './test.subr' 9. './test.subr'
10 10
11test_case_set_up() { 11test_case_set_up() {
12 wrkdir="$tmpdir/wrkdir" 12 wrkdir="$tmpdir/wrkdir"
13 mkdir "$wrkdir" 13 mkdir "$wrkdir"
14 14
15 create_file 'prepare-subst.mk' <<-EOF 15 create_file 'prepare-subst.mk' <<-EOF
@@ -1182,26 +1182,29 @@ if test_case_begin 'identity substitutio @@ -1182,26 +1182,29 @@ if test_case_begin 'identity substitutio
1182 # Since a regular expression with a subexpression must contain 1182 # Since a regular expression with a subexpression must contain
1183 # \( and \), it does not count as an identity substitution anyway, 1183 # \( and \), it does not count as an identity substitution anyway,
1184 # which makes the implementation simple. 1184 # which makes the implementation simple.
1185 assert_identity 'no' -e 's,aaa\(aaa$\),aaa\(aaa$\),' 1185 assert_identity 'no' -e 's,aaa\(aaa$\),aaa\(aaa$\),'
1186 1186
1187 assert_identity 'yes' -e 's,$a,$a,' 1187 assert_identity 'yes' -e 's,$a,$a,'
1188 assert_identity 'no' -e 's,a$,a$,' 1188 assert_identity 'no' -e 's,a$,a$,'
1189 1189
1190 # Same for the circumflex. 1190 # Same for the circumflex.
1191 assert_identity 'yes' -e 's,a^,a^,' 1191 assert_identity 'yes' -e 's,a^,a^,'
1192 assert_identity 'no' -e 's,^a,^a,' 1192 assert_identity 'no' -e 's,^a,^a,'
1193 assert_identity 'no' -e 's,\(^aaa\)aaa,\(^aaa\)aaa,' 1193 assert_identity 'no' -e 's,\(^aaa\)aaa,\(^aaa\)aaa,'
1194 1194
 1195 # Seen in games/bastet before 2020-05-16.
 1196 assert_identity 'yes' -e 's,a,a,1'
 1197
1195 test_case_end 1198 test_case_end
1196fi 1199fi
1197 1200
1198 1201
1199if test_case_begin 'identity substitution, found in file'; then 1202if test_case_begin 'identity substitution, found in file'; then
1200 1203
1201 # There are many situations in which a fixed text is replaced 1204 # There are many situations in which a fixed text is replaced
1202 # with a dynamic value that may or may not be equal to the 1205 # with a dynamic value that may or may not be equal to the
1203 # original text. 1206 # original text.
1204 # 1207 #
1205 # Typical examples are s|man|${PKGMANDIR}|, s|/usr/pkg|${PREFIX}|, 1208 # Typical examples are s|man|${PKGMANDIR}|, s|/usr/pkg|${PREFIX}|,
1206 # s|/dev/audio|${DEVOSSAUDIO}|. 1209 # s|/dev/audio|${DEVOSSAUDIO}|.
1207 # 1210 #