Module Name: src Committed By: rillig Date: Mon Jun 19 20:07:35 UTC 2023
Modified Files: src/usr.bin/make: cond.c src/usr.bin/make/unit-tests: directive-include-guard.exp directive-include-guard.mk Log Message: make: add tests for full code coverage of multiple-inclusion guards To generate a diff of this commit: cvs rdiff -u -r1.348 -r1.349 src/usr.bin/make/cond.c cvs rdiff -u -r1.4 -r1.5 \ src/usr.bin/make/unit-tests/directive-include-guard.exp cvs rdiff -u -r1.5 -r1.6 \ src/usr.bin/make/unit-tests/directive-include-guard.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/cond.c diff -u src/usr.bin/make/cond.c:1.348 src/usr.bin/make/cond.c:1.349 --- src/usr.bin/make/cond.c:1.348 Mon Jun 19 17:30:56 2023 +++ src/usr.bin/make/cond.c Mon Jun 19 20:07:35 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: cond.c,v 1.348 2023/06/19 17:30:56 rillig Exp $ */ +/* $NetBSD: cond.c,v 1.349 2023/06/19 20:07:35 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990 The Regents of the University of California. @@ -92,7 +92,7 @@ #include "dir.h" /* "@(#)cond.c 8.2 (Berkeley) 1/2/94" */ -MAKE_RCSID("$NetBSD: cond.c,v 1.348 2023/06/19 17:30:56 rillig Exp $"); +MAKE_RCSID("$NetBSD: cond.c,v 1.349 2023/06/19 20:07:35 rillig Exp $"); /* * Conditional expressions conform to this grammar: @@ -1259,11 +1259,10 @@ ParseVarnameGuard(const char **pp, const char * Cond_ExtractGuard(const char *line) { - const char *p = line, *varname; + const char *p, *varname; Substring dir; - if (!skip_string(&p, ".")) - return NULL; + p = line + 1; /* skip the '.' */ cpp_skip_hspace(&p); dir.start = p; Index: src/usr.bin/make/unit-tests/directive-include-guard.exp diff -u src/usr.bin/make/unit-tests/directive-include-guard.exp:1.4 src/usr.bin/make/unit-tests/directive-include-guard.exp:1.5 --- src/usr.bin/make/unit-tests/directive-include-guard.exp:1.4 Mon Jun 19 12:53:57 2023 +++ src/usr.bin/make/unit-tests/directive-include-guard.exp Mon Jun 19 20:07:35 2023 @@ -6,10 +6,20 @@ Parse_PushInput: file guarded-if.tmp, li Skipping 'guarded-if.tmp' because 'GUARDED_IF' is already set Parse_PushInput: file triple-negation.tmp, line 1 Parse_PushInput: file triple-negation.tmp, line 1 +Parse_PushInput: file ifdef-negated.tmp, line 1 +Parse_PushInput: file ifdef-negated.tmp, line 1 Parse_PushInput: file varname-mismatch.tmp, line 1 Parse_PushInput: file varname-mismatch.tmp, line 1 -Parse_PushInput: file varname-indirect.tmp, line 1 -Skipping 'varname-indirect.tmp' because 'VARNAME_INDIRECT' is already set +Parse_PushInput: file ifndef-plus.tmp, line 1 +Parse_PushInput: file ifndef-plus.tmp, line 1 +Parse_PushInput: file if-plus.tmp, line 1 +Parse_PushInput: file if-plus.tmp, line 1 +Parse_PushInput: file ifndef-indirect.tmp, line 1 +Parse_PushInput: file ifndef-indirect.tmp, line 1 +Parse_PushInput: file if-indirect.tmp, line 1 +Parse_PushInput: file if-indirect.tmp, line 1 +Parse_PushInput: file varassign-indirect.tmp, line 1 +Skipping 'varassign-indirect.tmp' because 'VARASSIGN_INDIRECT' is already set Parse_PushInput: file late-assignment.tmp, line 1 Skipping 'late-assignment.tmp' because 'LATE_ASSIGNMENT' is already set Parse_PushInput: file two-conditions.tmp, line 1 Index: src/usr.bin/make/unit-tests/directive-include-guard.mk diff -u src/usr.bin/make/unit-tests/directive-include-guard.mk:1.5 src/usr.bin/make/unit-tests/directive-include-guard.mk:1.6 --- src/usr.bin/make/unit-tests/directive-include-guard.mk:1.5 Mon Jun 19 12:53:57 2023 +++ src/usr.bin/make/unit-tests/directive-include-guard.mk Mon Jun 19 20:07:35 2023 @@ -1,4 +1,4 @@ -# $NetBSD: directive-include-guard.mk,v 1.5 2023/06/19 12:53:57 rillig Exp $ +# $NetBSD: directive-include-guard.mk,v 1.6 2023/06/19 20:07:35 rillig Exp $ # # Tests for multiple-inclusion guards in makefiles. # @@ -59,6 +59,16 @@ LINES.triple-negation= \ # expect: Parse_PushInput: file triple-negation.tmp, line 1 # expect: Parse_PushInput: file triple-negation.tmp, line 1 +# A conditional other than '.if' or '.ifndef' marks the file as non-guarded, +# even if it would actually work as a multiple-inclusion guard. +INCS+= ifdef-negated +LINES.ifdef-negated= \ + '.ifdef !IFDEF_NEGATED' \ + 'IFDEF_NEGATED=' \ + '.endif' +# expect: Parse_PushInput: file ifdef-negated.tmp, line 1 +# expect: Parse_PushInput: file ifdef-negated.tmp, line 1 + # The variable names in the '.if' and the assignment must be the same. INCS+= varname-mismatch LINES.varname-mismatch= \ @@ -68,16 +78,56 @@ LINES.varname-mismatch= \ # expect: Parse_PushInput: file varname-mismatch.tmp, line 1 # expect: Parse_PushInput: file varname-mismatch.tmp, line 1 +# The guard condition must consist of only the guard variable, nothing else. +INCS+= ifndef-plus +LINES.ifndef-plus= \ + '.ifndef IFNDEF_PLUS && IFNDEF_SECOND' \ + 'IFNDEF_PLUS=' \ + 'IFNDEF_SECOND=' \ + '.endif' +# expect: Parse_PushInput: file ifndef-plus.tmp, line 1 +# expect: Parse_PushInput: file ifndef-plus.tmp, line 1 + +# The guard condition must consist of only the guard variable, nothing else. +INCS+= if-plus +LINES.if-plus= \ + '.if !defined(IF_PLUS) && !defined(IF_SECOND)' \ + 'IF_PLUS=' \ + 'IF_SECOND=' \ + '.endif' +# expect: Parse_PushInput: file if-plus.tmp, line 1 +# expect: Parse_PushInput: file if-plus.tmp, line 1 + +# The variable name in an '.ifndef' guard must be given directly, it must not +# contain any '$' expression. +INCS+= ifndef-indirect +LINES.ifndef-indirect= \ + '.ifndef $${IFNDEF_INDIRECT:L}' \ + 'IFNDEF_INDIRECT=' \ + '.endif' +# expect: Parse_PushInput: file ifndef-indirect.tmp, line 1 +# expect: Parse_PushInput: file ifndef-indirect.tmp, line 1 + +# The variable name in an '.if' guard must be given directly, it must not contain +# any '$' expression. +INCS+= if-indirect +LINES.if-indirect= \ + '.if !defined($${IF_INDIRECT:L})' \ + 'IF_INDIRECT=' \ + '.endif' +# expect: Parse_PushInput: file if-indirect.tmp, line 1 +# expect: Parse_PushInput: file if-indirect.tmp, line 1 + # The variable name in the guard condition must only contain alphanumeric # characters and underscores. The guard variable is more flexible, it can be # set anywhere, as long as it is set when the guarded file is included next. -INCS+= varname-indirect -LINES.varname-indirect= \ - '.ifndef VARNAME_INDIRECT' \ - 'VARNAME_$${:UINDIRECT}=' \ +INCS+= varassign-indirect +LINES.varassign-indirect= \ + '.ifndef VARASSIGN_INDIRECT' \ + '$${VARASSIGN_INDIRECT:L}=' \ '.endif' -# expect: Parse_PushInput: file varname-indirect.tmp, line 1 -# expect: Skipping 'varname-indirect.tmp' because 'VARNAME_INDIRECT' is already set +# expect: Parse_PushInput: file varassign-indirect.tmp, line 1 +# expect: Skipping 'varassign-indirect.tmp' because 'VARASSIGN_INDIRECT' is already set # The time at which the guard variable is set doesn't matter, as long as it is # set when the file is included the next time.