Module Name: src Committed By: rillig Date: Sat Aug 19 11:09:02 UTC 2023
Modified Files: src/usr.bin/make: parse.c src/usr.bin/make/unit-tests: directive-export-gmake.exp directive-export-gmake.mk directive.exp directive.mk parse.exp parse.mk varname.exp varname.mk Log Message: make: show realistic invalid line in error message Previously, the error message 'Invalid line' showed only the expanded line, which might or might not show the actual problem. To be more helpful, add the unexpanded line to the error message in case they differ. Remove the special handling of invalid lines that result from merge conflicts. RCS is not commonly used anymore, and mentioning CVS was too specific. By echoing the whole line, the patterns '<<<<<<' and '>>>>>>' are clear enough to hint at the problem. To generate a diff of this commit: cvs rdiff -u -r1.705 -r1.706 src/usr.bin/make/parse.c cvs rdiff -u -r1.3 -r1.4 \ src/usr.bin/make/unit-tests/directive-export-gmake.exp cvs rdiff -u -r1.5 -r1.6 \ src/usr.bin/make/unit-tests/directive-export-gmake.mk \ src/usr.bin/make/unit-tests/parse.exp cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/directive.exp cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/directive.mk cvs rdiff -u -r1.6 -r1.7 src/usr.bin/make/unit-tests/parse.mk cvs rdiff -u -r1.19 -r1.20 src/usr.bin/make/unit-tests/varname.exp cvs rdiff -u -r1.12 -r1.13 src/usr.bin/make/unit-tests/varname.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/parse.c diff -u src/usr.bin/make/parse.c:1.705 src/usr.bin/make/parse.c:1.706 --- src/usr.bin/make/parse.c:1.705 Sat Aug 19 10:52:13 2023 +++ src/usr.bin/make/parse.c Sat Aug 19 11:09:02 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.705 2023/08/19 10:52:13 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.706 2023/08/19 11:09:02 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -105,7 +105,7 @@ #include "pathnames.h" /* "@(#)parse.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: parse.c,v 1.705 2023/08/19 10:52:13 rillig Exp $"); +MAKE_RCSID("$NetBSD: parse.c,v 1.706 2023/08/19 11:09:02 rillig Exp $"); /* Detects a multiple-inclusion guard in a makefile. */ typedef enum { @@ -871,14 +871,10 @@ MaybeUpdateMainTarget(void) } static void -InvalidLineType(const char *line) +InvalidLineType(const char *line, const char *unexpanded_line) { - if (strncmp(line, "<<<<<<", 6) == 0 || - strncmp(line, ">>>>>>", 6) == 0) - Parse_Error(PARSE_FATAL, - "Makefile appears to contain unresolved CVS/RCS/??? merge conflicts"); - else if (line[0] == '.') { - const char *dirstart = line + 1; + if (unexpanded_line[0] == '.') { + const char *dirstart = unexpanded_line + 1; const char *dirend; cpp_skip_whitespace(&dirstart); dirend = dirstart; @@ -886,8 +882,11 @@ InvalidLineType(const char *line) dirend++; Parse_Error(PARSE_FATAL, "Unknown directive \"%.*s\"", (int)(dirend - dirstart), dirstart); - } else + } else if (strcmp(line, unexpanded_line) == 0) Parse_Error(PARSE_FATAL, "Invalid line '%s'", line); + else + Parse_Error(PARSE_FATAL, "Invalid line '%s', expanded to '%s'", + unexpanded_line, line); } static void @@ -1398,7 +1397,8 @@ ParseDependencyTargets(char **pp, const char *lstart, ParseSpecial *inout_special, GNodeType *inout_targetAttr, - SearchPathList **inout_paths) + SearchPathList **inout_paths, + const char *unexpanded_line) { char *p = *pp; @@ -1423,7 +1423,7 @@ ParseDependencyTargets(char **pp, } if (*p == '\0') { - InvalidLineType(lstart); + InvalidLineType(lstart, unexpanded_line); return false; } @@ -1633,7 +1633,7 @@ ParseDependencySources(char *p, GNodeTyp * Upon return, the value of the line is unspecified. */ static void -ParseDependency(char *line) +ParseDependency(char *line, const char *unexpanded_line) { char *p; SearchPathList *paths; /* search paths to alter when parsing a list @@ -1650,7 +1650,8 @@ ParseDependency(char *line) targetAttr = OP_NONE; special = SP_NOT; - if (!ParseDependencyTargets(&p, line, &special, &targetAttr, &paths)) + if (!ParseDependencyTargets(&p, line, &special, &targetAttr, &paths, + unexpanded_line)) goto out; if (!Lst_IsEmpty(targets)) @@ -1658,7 +1659,7 @@ ParseDependency(char *line) op = ParseDependencyOp(&p); if (op == OP_NONE) { - InvalidLineType(line); + InvalidLineType(line, unexpanded_line); goto out; } ApplyDependencyOperator(op); @@ -2948,7 +2949,7 @@ ParseDependencyLine(char *line) Lst_Free(targets); targets = Lst_New(); - ParseDependency(expanded_line); + ParseDependency(expanded_line, line); free(expanded_line); if (shellcmd != NULL) Index: src/usr.bin/make/unit-tests/directive-export-gmake.exp diff -u src/usr.bin/make/unit-tests/directive-export-gmake.exp:1.3 src/usr.bin/make/unit-tests/directive-export-gmake.exp:1.4 --- src/usr.bin/make/unit-tests/directive-export-gmake.exp:1.3 Sat Aug 19 10:52:13 2023 +++ src/usr.bin/make/unit-tests/directive-export-gmake.exp Sat Aug 19 11:09:02 2023 @@ -1,4 +1,4 @@ -make: "directive-export-gmake.mk" line 73: Invalid line 'export VAR=1' +make: "directive-export-gmake.mk" line 71: Invalid line 'export VAR=${:U1}', expanded to 'export VAR=1' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive-export-gmake.mk diff -u src/usr.bin/make/unit-tests/directive-export-gmake.mk:1.5 src/usr.bin/make/unit-tests/directive-export-gmake.mk:1.6 --- src/usr.bin/make/unit-tests/directive-export-gmake.mk:1.5 Sat Aug 19 10:52:13 2023 +++ src/usr.bin/make/unit-tests/directive-export-gmake.mk Sat Aug 19 11:09:02 2023 @@ -1,4 +1,4 @@ -# $NetBSD: directive-export-gmake.mk,v 1.5 2023/08/19 10:52:13 rillig Exp $ +# $NetBSD: directive-export-gmake.mk,v 1.6 2023/08/19 11:09:02 rillig Exp $ # # Tests for the export directive (without leading dot), as in GNU make. @@ -65,10 +65,8 @@ export VAR=an ${UNDEF} variable # directive is only recognized if the line does not contain a ':', to allow # 'export' to be a regular target. .for value in 1 -# FIXME: The below error message is confusing because at the point -# where that error message is printed, all expressions from the line have -# already been expanded as part of the dependency line parsing, which in this -# case hides the ':' from the error message. -# expect+1: Invalid line 'export VAR=1' +# XXX: The ':' in this line is inside an expression and should thus not be +# interpreted as a dependency operator. +# expect+1: Invalid line 'export VAR=${:U1}' export VAR=${value} .endfor Index: src/usr.bin/make/unit-tests/parse.exp diff -u src/usr.bin/make/unit-tests/parse.exp:1.5 src/usr.bin/make/unit-tests/parse.exp:1.6 --- src/usr.bin/make/unit-tests/parse.exp:1.5 Sat Aug 19 10:52:14 2023 +++ src/usr.bin/make/unit-tests/parse.exp Sat Aug 19 11:09:02 2023 @@ -1,6 +1,6 @@ -make: "parse.mk" line 7: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts -make: "parse.mk" line 14: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts -make: "parse.mk" line 25: Invalid line 'one-target ' +make: "parse.mk" line 7: Invalid line '<<<<<< old' +make: "parse.mk" line 14: Invalid line '>>>>>> new' +make: "parse.mk" line 25: Invalid line 'one-target ${:U }', expanded to 'one-target ' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive.exp diff -u src/usr.bin/make/unit-tests/directive.exp:1.8 src/usr.bin/make/unit-tests/directive.exp:1.9 --- src/usr.bin/make/unit-tests/directive.exp:1.8 Sat Aug 19 10:52:14 2023 +++ src/usr.bin/make/unit-tests/directive.exp Sat Aug 19 11:09:02 2023 @@ -1,14 +1,14 @@ make: "directive.mk" line 10: Unknown directive "indented" make: "directive.mk" line 12: Unknown directive "indented" make: "directive.mk" line 14: Unknown directive "indented" -make: "directive.mk" line 21: Unknown directive "info" +make: "directive.mk" line 19: Unknown directive "" Global: .info = # (empty) Global: .info = value -make: "directive.mk" line 33: := value +make: "directive.mk" line 31: := value Global: .MAKEFLAGS = -r -k -d v -d Global: .MAKEFLAGS = -r -k -d v -d 0 -make: "directive.mk" line 42: Invalid line 'target-without-colon' -make: "directive.mk" line 45: Invalid line 'target-without-colon another-target' +make: "directive.mk" line 40: Invalid line 'target-without-colon' +make: "directive.mk" line 43: Invalid line 'target-without-colon another-target' make: Fatal errors encountered -- cannot continue make: stopped in unit-tests exit status 1 Index: src/usr.bin/make/unit-tests/directive.mk diff -u src/usr.bin/make/unit-tests/directive.mk:1.7 src/usr.bin/make/unit-tests/directive.mk:1.8 --- src/usr.bin/make/unit-tests/directive.mk:1.7 Sat Aug 19 10:52:14 2023 +++ src/usr.bin/make/unit-tests/directive.mk Sat Aug 19 11:09:02 2023 @@ -1,4 +1,4 @@ -# $NetBSD: directive.mk,v 1.7 2023/08/19 10:52:14 rillig Exp $ +# $NetBSD: directive.mk,v 1.8 2023/08/19 11:09:02 rillig Exp $ # # Tests for the preprocessing directives, such as .if or .info. @@ -15,9 +15,7 @@ # Directives must be written directly, not indirectly via variable # expressions. -# FIXME: The error message is misleading because it shows the expanded text of -# the line, while the parser works on the unexpanded line. -# expect+1: Unknown directive "info" +# expect+1: Unknown directive "" .${:Uinfo} directives cannot be indirect # There is no directive called '.target', therefore this is parsed as a Index: src/usr.bin/make/unit-tests/parse.mk diff -u src/usr.bin/make/unit-tests/parse.mk:1.6 src/usr.bin/make/unit-tests/parse.mk:1.7 --- src/usr.bin/make/unit-tests/parse.mk:1.6 Sat Aug 19 10:52:14 2023 +++ src/usr.bin/make/unit-tests/parse.mk Sat Aug 19 11:09:02 2023 @@ -1,16 +1,16 @@ -# $NetBSD: parse.mk,v 1.6 2023/08/19 10:52:14 rillig Exp $ +# $NetBSD: parse.mk,v 1.7 2023/08/19 11:09:02 rillig Exp $ # # Test those parts of the parsing that do not belong in any of the other # categories. -# expect+1: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts +# expect+1: Invalid line '<<<<<< old' <<<<<< old # No diagnostic since the following line is parsed as a variable assignment, # even though the variable name is empty. See also varname-empty.mk. ====== middle -# expect+1: Makefile appears to contain unresolved CVS/RCS/??? merge conflicts +# expect+1: Invalid line '>>>>>> new' >>>>>> new @@ -21,7 +21,7 @@ # the expanded line's terminating '\0'. # # https://bugs.freebsd.org/265119 -# expect+1: Invalid line 'one-target ' +# expect+1: Invalid line 'one-target ${:U }', expanded to 'one-target ' one-target ${:U } Index: src/usr.bin/make/unit-tests/varname.exp diff -u src/usr.bin/make/unit-tests/varname.exp:1.19 src/usr.bin/make/unit-tests/varname.exp:1.20 --- src/usr.bin/make/unit-tests/varname.exp:1.19 Sat Aug 19 10:52:14 2023 +++ src/usr.bin/make/unit-tests/varname.exp Sat Aug 19 11:09:02 2023 @@ -11,7 +11,7 @@ Var_Parse: ${:UVAR\(\(\(}= try2 (eval-de Evaluating modifier ${:U...} on value "" (eval-defined, undefined) Result of ${:UVAR\(\(\(} is "VAR\(\(\(" (eval-defined, defined) Global: .ALLTARGETS = VAR(((=) VAR\(\(\(= -make: "varname.mk" line 38: Invalid line 'VAR\(\(\(= try2' +make: "varname.mk" line 38: Invalid line '${:UVAR\(\(\(}= try2', expanded to 'VAR\(\(\(= try2' Var_Parse: ${VARNAME} (eval) Global: VAR((( = try3 Global: .MAKEFLAGS = -r -k -d v -d Index: src/usr.bin/make/unit-tests/varname.mk diff -u src/usr.bin/make/unit-tests/varname.mk:1.12 src/usr.bin/make/unit-tests/varname.mk:1.13 --- src/usr.bin/make/unit-tests/varname.mk:1.12 Sat Aug 19 10:52:14 2023 +++ src/usr.bin/make/unit-tests/varname.mk Sat Aug 19 11:09:02 2023 @@ -1,4 +1,4 @@ -# $NetBSD: varname.mk,v 1.12 2023/08/19 10:52:14 rillig Exp $ +# $NetBSD: varname.mk,v 1.13 2023/08/19 11:09:02 rillig Exp $ # # Tests for special variables, such as .MAKE or .PARSEDIR. # And for variable names in general. @@ -34,7 +34,7 @@ ${:UVAR(((}= try1 # as an escape character, therefore the parentheses still count to the nesting # level, which at the end of the line is still 3. Therefore this is not a # variable assignment as well. -# expect+1: Invalid line 'VAR\(\(\(= try2' +# expect+1: Invalid line '${:UVAR\(\(\(}= try2', expanded to 'VAR\(\(\(= try2' ${:UVAR\(\(\(}= try2 # To assign to a variable with an arbitrary name, the variable name has to # come from an external source, not the text that is parsed in the assignment