Module Name:    src
Committed By:   rillig
Date:           Sat Dec 12 18:00:18 UTC 2020

Modified Files:
        src/usr.bin/make: var.c
        src/usr.bin/make/unit-tests: directive-unexport-env.exp
            directive-unexport-env.mk

Log Message:
make(1): error out on misspelled .unexport-env


To generate a diff of this commit:
cvs rdiff -u -r1.722 -r1.723 src/usr.bin/make/var.c
cvs rdiff -u -r1.2 -r1.3 \
    src/usr.bin/make/unit-tests/directive-unexport-env.exp
cvs rdiff -u -r1.5 -r1.6 \
    src/usr.bin/make/unit-tests/directive-unexport-env.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.722 src/usr.bin/make/var.c:1.723
--- src/usr.bin/make/var.c:1.722	Sat Dec 12 00:53:23 2020
+++ src/usr.bin/make/var.c	Sat Dec 12 18:00:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: var.c,v 1.722 2020/12/12 00:53:23 rillig Exp $	*/
+/*	$NetBSD: var.c,v 1.723 2020/12/12 18:00:18 rillig Exp $	*/
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -130,7 +130,7 @@
 #include "metachar.h"
 
 /*	"@(#)var.c	8.3 (Berkeley) 3/19/94" */
-MAKE_RCSID("$NetBSD: var.c,v 1.722 2020/12/12 00:53:23 rillig Exp $");
+MAKE_RCSID("$NetBSD: var.c,v 1.723 2020/12/12 18:00:18 rillig Exp $");
 
 /* A string that may need to be freed after use. */
 typedef struct FStr {
@@ -751,20 +751,30 @@ ClearEnv(void)
 }
 
 static void
-GetVarnamesToUnexport(const char *str,
+GetVarnamesToUnexport(const char *directive,
 		      FStr *out_varnames, UnexportWhat *out_what)
 {
 	UnexportWhat what;
 	FStr varnames = FSTR_INIT;
+	const char *p = directive;
 
-	str += strlen("unexport");
-	if (strncmp(str, "-env", 4) == 0)
+	p += strlen("unexport");
+	if (strncmp(p, "-env", 4) == 0) {
+		if (ch_isspace(p[4])) {
+			Parse_Error(PARSE_FATAL,
+			    "The directive .unexport-env does not take "
+			    "arguments");
+		} else if (p[4] != '\0') {
+			Parse_Error(PARSE_FATAL,
+			    "Unknown directive \"%s\"", directive);
+		}
 		what = UNEXPORT_ENV;
-	else {
-		cpp_skip_whitespace(&str);
-		what = str[0] != '\0' ? UNEXPORT_NAMED : UNEXPORT_ALL;
+
+	} else {
+		cpp_skip_whitespace(&p);
+		what = p[0] != '\0' ? UNEXPORT_NAMED : UNEXPORT_ALL;
 		if (what == UNEXPORT_NAMED)
-			FStr_Assign(&varnames, str, NULL);
+			FStr_Assign(&varnames, p, NULL);
 	}
 
 	if (what != UNEXPORT_NAMED) {

Index: src/usr.bin/make/unit-tests/directive-unexport-env.exp
diff -u src/usr.bin/make/unit-tests/directive-unexport-env.exp:1.2 src/usr.bin/make/unit-tests/directive-unexport-env.exp:1.3
--- src/usr.bin/make/unit-tests/directive-unexport-env.exp:1.2	Sun Dec  6 16:06:11 2020
+++ src/usr.bin/make/unit-tests/directive-unexport-env.exp	Sat Dec 12 18:00:18 2020
@@ -1,6 +1,8 @@
+make: "directive-unexport-env.mk" line 15: Unknown directive "unexport-environment"
 Global:UT_EXPORTED = value
 Global:UT_UNEXPORTED = value
 Global:.MAKE.EXPORTED = UT_EXPORTED
+make: "directive-unexport-env.mk" line 21: The directive .unexport-env does not take arguments
 Var_Parse: ${.MAKE.EXPORTED:O:u} with VARE_WANTRES
 Applying ${.MAKE.EXPORTED:O} to "UT_EXPORTED" (VARE_WANTRES, none, none)
 Result of ${.MAKE.EXPORTED:O} is "UT_EXPORTED" (VARE_WANTRES, none, none)
@@ -10,4 +12,6 @@ Unexporting "UT_EXPORTED"
 Global:delete .MAKE.EXPORTED
 Global:.MAKEFLAGS =  -r -k -d v -d
 Global:.MAKEFLAGS =  -r -k -d v -d 0
-exit status 0
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1

Index: src/usr.bin/make/unit-tests/directive-unexport-env.mk
diff -u src/usr.bin/make/unit-tests/directive-unexport-env.mk:1.5 src/usr.bin/make/unit-tests/directive-unexport-env.mk:1.6
--- src/usr.bin/make/unit-tests/directive-unexport-env.mk:1.5	Sun Dec  6 17:29:27 2020
+++ src/usr.bin/make/unit-tests/directive-unexport-env.mk	Sat Dec 12 18:00:18 2020
@@ -1,15 +1,19 @@
-# $NetBSD: directive-unexport-env.mk,v 1.5 2020/12/06 17:29:27 rillig Exp $
+# $NetBSD: directive-unexport-env.mk,v 1.6 2020/12/12 18:00:18 rillig Exp $
 #
 # Tests for the .unexport-env directive.
+#
+# Before 2020-12-13, the directive unexport-env wrongly accepted arguments
+# and ignored them.
+#
+# Before 2020-12-13, misspelled directive names like "unexport-environment"
+# were not properly detected.
 
 # TODO: Implementation
 
 .unexport-en			# oops: misspelled
 .unexport-env			# ok
-.unexport-environment		# oops: misspelled
+.unexport-environment		# misspelled
 
-# As of 2020-12-06, the directive unexport-env is not supposed to accept
-# arguments, but it does without complaining about them.
 .MAKEFLAGS: -dv
 UT_EXPORTED=	value
 UT_UNEXPORTED=	value

Reply via email to