Module Name: src Committed By: rillig Date: Sun Sep 13 19:28:46 UTC 2020
Modified Files: src/usr.bin/make: var.c src/usr.bin/make/unit-tests: opt-debug-lint.exp opt-debug-lint.mk Log Message: make(1): in lint mode, improve error handling for undefined variables It's a first step for improving the error message that make prints. To generate a diff of this commit: cvs rdiff -u -r1.515 -r1.516 src/usr.bin/make/var.c cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/opt-debug-lint.exp \ src/usr.bin/make/unit-tests/opt-debug-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/usr.bin/make/var.c diff -u src/usr.bin/make/var.c:1.515 src/usr.bin/make/var.c:1.516 --- src/usr.bin/make/var.c:1.515 Sun Sep 13 19:16:22 2020 +++ src/usr.bin/make/var.c Sun Sep 13 19:28:46 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: var.c,v 1.515 2020/09/13 19:16:22 rillig Exp $ */ +/* $NetBSD: var.c,v 1.516 2020/09/13 19:28:46 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -121,7 +121,7 @@ #include "metachar.h" /* "@(#)var.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: var.c,v 1.515 2020/09/13 19:16:22 rillig Exp $"); +MAKE_RCSID("$NetBSD: var.c,v 1.516 2020/09/13 19:28:46 rillig Exp $"); #define VAR_DEBUG_IF(cond, fmt, ...) \ if (!(DEBUG(VAR) && (cond))) \ @@ -3489,8 +3489,10 @@ Var_Parse(const char **pp, GNode *ctxt, if (v == NULL) { *pp += 2; - *out_val = ShortVarValue(start[1], ctxt, eflags); - return eflags & VARE_UNDEFERR ? VPE_UNDEF_SILENT : VPE_OK; + *out_val = ShortVarValue(startc, ctxt, eflags); + if (DEBUG(LINT) && *out_val == var_Error) + Parse_Error(PARSE_FATAL, "Variable \"%s\" is undefined", name); + return eflags & VARE_UNDEFERR ? VPE_UNDEF_MSG : VPE_OK; } else { haveModifier = FALSE; p = start + 1; Index: src/usr.bin/make/unit-tests/opt-debug-lint.exp diff -u src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.1 src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.2 --- src/usr.bin/make/unit-tests/opt-debug-lint.exp:1.1 Sat Sep 5 06:20:51 2020 +++ src/usr.bin/make/unit-tests/opt-debug-lint.exp Sun Sep 13 19:28:46 2020 @@ -1 +1,5 @@ -exit status 0 +make: "opt-debug-lint.mk" line 18: Variable "X" is undefined +make: "opt-debug-lint.mk" line 18: Malformed conditional ($X) +make: Fatal errors encountered -- cannot continue +make: stopped in unit-tests +exit status 1 Index: src/usr.bin/make/unit-tests/opt-debug-lint.mk diff -u src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.1 src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.2 --- src/usr.bin/make/unit-tests/opt-debug-lint.mk:1.1 Sat Sep 5 06:20:51 2020 +++ src/usr.bin/make/unit-tests/opt-debug-lint.mk Sun Sep 13 19:28:46 2020 @@ -1,9 +1,36 @@ -# $NetBSD: opt-debug-lint.mk,v 1.1 2020/09/05 06:20:51 rillig Exp $ +# $NetBSD: opt-debug-lint.mk,v 1.2 2020/09/13 19:28:46 rillig Exp $ # # Tests for the -dL command line option, which runs additional checks # to catch common mistakes, such as unclosed variable expressions. -# TODO: Implementation +.MAKEFLAGS: -dL + +# Since 2020-09-13, undefined variables that are used on the left-hand side +# of a condition at parse time get a proper error message. Before, the +# error message was "Malformed conditional" only, which was wrong and +# misleading. The form of the condition is totally fine, it's the evaluation +# that fails. +# +# TODO: Get rid of the "Malformed conditional" error message. +# As long as the first error message is only printed in lint mode, it can +# get tricky to keep track of the actually printed error messages and those +# that still need to be printed. That's probably a solvable problem though. +.if $X +. error +.endif + +# The dynamic variables like .TARGET are treated specially. It does not make +# sense to expand them in the global scope since they will never be defined +# there under normal circumstances. Therefore they expand to a string that +# will later be expanded correctly, when the variable is evaluated again in +# the scope of an actual target. +# +# Even though the "@" variable is not defined at this point, this is not an +# error. In all practical cases, this is no problem. This particular test +# case is made up and unrealistic. +.if $@ != "\$(.TARGET)" +. error +.endif all: @:;