Module Name: src Committed By: rillig Date: Sun Jun 18 19:16:51 UTC 2023
Modified Files: src/usr.bin/make/unit-tests: directive-include-guard.exp directive-include-guard.mk Log Message: tests/make: extend test for multiple-inclusion guards To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 \ src/usr.bin/make/unit-tests/directive-include-guard.exp \ 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/unit-tests/directive-include-guard.exp diff -u src/usr.bin/make/unit-tests/directive-include-guard.exp:1.1 src/usr.bin/make/unit-tests/directive-include-guard.exp:1.2 --- src/usr.bin/make/unit-tests/directive-include-guard.exp:1.1 Fri Jun 16 09:25:13 2023 +++ src/usr.bin/make/unit-tests/directive-include-guard.exp Sun Jun 18 19:16:51 2023 @@ -22,4 +22,14 @@ Parse_PushInput: file directive-include- Parse_PushInput: file directive-include-guard-reuse.tmp, line 1 Parse_PushInput: file directive-include-guard-swapped.tmp, line 1 Parse_PushInput: file directive-include-guard-swapped.tmp, line 1 +Parse_PushInput: file directive-include-guard-undef-between.tmp, line 1 +Parse_PushInput: file directive-include-guard-undef-between.tmp, line 1 +Parse_PushInput: file directive-include-guard-undef-inside.tmp, line 1 +Parse_PushInput: file directive-include-guard-undef-inside.tmp, line 1 +Parse_PushInput: file directive-include-guard-if-elif.tmp, line 1 +Parse_PushInput: file directive-include-guard-if-elif.tmp, line 1 +Parse_PushInput: file directive-include-guard-if-else.tmp, line 1 +Parse_PushInput: file directive-include-guard-if-else.tmp, line 1 +Parse_PushInput: file directive-include-guard-inner-if-elif-else.tmp, line 1 +Parse_PushInput: file directive-include-guard-inner-if-elif-else.tmp, line 1 exit status 0 Index: src/usr.bin/make/unit-tests/directive-include-guard.mk diff -u src/usr.bin/make/unit-tests/directive-include-guard.mk:1.1 src/usr.bin/make/unit-tests/directive-include-guard.mk:1.2 --- src/usr.bin/make/unit-tests/directive-include-guard.mk:1.1 Fri Jun 16 09:25:13 2023 +++ src/usr.bin/make/unit-tests/directive-include-guard.mk Sun Jun 18 19:16:51 2023 @@ -1,4 +1,4 @@ -# $NetBSD: directive-include-guard.mk,v 1.1 2023/06/16 09:25:13 rillig Exp $ +# $NetBSD: directive-include-guard.mk,v 1.2 2023/06/18 19:16:51 rillig Exp $ # # Tests for multiple-inclusion guards in makefiles. # @@ -9,9 +9,12 @@ # ... # .endif # -# When such a file is included for the second time, it has no effect as all +# When such a file is included for the second time, it has no effect, as all # its content is skipped. # +# See also: +# https://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html +# # TODO: In these cases, do not include the file, to increase performance. @@ -66,6 +69,11 @@ LINES.varname-indirect= \ '.endif' # The variable assignment for the guard must directly follow the conditional. +# +# This requirement may be dropped entirely later, as the guard variable could +# also be undefined while reading the file or at a later point, and as long as +# the implementation checks the guard variable before skipping the file, the +# optimization is still valid. INCS+= late-assignment LINES.late-assignment= \ '.ifndef LATE_ASSIGNMENT' \ @@ -78,7 +86,7 @@ LINES.late-assignment= \ INCS+= two-conditions LINES.two-conditions= \ '.ifndef TWO_CONDITIONS' \ - '. if 0' \ + '. if 1' \ 'TWO_CONDITIONS=' \ '. endif' \ '.endif' @@ -119,6 +127,57 @@ LINES.swapped= \ '.ifndef SWAPPED' \ '.endif' +# If the guard variable is undefined at some later point, the guarded file is +# included again. +INCS+= undef-between +LINES.undef-between= \ + '.ifndef UNDEF_BETWEEN' \ + 'UNDEF_BETWEEN=' \ + '.endif' + +# If the guarded file undefines the guard variable, the guarded file is +# included again. +INCS+= undef-inside +LINES.undef-inside= \ + '.ifndef UNDEF_INSIDE' \ + 'UNDEF_INSIDE=' \ + '.undef UNDEF_INSIDE' \ + '.endif' + +# The outermost '.if' must not have an '.elif' branch. +INCS+= if-elif +LINES.if-elif = \ + '.ifndef IF_ELIF' \ + 'IF_ELIF=' \ + '.elif 1' \ + '.endif' + +# The outermost '.if' must not have an '.else' branch. +INCS+= if-else +LINES.if-else = \ + '.ifndef IF_ELSE' \ + 'IF_ELSE=' \ + '.else' \ + '.endif' + +# The inner '.if' directives may have an '.elif' or '.else'. +INCS+= inner-if-elif-else +LINES.inner-if-elif-else = \ + '.ifndef INNER_IF_ELIF_ELSE' \ + 'INNER_IF_ELIF_ELSE=' \ + '. if 0' \ + '. elif 0' \ + '. else' \ + '. endif' \ + '. if 0' \ + '. elif 1' \ + '. else' \ + '. endif' \ + '. if 1' \ + '. elif 1' \ + '. else' \ + '. endif' \ + '.endif' # Include each of the files twice. The directive-include-guard.exp file # contains a single entry for the files whose multiple-inclusion guard works, @@ -131,6 +190,7 @@ LINES.swapped= \ _!= printf '%s\n' ${LINES.$i} > ${fname} .MAKEFLAGS: -dp .include "${.CURDIR}/${fname}" +.undef ${i:Mundef-between:%=UNDEF_BETWEEN} .include "${.CURDIR}/${fname}" .MAKEFLAGS: -d0 _!= rm ${fname}