From 118ec9dfc5d1e928e3c7236096edae2f0c74e4e0 Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 5 Sep 2020 18:13:47 +0000 Subject: [PATCH] make(1): add test for .INCLUDEDFILE combined with .for loops The .for loops are implemented as a special kind of .include, therefore they affect the .INCLUDEDFROM variable. --- usr.bin/make/unit-tests/include-main.exp | 8 ++++++-- usr.bin/make/unit-tests/include-main.mk | 18 +++++++++++++++++- usr.bin/make/unit-tests/include-sub.mk | 23 +++++++++++++++++++++-- usr.bin/make/unit-tests/include-subsub.mk | 6 +++--- 4 files changed, 47 insertions(+), 8 deletions(-) diff --git a/usr.bin/make/unit-tests/include-main.exp b/usr.bin/make/unit-tests/include-main.exp index ce0bd7e8e357..984e7f5c3e22 100644 --- a/usr.bin/make/unit-tests/include-main.exp +++ b/usr.bin/make/unit-tests/include-main.exp @@ -1,6 +1,10 @@ make: "include-main.mk" line 12: main-before-ok +make: "include-main.mk" line 19: main-before-for-ok make: "include-sub.mk" line 4: sub-before-ok +make: "include-sub.mk" line 14: sub-before-for-ok make: "include-subsub.mk" line 4: subsub-ok -make: "include-sub.mk" line 14: warning: sub-after-fail(include-sub.mk) -make: "include-main.mk" line 22: warning: main-after-fail(include-sub.mk) +make: "include-sub.mk" line 25: warning: sub-after-fail(include-sub.mk) +make: "include-sub.mk" line 32: warning: sub-after-for-fail(include-sub.mk) +make: "include-main.mk" line 30: warning: main-after-fail(include-sub.mk) +make: "include-main.mk" line 35: main-after-for-ok exit status 0 diff --git a/usr.bin/make/unit-tests/include-main.mk b/usr.bin/make/unit-tests/include-main.mk index d8db9234e939..2cd9e7592380 100644 --- a/usr.bin/make/unit-tests/include-main.mk +++ b/usr.bin/make/unit-tests/include-main.mk @@ -1,4 +1,4 @@ -# $NetBSD: include-main.mk,v 1.3 2020/09/05 16:59:19 rillig Exp $ +# $NetBSD: include-main.mk,v 1.4 2020/09/05 18:13:47 rillig Exp $ # # Demonstrates that the .INCLUDEDFROMFILE magic variable does not behave # as described in the manual page. @@ -14,6 +14,14 @@ . warning main-before-fail(${.INCLUDEDFROMFILE}) .endif +.for i in once +. if !defined(${.INCLUDEDFROMFILE}) +. info main-before-for-ok +. else +. warning main-before-for-fail(${.INCLUDEDFROMFILE}) +. endif +.endfor + .include "include-sub.mk" .if !defined(.INCLUDEDFROMFILE) @@ -22,4 +30,12 @@ . warning main-after-fail(${.INCLUDEDFROMFILE}) .endif +.for i in once +. if !defined(${.INCLUDEDFROMFILE}) +. info main-after-for-ok +. else +. warning main-after-for-fail(${.INCLUDEDFROMFILE}) +. endif +.endfor + all: # nothing diff --git a/usr.bin/make/unit-tests/include-sub.mk b/usr.bin/make/unit-tests/include-sub.mk index 449f62cccdfe..6a283d43bf7f 100644 --- a/usr.bin/make/unit-tests/include-sub.mk +++ b/usr.bin/make/unit-tests/include-sub.mk @@ -1,11 +1,22 @@ -# $NetBSD: include-sub.mk,v 1.2 2020/09/05 16:59:19 rillig Exp $ +# $NetBSD: include-sub.mk,v 1.3 2020/09/05 18:13:47 rillig Exp $ .if ${.INCLUDEDFROMFILE} == "include-main.mk" . info sub-before-ok .else -. warning sub-before-fail +. warning sub-before-fail(${.INCLUDEDFROMFILE}) .endif +# As of 2020-09-05, the .for loop is implemented as "including a file" +# with a custom buffer. Therefore this loop has side effects on these +# variables. +.for i in once +. if ${.INCLUDEDFROMFILE} == "include-main.mk" +. info sub-before-for-ok +. else +. warning sub-before-for-fail(${.INCLUDEDFROMFILE}) +. endif +.endfor + .include "include-subsub.mk" .if ${.INCLUDEDFROMFILE} == "include-main.mk" @@ -13,3 +24,11 @@ .else . warning sub-after-fail(${.INCLUDEDFROMFILE}) .endif + +.for i in once +. if ${.INCLUDEDFROMFILE} == "include-main.mk" +. info sub-after-for-ok +. else +. warning sub-after-for-fail(${.INCLUDEDFROMFILE}) +. endif +.endfor diff --git a/usr.bin/make/unit-tests/include-subsub.mk b/usr.bin/make/unit-tests/include-subsub.mk index 871e99b76326..915d36d8a2a2 100644 --- a/usr.bin/make/unit-tests/include-subsub.mk +++ b/usr.bin/make/unit-tests/include-subsub.mk @@ -1,7 +1,7 @@ -# $NetBSD: include-subsub.mk,v 1.2 2020/09/05 16:59:19 rillig Exp $ +# $NetBSD: include-subsub.mk,v 1.3 2020/09/05 18:13:47 rillig Exp $ -.if ${.INCLUDEDFROMFILE:T} == "include-sub.mk" +.if ${.INCLUDEDFROMFILE} == "include-sub.mk" . info subsub-ok .else -. warning subsub-fail +. warning subsub-fail(${.INCLUDEDFROMFILE}) .endif