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 directives
details: https://anonhg.NetBSD.org/src/rev/cc73a41eebf4
branches: trunk
changeset: 979077:cc73a41eebf4
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Dec 13 01:07:54 2020 +0000
description:
make(1): error out on misspelled directives
Before, make accepted misspellings like .warnings, .export-literally and
a few others, all of which are unlikely to occur in practice. See the
test directive-misspellings.mk for further details.
diffstat:
usr.bin/make/parse.c | 82 ++++++++++++--------
usr.bin/make/unit-tests/directive-error.mk | 6 +-
usr.bin/make/unit-tests/directive-export-env.mk | 4 +-
usr.bin/make/unit-tests/directive-export-literal.mk | 4 +-
usr.bin/make/unit-tests/directive-export.exp | 5 +-
usr.bin/make/unit-tests/directive-export.mk | 12 +-
usr.bin/make/unit-tests/directive-info.exp | 2 +-
usr.bin/make/unit-tests/directive-info.mk | 4 +-
usr.bin/make/unit-tests/directive-misspellings.exp | 13 ++-
usr.bin/make/unit-tests/directive-misspellings.mk | 24 +++---
usr.bin/make/unit-tests/directive-undef.exp | 5 +-
usr.bin/make/unit-tests/directive-undef.mk | 7 +-
usr.bin/make/unit-tests/directive-unexport.exp | 14 +--
usr.bin/make/unit-tests/directive-unexport.mk | 7 +-
usr.bin/make/unit-tests/directive-warning.exp | 2 +-
usr.bin/make/unit-tests/directive-warning.mk | 4 +-
16 files changed, 103 insertions(+), 92 deletions(-)
diffs (truncated from 473 to 300 lines):
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/parse.c
--- a/usr.bin/make/parse.c Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/parse.c Sun Dec 13 01:07:54 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.474 2020/12/12 21:35:21 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.475 2020/12/13 01:07:54 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.474 2020/12/12 21:35:21 rillig Exp $");
+MAKE_RCSID("$NetBSD: parse.c,v 1.475 2020/12/13 01:07:54 rillig Exp $");
/* types and constants */
@@ -726,26 +726,20 @@
/* Parse and handle a .info, .warning or .error directive.
* For an .error directive, immediately exit. */
static Boolean
-ParseMessage(const char *directive)
+ParseMessage(ParseErrorLevel level, const char *umsg)
{
- const char *p = directive;
- ParseErrorLevel mtype = *p == 'i' ? PARSE_INFO :
- *p == 'w' ? PARSE_WARNING : PARSE_FATAL;
- char *arg;
-
- while (ch_isalpha(*p))
- p++;
- if (!ch_isspace(*p))
+ char *xmsg;
+
+ if (umsg[0] == '\0')
return FALSE; /* missing argument */
- cpp_skip_whitespace(&p);
- (void)Var_Subst(p, VAR_CMDLINE, VARE_WANTRES, &arg);
+ (void)Var_Subst(umsg, VAR_CMDLINE, VARE_WANTRES, &xmsg);
/* TODO: handle errors */
- Parse_Error(mtype, "%s", arg);
- free(arg);
-
- if (mtype == PARSE_FATAL) {
+ Parse_Error(level, "%s", xmsg);
+ free(xmsg);
+
+ if (level == PARSE_FATAL) {
PrintOnError(NULL, NULL);
exit(1);
}
@@ -2949,6 +2943,12 @@
}
}
+MAKE_INLINE Boolean
+IsDirective(const char *dir, size_t dirlen, const char *name)
+{
+ return dirlen == strlen(name) && memcmp(dir, name, dirlen) == 0;
+}
+
/*
* Lines that begin with '.' can be pretty much anything:
* - directives like '.include' or '.if',
@@ -2960,6 +2960,8 @@
ParseDirective(char *line)
{
char *cp = line + 1;
+ const char *dir, *arg;
+ size_t dirlen;
pp_skip_whitespace(&cp);
if (IsInclude(cp, FALSE)) {
@@ -2967,30 +2969,42 @@
return TRUE;
}
- if (strncmp(cp, "undef", 5) == 0) {
- const char *varname;
- cp += 5;
- pp_skip_whitespace(&cp);
- varname = cp;
+ dir = cp;
+ while (ch_isalpha(*cp) || *cp == '-')
+ cp++;
+ dirlen = (size_t)(cp - dir);
+
+ if (*cp != '\0' && !ch_isspace(*cp))
+ return FALSE;
+
+ pp_skip_whitespace(&cp);
+ arg = cp;
+
+ if (IsDirective(dir, dirlen, "undef")) {
for (; !ch_isspace(*cp) && *cp != '\0'; cp++)
continue;
*cp = '\0';
- Var_Delete(varname, VAR_GLOBAL);
+ Var_Delete(arg, VAR_GLOBAL);
/* TODO: undefine all variables, not only the first */
/* TODO: use Str_Words, like everywhere else */
return TRUE;
- } else if (strncmp(cp, "export", 6) == 0) {
- cp += 6;
- pp_skip_whitespace(&cp);
- Var_Export(cp);
+ } else if (IsDirective(dir, dirlen, "export") ||
+ IsDirective(dir, dirlen, "export-env") ||
+ IsDirective(dir, dirlen, "export-literal")) {
+ Var_Export(dir + strlen("export"));
+ return TRUE;
+ } else if (IsDirective(dir, dirlen, "unexport") ||
+ IsDirective(dir, dirlen, "unexport-env")) {
+ Var_UnExport(dir);
return TRUE;
- } else if (strncmp(cp, "unexport", 8) == 0) {
- Var_UnExport(cp);
- return TRUE;
- } else if (strncmp(cp, "info", 4) == 0 ||
- strncmp(cp, "error", 5) == 0 ||
- strncmp(cp, "warning", 7) == 0) {
- if (ParseMessage(cp))
+ } else if (IsDirective(dir, dirlen, "info")) {
+ if (ParseMessage(PARSE_INFO, arg))
+ return TRUE;
+ } else if (IsDirective(dir, dirlen, "warning")) {
+ if (ParseMessage(PARSE_WARNING, arg))
+ return TRUE;
+ } else if (IsDirective(dir, dirlen, "error")) {
+ if (ParseMessage(PARSE_FATAL, arg))
return TRUE;
}
return FALSE;
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-error.mk
--- a/usr.bin/make/unit-tests/directive-error.mk Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-error.mk Sun Dec 13 01:07:54 2020 +0000
@@ -1,6 +1,8 @@
-# $NetBSD: directive-error.mk,v 1.2 2020/08/16 14:25:16 rillig Exp $
+# $NetBSD: directive-error.mk,v 1.3 2020/12/13 01:07:54 rillig Exp $
#
-# Tests for the .error directive.
+# Tests for the .error directive, which prints an error message and exits
+# immediately, unlike other "fatal" parse errors, which continue to parse
+# until the end of the current top-level makefile.
# TODO: Implementation
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-export-env.mk
--- a/usr.bin/make/unit-tests/directive-export-env.mk Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-export-env.mk Sun Dec 13 01:07:54 2020 +0000
@@ -1,12 +1,10 @@
-# $NetBSD: directive-export-env.mk,v 1.3 2020/11/03 17:17:31 rillig Exp $
+# $NetBSD: directive-export-env.mk,v 1.4 2020/12/13 01:07:54 rillig Exp $
#
# Tests for the .export-env directive.
# TODO: Implementation
-.export-en # oops: misspelled
.export-env
-.export-environment # oops: misspelled
all:
@:;
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-export-literal.mk
--- a/usr.bin/make/unit-tests/directive-export-literal.mk Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-export-literal.mk Sun Dec 13 01:07:54 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-export-literal.mk,v 1.6 2020/11/03 17:17:31 rillig Exp $
+# $NetBSD: directive-export-literal.mk,v 1.7 2020/12/13 01:07:54 rillig Exp $
#
# Tests for the .export-literal directive, which exports a variable value
# without expanding it.
@@ -7,9 +7,7 @@
.export-literal UT_VAR
-.export-litera # oops: misspelled
.export-literal # oops: missing argument
-.export-literally # oops: misspelled
all:
@echo "$$UT_VAR"
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-export.exp
--- a/usr.bin/make/unit-tests/directive-export.exp Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-export.exp Sun Dec 13 01:07:54 2020 +0000
@@ -1,4 +1,1 @@
-make: "directive-export.mk" line 29: Unknown directive "expor"
-make: Fatal errors encountered -- cannot continue
-make: stopped in unit-tests
-exit status 1
+exit status 0
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-export.mk
--- a/usr.bin/make/unit-tests/directive-export.mk Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-export.mk Sun Dec 13 01:07:54 2020 +0000
@@ -1,6 +1,9 @@
-# $NetBSD: directive-export.mk,v 1.5 2020/12/12 19:31:18 rillig Exp $
+# $NetBSD: directive-export.mk,v 1.6 2020/12/13 01:07:54 rillig Exp $
#
# Tests for the .export directive.
+#
+# See also:
+# directive-misspellings.mk
# TODO: Implementation
@@ -25,11 +28,8 @@
. error
.endif
-# Tests for parsing the .export directive.
-.expor # misspelled
-.export # oops: missing argument
-.export VARNAME
-.exporting works # oops: misspelled
+# No argument means to export all variables.
+.export
all:
@:;
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-info.exp
--- a/usr.bin/make/unit-tests/directive-info.exp Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-info.exp Sun Dec 13 01:07:54 2020 +0000
@@ -4,7 +4,7 @@
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: message
+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"
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-info.mk
--- a/usr.bin/make/unit-tests/directive-info.mk Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-info.mk Sun Dec 13 01:07:54 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: directive-info.mk,v 1.4 2020/11/15 11:57:00 rillig Exp $
+# $NetBSD: directive-info.mk,v 1.5 2020/12/13 01:07:54 rillig Exp $
#
# Tests for the .info directive.
@@ -10,7 +10,7 @@
.info message
.info indented message
.information
-.information message # oops: misspelled
+.information message # Accepted before 2020-12-13 01:??:??.
.info.man: # not a message, but possibly a suffix rule
# Even if lines would have trailing whitespace, this would be trimmed by
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-misspellings.exp
--- a/usr.bin/make/unit-tests/directive-misspellings.exp Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-misspellings.exp Sun Dec 13 01:07:54 2020 +0000
@@ -5,6 +5,12 @@
make: "directive-misspellings.mk" line 18: Unknown directive "errox"
make: "directive-misspellings.mk" line 22: Unknown directive "expor"
make: "directive-misspellings.mk" line 24: Unknown directive "exporx"
+make: "directive-misspellings.mk" line 25: Unknown directive "exports"
+make: "directive-misspellings.mk" line 27: Unknown directive "export-en"
+make: "directive-misspellings.mk" line 30: Unknown directive "export-environment"
+make: "directive-misspellings.mk" line 32: Unknown directive "export-litera"
+make: "directive-misspellings.mk" line 34: Unknown directive "export-literax"
+make: "directive-misspellings.mk" line 35: Unknown directive "export-literally"
make: "directive-misspellings.mk" line 37: Unknown directive "-includ"
make: "directive-misspellings.mk" line 39: Unknown directive "-includx"
make: "directive-misspellings.mk" line 40: .include filename must be delimited by '"' or '<'
@@ -15,15 +21,16 @@
make: "directive-misspellings.mk" line 47: Unknown directive "inf"
make: "directive-misspellings.mk" line 48: msg
make: "directive-misspellings.mk" line 49: Unknown directive "infx"
-make: "directive-misspellings.mk" line 50: msg
+make: "directive-misspellings.mk" line 50: Unknown directive "infos"
make: "directive-misspellings.mk" line 52: Unknown directive "sinclud"
make: "directive-misspellings.mk" line 54: Unknown directive "sincludx"
make: "directive-misspellings.mk" line 55: .include filename must be delimited by '"' or '<'
make: "directive-misspellings.mk" line 57: Unknown directive "unde"
make: "directive-misspellings.mk" line 59: Unknown directive "undex"
+make: "directive-misspellings.mk" line 60: Unknown directive "undefs"
make: "directive-misspellings.mk" line 62: Unknown directive "unexpor"
make: "directive-misspellings.mk" line 64: Unknown directive "unexporx"
-make: "directive-misspellings.mk" line 65: Unknown directive "unexports varname"
+make: "directive-misspellings.mk" line 65: Unknown directive "unexports"
make: "directive-misspellings.mk" line 67: Unknown directive "unexport-en"
make: "directive-misspellings.mk" line 69: The directive .unexport-env does not take arguments
make: "directive-misspellings.mk" line 70: Unknown directive "unexport-enx"
@@ -32,7 +39,7 @@
make: "directive-misspellings.mk" line 74: Unknown directive "warnin"
make: "directive-misspellings.mk" line 75: warning: msg
make: "directive-misspellings.mk" line 76: Unknown directive "warninx"
-make: "directive-misspellings.mk" line 77: warning: msg
+make: "directive-misspellings.mk" line 77: Unknown directive "warnings"
make: Fatal errors encountered -- cannot continue
make: stopped in unit-tests
exit status 1
diff -r 419afdf7757d -r cc73a41eebf4 usr.bin/make/unit-tests/directive-misspellings.mk
--- a/usr.bin/make/unit-tests/directive-misspellings.mk Sun Dec 13 00:46:25 2020 +0000
+++ b/usr.bin/make/unit-tests/directive-misspellings.mk Sun Dec 13 01:07:54 2020 +0000
Home |
Main Index |
Thread Index |
Old Index