Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make make(1): error out on misspelled .unexport-env



details:   https://anonhg.NetBSD.org/src/rev/02de734ef8ec
branches:  trunk
changeset: 947167:02de734ef8ec
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Dec 12 18:00:18 2020 +0000

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

diffstat:

 usr.bin/make/unit-tests/directive-unexport-env.exp |   6 +++-
 usr.bin/make/unit-tests/directive-unexport-env.mk  |  12 +++++--
 usr.bin/make/var.c                                 |  30 ++++++++++++++-------
 3 files changed, 33 insertions(+), 15 deletions(-)

diffs (104 lines):

diff -r 56903db4252a -r 02de734ef8ec usr.bin/make/unit-tests/directive-unexport-env.exp
--- a/usr.bin/make/unit-tests/directive-unexport-env.exp        Sat Dec 12 16:54:20 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-unexport-env.exp        Sat Dec 12 18:00:18 2020 +0000
@@ -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 @@
 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
diff -r 56903db4252a -r 02de734ef8ec usr.bin/make/unit-tests/directive-unexport-env.mk
--- a/usr.bin/make/unit-tests/directive-unexport-env.mk Sat Dec 12 16:54:20 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-unexport-env.mk Sat Dec 12 18:00:18 2020 +0000
@@ -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
diff -r 56903db4252a -r 02de734ef8ec usr.bin/make/var.c
--- a/usr.bin/make/var.c        Sat Dec 12 16:54:20 2020 +0000
+++ b/usr.bin/make/var.c        Sat Dec 12 18:00:18 2020 +0000
@@ -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 @@
 }
 
 static void
-GetVarnamesToUnexport(const char *str,
+GetVarnamesToUnexport(const char *directive,
                      FStr *out_varnames, UnexportWhat *out_what)
 {
        UnexportWhat what;
        FStr varnames = FSTR_INIT;
-
-       str += strlen("unexport");
-       if (strncmp(str, "-env", 4) == 0)
+       const char *p = directive;
+
+       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) {



Home | Main Index | Thread Index | Old Index