Module Name: src
Committed By: rillig
Date: Sun Nov 8 23:54:28 UTC 2020
Modified Files:
src/distrib/sets/lists/tests: mi
src/usr.bin/make: cond.c
src/usr.bin/make/unit-tests: Makefile
Added Files:
src/usr.bin/make/unit-tests: cond-op-and-lint.exp cond-op-and-lint.mk
cond-op-or-lint.exp cond-op-or-lint.mk
Log Message:
make(1): in lint mode, only allow '&&' and '||', not '&' and '|'
These variants of the condition operators are neither documented in the
manual page nor are they used in practice.
To generate a diff of this commit:
cvs rdiff -u -r1.964 -r1.965 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.196 -r1.197 src/usr.bin/make/cond.c
cvs rdiff -u -r1.191 -r1.192 src/usr.bin/make/unit-tests/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.bin/make/unit-tests/cond-op-and-lint.exp \
src/usr.bin/make/unit-tests/cond-op-and-lint.mk \
src/usr.bin/make/unit-tests/cond-op-or-lint.exp \
src/usr.bin/make/unit-tests/cond-op-or-lint.mk
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.964 src/distrib/sets/lists/tests/mi:1.965
--- src/distrib/sets/lists/tests/mi:1.964 Sun Nov 8 16:44:47 2020
+++ src/distrib/sets/lists/tests/mi Sun Nov 8 23:54:28 2020
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.964 2020/11/08 16:44:47 rillig Exp $
+# $NetBSD: mi,v 1.965 2020/11/08 23:54:28 rillig Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4859,10 +4859,14 @@
./usr/tests/usr.bin/make/unit-tests/cond-func.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-late.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-late.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-and-lint.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-and-lint.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-and.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-and.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-not.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-not.mk tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-or-lint.exp tests-usr.bin-tests compattestfile,atf
+./usr/tests/usr.bin/make/unit-tests/cond-op-or-lint.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-or.exp tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-or.mk tests-usr.bin-tests compattestfile,atf
./usr/tests/usr.bin/make/unit-tests/cond-op-parentheses.exp tests-usr.bin-tests compattestfile,atf
Index: src/usr.bin/make/cond.c
diff -u src/usr.bin/make/cond.c:1.196 src/usr.bin/make/cond.c:1.197
--- src/usr.bin/make/cond.c:1.196 Sun Nov 8 23:20:19 2020
+++ src/usr.bin/make/cond.c Sun Nov 8 23:54:28 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: cond.c,v 1.196 2020/11/08 23:20:19 rillig Exp $ */
+/* $NetBSD: cond.c,v 1.197 2020/11/08 23:54:28 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -93,7 +93,7 @@
#include "dir.h"
/* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */
-MAKE_RCSID("$NetBSD: cond.c,v 1.196 2020/11/08 23:20:19 rillig Exp $");
+MAKE_RCSID("$NetBSD: cond.c,v 1.197 2020/11/08 23:54:28 rillig Exp $");
/*
* The parsing of conditional expressions is based on this grammar:
@@ -836,15 +836,23 @@ CondParser_Token(CondParser *par, Boolea
case '|':
par->p++;
- if (par->p[0] == '|') {
+ if (par->p[0] == '|')
par->p++;
+ else if (opts.lint) {
+ Parse_Error(PARSE_FATAL, "Unknown operator '|'");
+ par->printedError = TRUE;
+ return TOK_ERROR;
}
return TOK_OR;
case '&':
par->p++;
- if (par->p[0] == '&') {
+ if (par->p[0] == '&')
par->p++;
+ else if (opts.lint) {
+ Parse_Error(PARSE_FATAL, "Unknown operator '&'");
+ par->printedError = TRUE;
+ return TOK_ERROR;
}
return TOK_AND;
Index: src/usr.bin/make/unit-tests/Makefile
diff -u src/usr.bin/make/unit-tests/Makefile:1.191 src/usr.bin/make/unit-tests/Makefile:1.192
--- src/usr.bin/make/unit-tests/Makefile:1.191 Sun Nov 8 16:44:47 2020
+++ src/usr.bin/make/unit-tests/Makefile Sun Nov 8 23:54:28 2020
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.191 2020/11/08 16:44:47 rillig Exp $
+# $NetBSD: Makefile,v 1.192 2020/11/08 23:54:28 rillig Exp $
#
# Unit tests for make(1)
#
@@ -62,8 +62,10 @@ TESTS+= cond-func-target
TESTS+= cond-late
TESTS+= cond-op
TESTS+= cond-op-and
+TESTS+= cond-op-and-lint
TESTS+= cond-op-not
TESTS+= cond-op-or
+TESTS+= cond-op-or-lint
TESTS+= cond-op-parentheses
TESTS+= cond-short
TESTS+= cond-token-number
Added files:
Index: src/usr.bin/make/unit-tests/cond-op-and-lint.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-op-and-lint.exp:1.1
--- /dev/null Sun Nov 8 23:54:28 2020
+++ src/usr.bin/make/unit-tests/cond-op-and-lint.exp Sun Nov 8 23:54:28 2020
@@ -0,0 +1,4 @@
+make: "cond-op-and-lint.mk" line 9: Unknown operator '&'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/cond-op-and-lint.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-op-and-lint.mk:1.1
--- /dev/null Sun Nov 8 23:54:28 2020
+++ src/usr.bin/make/unit-tests/cond-op-and-lint.mk Sun Nov 8 23:54:28 2020
@@ -0,0 +1,13 @@
+# $NetBSD: cond-op-and-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $
+#
+# Tests for the && operator in .if conditions, in lint mode.
+
+.MAKEFLAGS: -dL
+
+# The '&' operator is not allowed in lint mode.
+# It is not used in practice anyway.
+.if 0 & 0
+. error
+.else
+. error
+.endif
Index: src/usr.bin/make/unit-tests/cond-op-or-lint.exp
diff -u /dev/null src/usr.bin/make/unit-tests/cond-op-or-lint.exp:1.1
--- /dev/null Sun Nov 8 23:54:28 2020
+++ src/usr.bin/make/unit-tests/cond-op-or-lint.exp Sun Nov 8 23:54:28 2020
@@ -0,0 +1,4 @@
+make: "cond-op-or-lint.mk" line 9: Unknown operator '|'
+make: Fatal errors encountered -- cannot continue
+make: stopped in unit-tests
+exit status 1
Index: src/usr.bin/make/unit-tests/cond-op-or-lint.mk
diff -u /dev/null src/usr.bin/make/unit-tests/cond-op-or-lint.mk:1.1
--- /dev/null Sun Nov 8 23:54:28 2020
+++ src/usr.bin/make/unit-tests/cond-op-or-lint.mk Sun Nov 8 23:54:28 2020
@@ -0,0 +1,13 @@
+# $NetBSD: cond-op-or-lint.mk,v 1.1 2020/11/08 23:54:28 rillig Exp $
+#
+# Tests for the || operator in .if conditions, in lint mode.
+
+.MAKEFLAGS: -dL
+
+# The '|' operator is not allowed in lint mode.
+# It is not used in practice anyway.
+.if 0 | 0
+. error
+.else
+. error
+.endif