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.diff -r1.23 -r1.24 pkgsrc/games/bastet/Makefile
(rillig)
@@ -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 | |||
3 | DISTNAME= bastet-0.43.2 | 3 | DISTNAME= bastet-0.43.2 | |
4 | PKGREVISION= 2 | 4 | PKGREVISION= 2 | |
5 | CATEGORIES= games | 5 | CATEGORIES= games | |
6 | MASTER_SITES= ${MASTER_SITE_GITHUB:=fph/} | 6 | MASTER_SITES= ${MASTER_SITE_GITHUB:=fph/} | |
7 | 7 | |||
8 | MAINTAINER= pkgsrc-users@NetBSD.org | 8 | MAINTAINER= pkgsrc-users@NetBSD.org | |
9 | HOMEPAGE= https://fph.altervista.org/prog/bastet.html | 9 | HOMEPAGE= https://fph.altervista.org/prog/bastet.html | |
10 | COMMENT= Bastard Tetris | 10 | COMMENT= Bastard Tetris | |
11 | LICENSE= gnu-gpl-v3 | 11 | LICENSE= gnu-gpl-v3 | |
12 | 12 | |||
13 | USE_LANGUAGES= c c++ | 13 | USE_LANGUAGES= c c++ | |
14 | USE_TOOLS+= gmake | 14 | USE_TOOLS+= gmake | |
15 | BUILD_DEFS+= VARBASE | 15 | BUILD_DEFS+= VARBASE | |
16 | 16 | |||
17 | USE_GAMESGROUP= yes | 17 | USE_GAMESGROUP= yes | |
18 | SPECIAL_PERMS= bin/bastet ${SETGID_GAMES_PERMS} | 18 | SPECIAL_PERMS= bin/bastet ${SETGID_GAMES_PERMS} | |
19 | INSTALLATION_DIRS= bin ${PKGMANDIR}/man6 | 19 | INSTALLATION_DIRS= bin ${PKGMANDIR}/man6 | |
20 | 20 | |||
21 | SUBST_CLASSES+= vardir | 21 | SUBST_CLASSES+= vardir | |
22 | SUBST_STAGE.vardir= pre-configure | 22 | SUBST_STAGE.vardir= pre-configure | |
23 | SUBST_FILES.vardir= Config.cpp | 23 | SUBST_FILES.vardir= Config.cpp | |
24 | SUBST_MESSAGE.vardir= Fixing VARBASE. | 24 | SUBST_MESSAGE.vardir= Fixing VARBASE. | |
25 | SUBST_SED.vardir= -e "s|/var/games|${VARBASE}/games|1" | 25 | SUBST_SED.vardir= -e "s|/var/games|${VARBASE}/games|" | |
26 | 26 | |||
27 | REQD_FILES_PERMS+= /dev/null ${VARBASE}/games/bastet.scores2 ${GAMEDATA_PERMS} | 27 | REQD_FILES_PERMS+= /dev/null ${VARBASE}/games/bastet.scores2 ${GAMEDATA_PERMS} | |
28 | 28 | |||
29 | do-install: | 29 | do-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" |
@@ -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. | |
12 | function identity_char(s, sep, i) { | 12 | function 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 | |||
51 | function main( i) { | 51 | function 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 | |||
58 | BEGIN { | 58 | BEGIN { | |
59 | exit(main() ? 0 : 1); | 59 | exit(main() ? 0 : 1); | |
60 | } | 60 | } |
@@ -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 | |||
7 | set -eu | 7 | set -eu | |
8 | 8 | |||
9 | . './test.subr' | 9 | . './test.subr' | |
10 | 10 | |||
11 | test_case_set_up() { | 11 | test_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 | |
1196 | fi | 1199 | fi | |
1197 | 1200 | |||
1198 | 1201 | |||
1199 | if test_case_begin 'identity substitution, found in file'; then | 1202 | if 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 | # |