Module Name: src Committed By: rillig Date: Sun Mar 30 00:35:52 UTC 2025
Modified Files: src/usr.bin/make: var.c src/usr.bin/make/unit-tests: moderrs.exp moderrs.mk varmod-sysv.mk varmod-to-separator.exp varmod-to-separator.mk varmod.mk Log Message: make: let the ":t" modifiers fall back to the ":from=to" modifier Suggested by https://bugs.freebsd.org/285726. This means that the ":t" modifiers cannot have future extensions that include a "=", as that may break existing code. To generate a diff of this commit: cvs rdiff -u -r1.1153 -r1.1154 src/usr.bin/make/var.c cvs rdiff -u -r1.51 -r1.52 src/usr.bin/make/unit-tests/moderrs.exp cvs rdiff -u -r1.45 -r1.46 src/usr.bin/make/unit-tests/moderrs.mk cvs rdiff -u -r1.23 -r1.24 src/usr.bin/make/unit-tests/varmod-sysv.mk cvs rdiff -u -r1.19 -r1.20 \ src/usr.bin/make/unit-tests/varmod-to-separator.exp cvs rdiff -u -r1.22 -r1.23 src/usr.bin/make/unit-tests/varmod-to-separator.mk cvs rdiff -u -r1.24 -r1.25 src/usr.bin/make/unit-tests/varmod.mk Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.1153 src/usr.bin/make/var.c:1.1154 --- src/usr.bin/make/var.c:1.1153 Sat Mar 29 23:50:07 2025 +++ src/usr.bin/make/var.c Sun Mar 30 00:35:52 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.1153 2025/03/29 23:50:07 rillig Exp $ */ +/* $NetBSD: var.c,v 1.1154 2025/03/30 00:35:52 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -128,7 +128,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.1153 2025/03/29 23:50:07 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.1154 2025/03/30 00:35:52 rillig Exp $"); /* * Variables are defined using one of the VAR=value assignments. Their @@ -3096,11 +3096,8 @@ ApplyModifier_ToSep(const char **pp, Mod goto ok; } - /* ":ts<unrecognized><unrecognized>". */ - if (sep[0] != '\\') { - (*pp)++; /* just for backwards compatibility */ - return AMR_BAD; - } + if (sep[0] != '\\') + return AMR_UNKNOWN; /* ":ts\n" */ if (sep[1] == 'n') { @@ -3124,20 +3121,16 @@ ApplyModifier_ToSep(const char **pp, Mod if (sep[1] == 'x') { base = 16; p++; - } else if (!ch_isdigit(sep[1])) { - (*pp)++; /* just for backwards compatibility */ - return AMR_BAD; /* ":ts<backslash><unrecognized>". */ - } + } else if (!ch_isdigit(sep[1])) + return AMR_UNKNOWN; /* ":ts\..." */ if (!TryParseChar(&p, base, &ch->sep)) { Parse_Error(PARSE_FATAL, "Invalid character number at \"%s\"", p); return AMR_CLEANUP; } - if (!IsDelimiter(*p, ch)) { - (*pp)++; /* just for backwards compatibility */ - return AMR_BAD; - } + if (!IsDelimiter(*p, ch)) + return AMR_UNKNOWN; *pp = p; } @@ -3190,18 +3183,14 @@ ApplyModifier_To(const char **pp, ModCha const char *mod = *pp; assert(mod[0] == 't'); - if (IsDelimiter(mod[1], ch)) { - *pp = mod + 1; - return AMR_BAD; /* Found ":t<endc>" or ":t:". */ - } + if (IsDelimiter(mod[1], ch)) + return AMR_UNKNOWN; /* ":t<endc>" or ":t:" */ if (mod[1] == 's') return ApplyModifier_ToSep(pp, ch); - if (!IsDelimiter(mod[2], ch)) { /* :t<any><any> */ - *pp = mod + 1; - return AMR_BAD; - } + if (!IsDelimiter(mod[2], ch)) + return AMR_UNKNOWN; if (mod[1] == 'A') { /* :tA */ *pp = mod + 2; @@ -3236,9 +3225,7 @@ ApplyModifier_To(const char **pp, ModCha return AMR_OK; } - /* Found ":t<unrecognized>:" or ":t<unrecognized><endc>". */ - *pp = mod + 1; /* XXX: unnecessary but observable */ - return AMR_BAD; + return AMR_UNKNOWN; /* ":t<any>:" or ":t<any><endc>" */ } /* :[#], :[1], :[-1..1], etc. */ Index: src/usr.bin/make/unit-tests/moderrs.exp diff -u src/usr.bin/make/unit-tests/moderrs.exp:1.51 src/usr.bin/make/unit-tests/moderrs.exp:1.52 --- src/usr.bin/make/unit-tests/moderrs.exp:1.51 Sat Mar 29 19:08:52 2025 +++ src/usr.bin/make/unit-tests/moderrs.exp Sun Mar 30 00:35:52 2025 @@ -107,31 +107,31 @@ make: Unclosed expression, expecting '}' 7: TheVariable 112358132134 15152535558513521534 -make: Bad modifier ":ts\65oct" +make: Unknown modifier ":ts\65oct" while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34" in command "@echo ${FIB:ts\65oct} # bad modifier" in target "mod-ts-parse-3" -make: Bad modifier ":ts\65oct" +make: Unknown modifier ":ts\65oct" while evaluating "${:U${FIB}:ts\65oct} # bad modifier, variable name is """ with value "1 1 2 3 5 8 13 21 34" in command "@echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is """ in target "mod-ts-parse-4" -make: Bad modifier ":tsxy" +make: Unknown modifier ":tsxy" while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34" in command "@echo ${FIB:tsxy} # modifier too long" in target "mod-ts-parse-5" -make: Bad modifier ":t" +make: Unknown modifier ":t" while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34" in command "@echo ${FIB:t" in target "mod-t-parse-1" -make: Bad modifier ":txy" +make: Unknown modifier ":txy" while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34" in command "@echo ${FIB:txy}" in target "mod-t-parse-2" -make: Bad modifier ":t" +make: Unknown modifier ":t" while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34" in command "@echo ${FIB:t}" in target "mod-t-parse-3" -make: Bad modifier ":t" +make: Unknown modifier ":t" while evaluating variable "FIB" with value "1 1 2 3 5 8 13 21 34" in command "@echo ${FIB:t:M*}" in target "mod-t-parse-4" Index: src/usr.bin/make/unit-tests/moderrs.mk diff -u src/usr.bin/make/unit-tests/moderrs.mk:1.45 src/usr.bin/make/unit-tests/moderrs.mk:1.46 --- src/usr.bin/make/unit-tests/moderrs.mk:1.45 Sat Mar 29 19:08:52 2025 +++ src/usr.bin/make/unit-tests/moderrs.mk Sun Mar 30 00:35:52 2025 @@ -1,4 +1,4 @@ -# $NetBSD: moderrs.mk,v 1.45 2025/03/29 19:08:52 rillig Exp $ +# $NetBSD: moderrs.mk,v 1.46 2025/03/30 00:35:52 rillig Exp $ # # various modifier error tests @@ -153,26 +153,26 @@ mod-ts-parse-1: mod-ts-parse-2: @echo ${FIB:ts\65} # octal 065 == U+0035 == '5' mod-ts-parse-3: -# expect: make: Bad modifier ":ts\65oct" +# expect: make: Unknown modifier ":ts\65oct" @echo ${FIB:ts\65oct} # bad modifier mod-ts-parse-4: -# expect: make: Bad modifier ":ts\65oct" +# expect: make: Unknown modifier ":ts\65oct" @echo ${:U${FIB}:ts\65oct} # bad modifier, variable name is "" mod-ts-parse-5: -# expect: make: Bad modifier ":tsxy" +# expect: make: Unknown modifier ":tsxy" @echo ${FIB:tsxy} # modifier too long mod-t-parse-1: -# expect: make: Bad modifier ":t" +# expect: make: Unknown modifier ":t" @echo ${FIB:t mod-t-parse-2: -# expect: make: Bad modifier ":txy" +# expect: make: Unknown modifier ":txy" @echo ${FIB:txy} mod-t-parse-3: -# expect: make: Bad modifier ":t" +# expect: make: Unknown modifier ":t" @echo ${FIB:t} mod-t-parse-4: -# expect: make: Bad modifier ":t" +# expect: make: Unknown modifier ":t" @echo ${FIB:t:M*} mod-ifelse-parse-1: Index: src/usr.bin/make/unit-tests/varmod-sysv.mk diff -u src/usr.bin/make/unit-tests/varmod-sysv.mk:1.23 src/usr.bin/make/unit-tests/varmod-sysv.mk:1.24 --- src/usr.bin/make/unit-tests/varmod-sysv.mk:1.23 Sat Mar 29 11:51:54 2025 +++ src/usr.bin/make/unit-tests/varmod-sysv.mk Sun Mar 30 00:35:52 2025 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-sysv.mk,v 1.23 2025/03/29 11:51:54 rillig Exp $ +# $NetBSD: varmod-sysv.mk,v 1.24 2025/03/30 00:35:52 rillig Exp $ # # Tests for the variable modifier ':from=to', which replaces the suffix # "from" with "to". It can also use '%' as a wildcard. @@ -260,4 +260,27 @@ INDIRECT= 1:${VALUE} 2:$${VALUE} 4:$$$${ .endif +# The various ":t..." modifiers fall back to the ":from=to" modifier. +.if ${:Utarget:target=source} != "source" +. error +.endif +.if ${:Ufile.ts:ts=js} != "file.js" +. error +.endif +.if ${:Ufile.tsx:tsx=jsx} != "file.jsx" +. error +.endif +.if ${:Ufile.ts\\part:ts\part=replaced} != "file.replaced" +. error +.endif +.if ${:Ufile.ts\\123xyz:ts\123xyz=gone} != "file.gone" +. error +.endif +# Since the ":ts=" modifier is a valid form of the ":ts" modifier, don't fall +# back to the ":from=to" modifier. +.if ${:U1 2 3 file.ts:ts=} != "1=2=3=file.ts" +. error +.endif + + all: Index: src/usr.bin/make/unit-tests/varmod-to-separator.exp diff -u src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.19 src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.20 --- src/usr.bin/make/unit-tests/varmod-to-separator.exp:1.19 Sat Jan 11 20:54:46 2025 +++ src/usr.bin/make/unit-tests/varmod-to-separator.exp Sun Mar 30 00:35:52 2025 @@ -6,21 +6,21 @@ make: "varmod-to-separator.mk" line 177: while evaluating variable "word" with value "word" make: "varmod-to-separator.mk" line 183: Invalid character number at "112233445566778899}" while evaluating variable "word" with value "word" -make: "varmod-to-separator.mk" line 188: Bad modifier ":ts\-300" +make: "varmod-to-separator.mk" line 188: Unknown modifier ":ts\-300" while evaluating variable "WORDS" with value "one two three" -make: "varmod-to-separator.mk" line 197: Bad modifier ":ts\8" +make: "varmod-to-separator.mk" line 197: Unknown modifier ":ts\8" while evaluating variable "1 2 3" with value "1 2 3" -make: "varmod-to-separator.mk" line 205: Bad modifier ":ts\100L" +make: "varmod-to-separator.mk" line 205: Unknown modifier ":ts\100L" while evaluating variable "1 2 3" with value "1 2 3" -make: "varmod-to-separator.mk" line 213: Bad modifier ":ts\x40g" +make: "varmod-to-separator.mk" line 213: Unknown modifier ":ts\x40g" while evaluating variable "1 2 3" with value "1 2 3" -make: "varmod-to-separator.mk" line 222: Bad modifier ":tx" +make: "varmod-to-separator.mk" line 222: Unknown modifier ":tx" while evaluating variable "WORDS" with value "one two three four five six" -make: "varmod-to-separator.mk" line 230: Bad modifier ":ts\X" +make: "varmod-to-separator.mk" line 230: Unknown modifier ":ts\X" while evaluating variable "WORDS" with value "one two three four five six" -make: "varmod-to-separator.mk" line 239: Bad modifier ":t\X" +make: "varmod-to-separator.mk" line 239: Unknown modifier ":ts\X" while evaluating variable "WORDS" with value "one two three four five six" -make: "varmod-to-separator.mk" line 255: Bad modifier ":ts\69" +make: "varmod-to-separator.mk" line 255: Unknown modifier ":ts\69" while evaluating "${:Ua b:ts\69}" with value "a b" make: "varmod-to-separator.mk" line 263: Invalid character number at "1F60E}" while evaluating "${:Ua b:ts\x1F60E}" with value "a b" Index: src/usr.bin/make/unit-tests/varmod-to-separator.mk diff -u src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.22 src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.23 --- src/usr.bin/make/unit-tests/varmod-to-separator.mk:1.22 Sat Mar 29 17:31:34 2025 +++ src/usr.bin/make/unit-tests/varmod-to-separator.mk Sun Mar 30 00:35:52 2025 @@ -1,4 +1,4 @@ -# $NetBSD: varmod-to-separator.mk,v 1.22 2025/03/29 17:31:34 rillig Exp $ +# $NetBSD: varmod-to-separator.mk,v 1.23 2025/03/30 00:35:52 rillig Exp $ # # Tests for the :ts variable modifier, which joins the words of the variable # using an arbitrary character as word separator. @@ -184,7 +184,7 @@ WORDS= one two three four five six .endif # Negative numbers are not allowed for the separator character. -# expect+1: Bad modifier ":ts\-300" +# expect+1: Unknown modifier ":ts\-300" .if ${WORDS:[1..3]:ts\-300:tu} . error .else @@ -193,7 +193,7 @@ WORDS= one two three four five six # The character number is interpreted as octal number by default. # The digit '8' is not an octal digit though. -# expect+1: Bad modifier ":ts\8" +# expect+1: Unknown modifier ":ts\8" .if ${1 2 3:L:ts\8:tu} . error .else @@ -201,7 +201,7 @@ WORDS= one two three four five six .endif # Trailing characters after the octal character number are rejected. -# expect+1: Bad modifier ":ts\100L" +# expect+1: Unknown modifier ":ts\100L" .if ${1 2 3:L:ts\100L} . error .else @@ -209,7 +209,7 @@ WORDS= one two three four five six .endif # Trailing characters after the hexadecimal character number are rejected. -# expect+1: Bad modifier ":ts\x40g" +# expect+1: Unknown modifier ":ts\x40g" .if ${1 2 3:L:ts\x40g} . error .else @@ -218,7 +218,7 @@ WORDS= one two three four five six # In the :t modifier, the :t must be followed by any of A, l, s, u. -# expect+1: Bad modifier ":tx" +# expect+1: Unknown modifier ":tx" .if ${WORDS:tx} . error .else @@ -226,7 +226,7 @@ WORDS= one two three four five six .endif # The word separator can only be a single character. -# expect+1: Bad modifier ":ts\X" +# expect+1: Unknown modifier ":ts\X" .if ${WORDS:ts\X} . error .else @@ -235,8 +235,8 @@ WORDS= one two three four five six # After the backslash, only n, t, an octal number, or x and a hexadecimal # number are allowed. -# expect+1: Bad modifier ":t\X" -.if ${WORDS:t\X} != "anything" +# expect+1: Unknown modifier ":ts\X" +.if ${WORDS:ts\X} != "anything" . error .endif @@ -251,7 +251,7 @@ WORDS= one two three four five six # happens for non-octal digits. From 2003.07.23.18.06.46 to # 2016.02.27.16.20.06, the result was '1E2', since 2016.03.07.20.20.35 make no # longer accepts this escape and complains. -# expect+1: Bad modifier ":ts\69" +# expect+1: Unknown modifier ":ts\69" .if ${:Ua b:ts\69} . error .else Index: src/usr.bin/make/unit-tests/varmod.mk diff -u src/usr.bin/make/unit-tests/varmod.mk:1.24 src/usr.bin/make/unit-tests/varmod.mk:1.25 --- src/usr.bin/make/unit-tests/varmod.mk:1.24 Sat Mar 29 23:50:07 2025 +++ src/usr.bin/make/unit-tests/varmod.mk Sun Mar 30 00:35:52 2025 @@ -1,4 +1,4 @@ -# $NetBSD: varmod.mk,v 1.24 2025/03/29 23:50:07 rillig Exp $ +# $NetBSD: varmod.mk,v 1.25 2025/03/30 00:35:52 rillig Exp $ # # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback. # @@ -62,7 +62,7 @@ # | q | strict | | yes | # | range | strict | | no | # | sh | strict | | yes | -# | t | strict | | no | +# | t | strict | | yes | # | u | strict | | yes | # | from=to | greedy | SysV, fallback | --- |