Module Name:    src
Committed By:   rillig
Date:           Sat Dec 19 22:33:12 UTC 2020

Modified Files:
        src/usr.bin/make: parse.c
        src/usr.bin/make/unit-tests: directive-if.exp directive-if.mk
            directive-info.exp directive-info.mk directive-warning.exp
            directive-warning.mk varmod.exp varmod.mk

Log Message:
make(1): fix error message for .info/.warning/.error without argument

Previously, the error message was "Unknown directive", which was
obviously wrong.  The new error message is "Missing argument".


To generate a diff of this commit:
cvs rdiff -u -r1.502 -r1.503 src/usr.bin/make/parse.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/make/unit-tests/directive-if.exp \
    src/usr.bin/make/unit-tests/directive-info.mk
cvs rdiff -u -r1.8 -r1.9 src/usr.bin/make/unit-tests/directive-if.mk
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/make/unit-tests/directive-info.exp \
    src/usr.bin/make/unit-tests/directive-warning.mk
cvs rdiff -u -r1.3 -r1.4 src/usr.bin/make/unit-tests/directive-warning.exp \
    src/usr.bin/make/unit-tests/varmod.exp
cvs rdiff -u -r1.4 -r1.5 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/parse.c
diff -u src/usr.bin/make/parse.c:1.502 src/usr.bin/make/parse.c:1.503
--- src/usr.bin/make/parse.c:1.502	Sat Dec 19 20:16:36 2020
+++ src/usr.bin/make/parse.c	Sat Dec 19 22:33:11 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.502 2020/12/19 20:16:36 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.503 2020/12/19 22:33:11 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -117,7 +117,7 @@
 #include "pathnames.h"
 
 /*	"@(#)parse.c	8.3 (Berkeley) 3/19/94"	*/
-MAKE_RCSID("$NetBSD: parse.c,v 1.502 2020/12/19 20:16:36 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.503 2020/12/19 22:33:11 rillig Exp $");
 
 /* types and constants */
 
@@ -723,13 +723,16 @@ Parse_Error(ParseErrorLevel type, const 
 
 /* Parse and handle a .info, .warning or .error directive.
  * For an .error directive, immediately exit. */
-static Boolean
-ParseMessage(ParseErrorLevel level, const char *umsg)
+static void
+ParseMessage(ParseErrorLevel level, const char *levelName, const char *umsg)
 {
 	char *xmsg;
 
-	if (umsg[0] == '\0')
-		return FALSE;	/* missing argument */
+	if (umsg[0] == '\0') {
+		Parse_Error(PARSE_FATAL, "Missing argument for \".%s\"",
+		    levelName);
+		return;
+	}
 
 	(void)Var_Subst(umsg, VAR_CMDLINE, VARE_WANTRES, &xmsg);
 	/* TODO: handle errors */
@@ -741,7 +744,6 @@ ParseMessage(ParseErrorLevel level, cons
 		PrintOnError(NULL, NULL);
 		exit(1);
 	}
-	return TRUE;
 }
 
 /* Add the child to the parent's children.
@@ -3070,14 +3072,14 @@ ParseDirective(char *line)
 		Var_UnExport(TRUE, arg);
 		return TRUE;
 	} else if (IsDirective(dir, dirlen, "info")) {
-		if (ParseMessage(PARSE_INFO, arg))
-			return TRUE;
+		ParseMessage(PARSE_INFO, "info", arg);
+		return TRUE;
 	} else if (IsDirective(dir, dirlen, "warning")) {
-		if (ParseMessage(PARSE_WARNING, arg))
-			return TRUE;
+		ParseMessage(PARSE_WARNING, "warning", arg);
+		return TRUE;
 	} else if (IsDirective(dir, dirlen, "error")) {
-		if (ParseMessage(PARSE_FATAL, arg))
-			return TRUE;
+		ParseMessage(PARSE_FATAL, "error", arg);
+		return TRUE;
 	}
 	return FALSE;
 }

Index: src/usr.bin/make/unit-tests/directive-if.exp
diff -u src/usr.bin/make/unit-tests/directive-if.exp:1.7 src/usr.bin/make/unit-tests/directive-if.exp:1.8
--- src/usr.bin/make/unit-tests/directive-if.exp:1.7	Mon Dec 14 21:02:25 2020
+++ src/usr.bin/make/unit-tests/directive-if.exp	Sat Dec 19 22:33:11 2020
@@ -1,9 +1,9 @@
 make: "directive-if.mk" line 13: 0 evaluates to false.
 make: "directive-if.mk" line 17: 1 evaluates to true.
 make: "directive-if.mk" line 40: Unknown directive "ifx"
-make: "directive-if.mk" line 41: Unknown directive "error"
+make: "directive-if.mk" line 41: This is not conditional.
 make: "directive-if.mk" line 42: if-less else
-make: "directive-if.mk" line 43: Unknown directive "error"
+make: "directive-if.mk" line 43: This is not conditional.
 make: "directive-if.mk" line 44: if-less endif
 make: "directive-if.mk" line 47: Malformed conditional ()
 make: "directive-if.mk" line 57: Quotes in plain words are probably a mistake.
Index: src/usr.bin/make/unit-tests/directive-info.mk
diff -u src/usr.bin/make/unit-tests/directive-info.mk:1.7 src/usr.bin/make/unit-tests/directive-info.mk:1.8
--- src/usr.bin/make/unit-tests/directive-info.mk:1.7	Sat Dec 19 12:40:00 2020
+++ src/usr.bin/make/unit-tests/directive-info.mk	Sat Dec 19 22:33:11 2020
@@ -1,12 +1,16 @@
-# $NetBSD: directive-info.mk,v 1.7 2020/12/19 12:40:00 rillig Exp $
+# $NetBSD: directive-info.mk,v 1.8 2020/12/19 22:33:11 rillig Exp $
 #
 # Tests for the .info directive.
+#
+# Until parse.c 1.502 from 2020-12-19, a missing argument to the directive
+# produced the wrong error message "Unknown directive".  Since parse.c 1.503
+# from 2020-12-19, the correct "Missing argument" is produced.
 
 # TODO: Implementation
 
 .info begin .info tests
 .inf				# misspelled
-.info				# oops: message should be "missing parameter"
+.info				# "Missing argument"
 .info message
 .info		indented message
 .information

Index: src/usr.bin/make/unit-tests/directive-if.mk
diff -u src/usr.bin/make/unit-tests/directive-if.mk:1.8 src/usr.bin/make/unit-tests/directive-if.mk:1.9
--- src/usr.bin/make/unit-tests/directive-if.mk:1.8	Mon Dec 14 21:02:25 2020
+++ src/usr.bin/make/unit-tests/directive-if.mk	Sat Dec 19 22:33:11 2020
@@ -1,4 +1,4 @@
-# $NetBSD: directive-if.mk,v 1.8 2020/12/14 21:02:25 rillig Exp $
+# $NetBSD: directive-if.mk,v 1.9 2020/12/19 22:33:11 rillig Exp $
 #
 # Tests for the .if directive.
 #
@@ -38,9 +38,9 @@
 # are interpreted as ordinary directives, producing the error messages
 # "if-less else" and "if-less endif".
 .ifx 123
-.  error
+.info This is not conditional.
 .else
-.  error
+.info This is not conditional.
 .endif
 
 # Missing condition.

Index: src/usr.bin/make/unit-tests/directive-info.exp
diff -u src/usr.bin/make/unit-tests/directive-info.exp:1.5 src/usr.bin/make/unit-tests/directive-info.exp:1.6
--- src/usr.bin/make/unit-tests/directive-info.exp:1.5	Sat Dec 19 12:40:00 2020
+++ src/usr.bin/make/unit-tests/directive-info.exp	Sat Dec 19 22:33:11 2020
@@ -1,15 +1,15 @@
-make: "directive-info.mk" line 7: begin .info tests
-make: "directive-info.mk" line 8: Unknown directive "inf"
-make: "directive-info.mk" line 9: Unknown directive "info"
-make: "directive-info.mk" line 10: message
-make: "directive-info.mk" line 11: indented message
-make: "directive-info.mk" line 12: Unknown directive "information"
-make: "directive-info.mk" line 13: Unknown directive "information"
-make: "directive-info.mk" line 18: Unknown directive "info"
-make: "directive-info.mk" line 19: Unknown directive "info"
-make: "directive-info.mk" line 22: Unknown directive "info-message"
-make: "directive-info.mk" line 23: no-target: no-source
-make: "directive-info.mk" line 32: expect line 30 for multi-line message
+make: "directive-info.mk" line 11: begin .info tests
+make: "directive-info.mk" line 12: Unknown directive "inf"
+make: "directive-info.mk" line 13: Missing argument for ".info"
+make: "directive-info.mk" line 14: message
+make: "directive-info.mk" line 15: indented message
+make: "directive-info.mk" line 16: Unknown directive "information"
+make: "directive-info.mk" line 17: Unknown directive "information"
+make: "directive-info.mk" line 22: Missing argument for ".info"
+make: "directive-info.mk" line 23: Missing argument for ".info"
+make: "directive-info.mk" line 26: Unknown directive "info-message"
+make: "directive-info.mk" line 27: no-target: no-source
+make: "directive-info.mk" line 36: expect line 30 for multi-line message
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
Index: src/usr.bin/make/unit-tests/directive-warning.mk
diff -u src/usr.bin/make/unit-tests/directive-warning.mk:1.5 src/usr.bin/make/unit-tests/directive-warning.mk:1.6
--- src/usr.bin/make/unit-tests/directive-warning.mk:1.5	Sun Dec 13 01:10:22 2020
+++ src/usr.bin/make/unit-tests/directive-warning.mk	Sat Dec 19 22:33:11 2020
@@ -1,6 +1,10 @@
-# $NetBSD: directive-warning.mk,v 1.5 2020/12/13 01:10:22 rillig Exp $
+# $NetBSD: directive-warning.mk,v 1.6 2020/12/19 22:33:11 rillig Exp $
 #
 # Tests for the .warning directive.
+#
+# Until parse.c 1.502 from 2020-12-19, a missing argument to the directive
+# produced the wrong error message "Unknown directive".  Since parse.c 1.503
+# from 2020-12-19, the correct "Missing argument" is produced.
 
 # TODO: Implementation
 
@@ -8,7 +12,7 @@
 .warn message			# misspelled
 .warnin				# misspelled
 .warnin	message			# misspelled
-.warning			# oops: should be "missing argument"
+.warning			# "Missing argument"
 .warning message		# ok
 .warnings			# misspelled
 .warnings messages		# Accepted before 2020-12-13 01:07:54.

Index: src/usr.bin/make/unit-tests/directive-warning.exp
diff -u src/usr.bin/make/unit-tests/directive-warning.exp:1.3 src/usr.bin/make/unit-tests/directive-warning.exp:1.4
--- src/usr.bin/make/unit-tests/directive-warning.exp:1.3	Sun Dec 13 01:07:54 2020
+++ src/usr.bin/make/unit-tests/directive-warning.exp	Sat Dec 19 22:33:11 2020
@@ -1,11 +1,11 @@
-make: "directive-warning.mk" line 7: Unknown directive "warn"
-make: "directive-warning.mk" line 8: Unknown directive "warn"
-make: "directive-warning.mk" line 9: Unknown directive "warnin"
-make: "directive-warning.mk" line 10: Unknown directive "warnin"
-make: "directive-warning.mk" line 11: Unknown directive "warning"
-make: "directive-warning.mk" line 12: warning: message
-make: "directive-warning.mk" line 13: Unknown directive "warnings"
-make: "directive-warning.mk" line 14: Unknown directive "warnings"
+make: "directive-warning.mk" line 11: Unknown directive "warn"
+make: "directive-warning.mk" line 12: Unknown directive "warn"
+make: "directive-warning.mk" line 13: Unknown directive "warnin"
+make: "directive-warning.mk" line 14: Unknown directive "warnin"
+make: "directive-warning.mk" line 15: Missing argument for ".warning"
+make: "directive-warning.mk" line 16: warning: message
+make: "directive-warning.mk" line 17: Unknown directive "warnings"
+make: "directive-warning.mk" line 18: Unknown directive "warnings"
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1
Index: src/usr.bin/make/unit-tests/varmod.exp
diff -u src/usr.bin/make/unit-tests/varmod.exp:1.3 src/usr.bin/make/unit-tests/varmod.exp:1.4
--- src/usr.bin/make/unit-tests/varmod.exp:1.3	Mon Nov  2 17:30:22 2020
+++ src/usr.bin/make/unit-tests/varmod.exp	Sat Dec 19 22:33:11 2020
@@ -2,7 +2,7 @@ make: "varmod.mk" line 42: To escape a d
 make: "varmod.mk" line 42: Invalid variable name ':', at "$:L} != """
 make: "varmod.mk" line 47: Dollar followed by nothing
 make: "varmod.mk" line 56: Missing delimiter ':' after modifier "P"
-make: "varmod.mk" line 57: Unknown directive "error"
+make: "varmod.mk" line 57: Missing argument for ".error"
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests
 exit status 1

Index: src/usr.bin/make/unit-tests/varmod.mk
diff -u src/usr.bin/make/unit-tests/varmod.mk:1.4 src/usr.bin/make/unit-tests/varmod.mk:1.5
--- src/usr.bin/make/unit-tests/varmod.mk:1.4	Mon Nov  2 17:30:22 2020
+++ src/usr.bin/make/unit-tests/varmod.mk	Sat Dec 19 22:33:11 2020
@@ -1,4 +1,4 @@
-# $NetBSD: varmod.mk,v 1.4 2020/11/02 17:30:22 rillig Exp $
+# $NetBSD: varmod.mk,v 1.5 2020/12/19 22:33:11 rillig Exp $
 #
 # Tests for variable modifiers, such as :Q, :S,from,to or :Ufallback.
 
@@ -51,7 +51,7 @@ DOLLAR2=	${:U\$}
 # The variable modifier :P does not fall back to the SysV modifier.
 # Therefore the modifier :P=RE generates a parse error.
 # XXX: The .error should not be reached since the variable expression is
-# malformed.
+# malformed, and this error should be propagated up to Cond_EvalLine.
 VAR=	STOP
 .if ${VAR:P=RE} != "STORE"
 .  error

Reply via email to