Module Name: src Committed By: rillig Date: Wed Aug 7 05:48:45 UTC 2024
Modified Files: src/usr.bin/make: cond.c src/usr.bin/make/unit-tests: cond-func.exp cond-func.mk directive-include-guard.exp directive-include-guard.mk Log Message: make: in erroneous conditions, report the non-expanded text In a condition, when a function call expression is missing its closing parenthesis, there's no point in having the expanded argument text in the error message. When parsing a bare word in a condition, the trailing space was included in that word, which was inconsistent, as the leading space was not included either. Removing the trailing space from the word reduces the cases where a multiple-inclusion guard steps in, but only in an edge case that is irrelevant in practice. To generate a diff of this commit: cvs rdiff -u -r1.368 -r1.369 src/usr.bin/make/cond.c cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/cond-func.exp cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/cond-func.mk \ src/usr.bin/make/unit-tests/directive-include-guard.mk cvs rdiff -u -r1.15 -r1.16 \ src/usr.bin/make/unit-tests/directive-include-guard.exp 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/cond.c diff -u src/usr.bin/make/cond.c:1.368 src/usr.bin/make/cond.c:1.369 --- src/usr.bin/make/cond.c:1.368 Tue Aug 6 18:00:16 2024 +++ src/usr.bin/make/cond.c Wed Aug 7 05:48:45 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.368 2024/08/06 18:00:16 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.369 2024/08/07 05:48:45 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -91,7 +91,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.368 2024/08/06 18:00:16 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.369 2024/08/07 05:48:45 rillig Exp $"); /* * Conditional expressions conform to this grammar: @@ -242,7 +242,6 @@ ParseWord(const char **pp, bool doEval) p++; } - cpp_skip_hspace(&p); *pp = p; return Buf_DoneData(&word); @@ -252,12 +251,14 @@ ParseWord(const char **pp, bool doEval) static char * ParseFuncArg(CondParser *par, const char **pp, bool doEval, const char *func) { - const char *p = *pp; + const char *p = *pp, *argStart, *argEnd; char *res; p++; /* skip the '(' */ cpp_skip_hspace(&p); + argStart = p; res = ParseWord(&p, doEval); + argEnd = p; cpp_skip_hspace(&p); if (*p++ != ')') { @@ -266,8 +267,8 @@ ParseFuncArg(CondParser *par, const char len++; Parse_Error(PARSE_FATAL, - "Missing ')' after argument '%s' for '%.*s'", - res, len, func); + "Missing ')' after argument '%.*s' for '%.*s'", + (int)(argEnd - argStart), argStart, len, func); par->printedError = true; free(res); return NULL; @@ -735,6 +736,7 @@ CondParser_ComparisonOrLeaf(CondParser * */ arg = ParseWord(&p, doEval); assert(arg[0] != '\0'); + cpp_skip_hspace(&p); if (*p == '=' || *p == '!' || *p == '<' || *p == '>') { free(arg); Index: src/usr.bin/make/unit-tests/cond-func.exp diff -u src/usr.bin/make/unit-tests/cond-func.exp:1.12 src/usr.bin/make/unit-tests/cond-func.exp:1.13 --- src/usr.bin/make/unit-tests/cond-func.exp:1.12 Wed Aug 7 05:37:11 2024 +++ src/usr.bin/make/unit-tests/cond-func.exp Wed Aug 7 05:48:45 2024 @@ -7,7 +7,7 @@ make: "cond-func.mk" line 115: A plain f make: "cond-func.mk" line 126: Symbols may start with a function name. make: "cond-func.mk" line 132: Symbols may start with a function name. make: "cond-func.mk" line 138: Missing ')' after argument '' for 'defined' -make: "cond-func.mk" line 146: Missing ')' after argument 'VARNAME.param' for 'defined' +make: "cond-func.mk" line 145: Missing ')' after argument '${:UVARNAME}.param' for 'defined' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/cond-func.mk diff -u src/usr.bin/make/unit-tests/cond-func.mk:1.17 src/usr.bin/make/unit-tests/cond-func.mk:1.18 --- src/usr.bin/make/unit-tests/cond-func.mk:1.17 Wed Aug 7 05:37:11 2024 +++ src/usr.bin/make/unit-tests/cond-func.mk Wed Aug 7 05:48:45 2024 @@ -1,4 +1,4 @@ -# $NetBSD: cond-func.mk,v 1.17 2024/08/07 05:37:11 rillig Exp $ +# $NetBSD: cond-func.mk,v 1.18 2024/08/07 05:48:45 rillig Exp $ # # Tests for those parts of the functions in .if conditions that are common # among several functions. @@ -141,8 +141,7 @@ defined-var= # defined but empty . error .endif -# XXX: Don't use the expanded argument in the diagnostic. -# expect+1: Missing ')' after argument 'VARNAME.param' for 'defined' +# expect+1: Missing ')' after argument '${:UVARNAME}.param' for 'defined' .if defined(${:UVARNAME}.param extra) . error .else Index: src/usr.bin/make/unit-tests/directive-include-guard.mk diff -u src/usr.bin/make/unit-tests/directive-include-guard.mk:1.17 src/usr.bin/make/unit-tests/directive-include-guard.mk:1.18 --- src/usr.bin/make/unit-tests/directive-include-guard.mk:1.17 Wed Aug 7 05:37:11 2024 +++ src/usr.bin/make/unit-tests/directive-include-guard.mk Wed Aug 7 05:48:45 2024 @@ -1,4 +1,4 @@ -# $NetBSD: directive-include-guard.mk,v 1.17 2024/08/07 05:37:11 rillig Exp $ +# $NetBSD: directive-include-guard.mk,v 1.18 2024/08/07 05:48:45 rillig Exp $ # # Tests for multiple-inclusion guards in makefiles. # @@ -581,7 +581,7 @@ LINES.target-name-exclamation= \ # expect: Parse_PushInput: file target-name-exclamation.tmp, line 1 # expect: Parse_PushInput: file target-name-exclamation.tmp, line 1 -# If the guard target name is enclosed in spaces, it does not have an effect, +# If the guard target name has leading spaces, it does not have an effect, # as that form is not common in practice. CASES+= target-name-leading-space LINES.target-name-leading-space= \ @@ -591,13 +591,15 @@ LINES.target-name-leading-space= \ # expect: Parse_PushInput: file target-name-leading-space.tmp, line 1 # expect: Parse_PushInput: file target-name-leading-space.tmp, line 1 +# If the guard target name has trailing spaces, it does not have an effect, +# as that form is not common in practice. CASES+= target-name-trailing-space LINES.target-name-trailing-space= \ '.if !target(target-name-trailing-space )' \ 'target-name-trailing-space: .NOTMAIN' \ '.endif' # expect: Parse_PushInput: file target-name-trailing-space.tmp, line 1 -# expect: Skipping 'target-name-trailing-space.tmp' because 'target-name-trailing-space' is defined +# expect: Parse_PushInput: file target-name-trailing-space.tmp, line 1 # If the guard target condition is enclosed in parentheses, it does not have # an effect, as that form is not common in practice. Index: src/usr.bin/make/unit-tests/directive-include-guard.exp diff -u src/usr.bin/make/unit-tests/directive-include-guard.exp:1.15 src/usr.bin/make/unit-tests/directive-include-guard.exp:1.16 --- src/usr.bin/make/unit-tests/directive-include-guard.exp:1.15 Wed Aug 7 05:37:11 2024 +++ src/usr.bin/make/unit-tests/directive-include-guard.exp Wed Aug 7 05:48:45 2024 @@ -98,7 +98,7 @@ Parse_PushInput: file target-name-exclam Parse_PushInput: file target-name-leading-space.tmp, line 1 Parse_PushInput: file target-name-leading-space.tmp, line 1 Parse_PushInput: file target-name-trailing-space.tmp, line 1 -Skipping 'target-name-trailing-space.tmp' because 'target-name-trailing-space' is defined +Parse_PushInput: file target-name-trailing-space.tmp, line 1 Parse_PushInput: file target-call-parenthesized.tmp, line 1 Parse_PushInput: file target-call-parenthesized.tmp, line 1 Parse_PushInput: file multiline.tmp, line 1