Module Name:    src
Committed By:   rillig
Date:           Thu Jun  1 09:02:14 UTC 2023

Modified Files:
        src/usr.bin/make: for.c
        src/usr.bin/make/unit-tests: directive-for-empty.exp
            directive-for-escape.exp directive-for-escape.mk directive-for.exp
            opt-debug-for.exp

Log Message:
make: add more details to debug logging of .for loops


To generate a diff of this commit:
cvs rdiff -u -r1.175 -r1.176 src/usr.bin/make/for.c
cvs rdiff -u -r1.1 -r1.2 src/usr.bin/make/unit-tests/directive-for-empty.exp
cvs rdiff -u -r1.19 -r1.20 \
    src/usr.bin/make/unit-tests/directive-for-escape.exp
cvs rdiff -u -r1.18 -r1.19 \
    src/usr.bin/make/unit-tests/directive-for-escape.mk
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/make/unit-tests/directive-for.exp
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/make/unit-tests/opt-debug-for.exp

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/for.c
diff -u src/usr.bin/make/for.c:1.175 src/usr.bin/make/for.c:1.176
--- src/usr.bin/make/for.c:1.175	Thu Jun  1 07:44:10 2023
+++ src/usr.bin/make/for.c	Thu Jun  1 09:02:14 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: for.c,v 1.175 2023/06/01 07:44:10 rillig Exp $	*/
+/*	$NetBSD: for.c,v 1.176 2023/06/01 09:02:14 rillig Exp $	*/
 
 /*
  * Copyright (c) 1992, The Regents of the University of California.
@@ -58,7 +58,7 @@
 #include "make.h"
 
 /*	"@(#)for.c	8.1 (Berkeley) 6/6/93"	*/
-MAKE_RCSID("$NetBSD: for.c,v 1.175 2023/06/01 07:44:10 rillig Exp $");
+MAKE_RCSID("$NetBSD: for.c,v 1.176 2023/06/01 09:02:14 rillig Exp $");
 
 
 typedef struct ForLoop {
@@ -513,7 +513,12 @@ For_NextIteration(ForLoop *f, Buffer *bo
 
 	f->nextItem += (unsigned int)f->vars.len;
 	ForLoop_SubstBody(f, f->nextItem - (unsigned int)f->vars.len, body);
-	DEBUG1(FOR, "For: loop body:\n%s", body->data);
+	if (DEBUG(FOR)) {
+		char *details = ForLoop_Details(f);
+		debug_printf("For: loop body with %s:\n%s",
+		    details, body->data);
+		free(details);
+	}
 	return true;
 }
 

Index: src/usr.bin/make/unit-tests/directive-for-empty.exp
diff -u src/usr.bin/make/unit-tests/directive-for-empty.exp:1.1 src/usr.bin/make/unit-tests/directive-for-empty.exp:1.2
--- src/usr.bin/make/unit-tests/directive-for-empty.exp:1.1	Mon May 23 22:33:56 2022
+++ src/usr.bin/make/unit-tests/directive-for-empty.exp	Thu Jun  1 09:02:14 2023
@@ -3,7 +3,7 @@ make: "directive-for-empty.mk" line 34: 
 make: "directive-for-empty.mk" line 34: Missing argument for ".error"
 make: "directive-for-empty.mk" line 34: Missing argument for ".error"
 For: end for 1
-For: loop body:
+For: loop body with i = value:
 # The identifier 'empty' can only be used in conditions such as .if, .ifdef or
 # .elif.  In other lines the string 'empty(' must be preserved.
 CPPFLAGS+=	-Dmessage="empty(i)"

Index: src/usr.bin/make/unit-tests/directive-for-escape.exp
diff -u src/usr.bin/make/unit-tests/directive-for-escape.exp:1.19 src/usr.bin/make/unit-tests/directive-for-escape.exp:1.20
--- src/usr.bin/make/unit-tests/directive-for-escape.exp:1.19	Tue May  9 19:43:12 2023
+++ src/usr.bin/make/unit-tests/directive-for-escape.exp	Thu Jun  1 09:02:14 2023
@@ -1,52 +1,52 @@
 For: end for 1
-For: loop body:
+For: loop body with chars = !"#$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~:
 .  info ${:U!"#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~}
 make: Unclosed variable expression, expecting '}' for modifier "U!"" of variable "" with value "!""
 make: "directive-for-escape.mk" line 21: !"
 For: end for 1
-For: loop body:
+For: loop body with chars = !"\\#$%&'()*+,-./0-9:;<=>?@A-Z[\]_^a-z{|}~:
 .  info ${:U!"\\\\#$%&'()*+,-./0-9\:;<=>?@A-Z[\\]_^a-z{|\}~}
 make: Unclosed variable expression, expecting '}' for modifier "U!"\\\\" of variable "" with value "!"\\"
 make: "directive-for-escape.mk" line 32: !"\\
 For: end for 1
-For: loop body:
+For: loop body with i = $:
 .  info ${:U\$}
 make: "directive-for-escape.mk" line 47: $
-For: loop body:
+For: loop body with i = ${V}:
 .  info ${:U${V}}
 make: "directive-for-escape.mk" line 47: value
-For: loop body:
+For: loop body with i = ${V:=-with-modifier}:
 .  info ${:U${V:=-with-modifier}}
 make: "directive-for-escape.mk" line 47: value-with-modifier
-For: loop body:
+For: loop body with i = $(V):
 .  info ${:U$(V)}
 make: "directive-for-escape.mk" line 47: value
-For: loop body:
+For: loop body with i = $(V:=-with-modifier):
 .  info ${:U$(V:=-with-modifier)}
 make: "directive-for-escape.mk" line 47: value-with-modifier
 For: end for 1
-For: loop body:
+For: loop body with i = ${UNDEF:U\$\$:
 # ${:U\${UNDEF\:U\\$\\$}
-For: loop body:
+For: loop body with i = {{}}:
 # ${:U{{\}\}}
-For: loop body:
+For: loop body with i = end}:
 # ${:Uend\}}
 For: end for 1
-For: loop body:
+For: loop body with i = ${UNDEF:U\$\$:
 .  info ${:U\${UNDEF\:U\\$\\$}
 make: "directive-for-escape.mk" line 101: ${UNDEF:U\backslash$
-For: loop body:
+For: loop body with i = {{}}:
 .  info ${:U{{\}\}}
 make: "directive-for-escape.mk" line 101: {{}}
-For: loop body:
+For: loop body with i = end}:
 .  info ${:Uend\}}
 make: "directive-for-escape.mk" line 101: end}
 For: end for 1
-For: loop body:
+For: loop body with i = begin<${UNDEF:Ufallback:N{{{}}}}>end:
 .  info ${:Ubegin<${UNDEF:Ufallback:N{{{}}}}>end}
 make: "directive-for-escape.mk" line 122: begin<fallback>end
 For: end for 1
-For: loop body:
+For: loop body with i = $:
 .  info ${:U\$}
 make: "directive-for-escape.mk" line 131: $
 make: "directive-for-escape.mk" line 140: invalid character ':' in .for loop variable name
@@ -54,7 +54,7 @@ For: end for 1
 make: "directive-for-escape.mk" line 150: invalid character '}' in .for loop variable name
 For: end for 1
 For: end for 1
-For: loop body:
+For: loop body with i = inner:
 .  info .        $$i: ${:Uinner}
 .  info .      $${i}: ${:Uinner}
 .  info .   $${i:M*}: ${:Uinner:M*}
@@ -81,19 +81,22 @@ make: "directive-for-escape.mk" line 199
 For: end for 1
 make: "directive-for-escape.mk" line 212: newline in .for value
 make: "directive-for-escape.mk" line 212: newline in .for value
-For: loop body:
+For: loop body with i = "
+":
 .  info short: ${:U" "}
 .  info long: ${:U" "}
 make: "directive-for-escape.mk" line 213: short: " "
 make: "directive-for-escape.mk" line 214: long: " "
 For: end for 1
-For: loop body:
+For: loop body with i = "
+":
 For: end for 1
 Parse_PushInput: .for loop in directive-for-escape.mk, line 230
 make: "directive-for-escape.mk" line 230: newline in .for value
 	in .for loop from directive-for-escape.mk:230 with i = "
 "
-For: loop body:
+For: loop body with i = "
+":
 : ${:U" "}
 SetFilenameVars: ${.PARSEDIR} = <some-dir> ${.PARSEFILE} = `directive-for-escape.mk'
 Parsing line 231: : ${:U" "}
@@ -103,42 +106,42 @@ SetFilenameVars: ${.PARSEDIR} = <some-di
 Parsing line 233: .MAKEFLAGS: -d0
 ParseDependency(.MAKEFLAGS: -d0)
 For: end for 1
-For: loop body:
+For: loop body with i = #:
 # ${:U#}
-For: loop body:
+For: loop body with i = \\#:
 # ${:U\\\\#}
 For: end for 1
-For: loop body:
+For: loop body with i = $:
 # ${:U\$}
-For: loop body:
+For: loop body with i = $i:
 # ${:U$i}
-For: loop body:
+For: loop body with i = $(i):
 # ${:U$(i)}
-For: loop body:
+For: loop body with i = ${i}:
 # ${:U${i}}
-For: loop body:
+For: loop body with i = $$:
 # ${:U$$}
-For: loop body:
+For: loop body with i = $$$$:
 # ${:U$$$$}
-For: loop body:
+For: loop body with i = ${:U\$\$}:
 # ${:U${:U\$\$}}
 For: end for 1
-For: loop body:
+For: loop body with i = ${.TARGET}:
 # ${:U${.TARGET}}
-For: loop body:
+For: loop body with i = ${.TARGET}:
 # ${:U${.TARGET}}
-For: loop body:
+For: loop body with i = $${.TARGET}:
 # ${:U$${.TARGET\}}
-For: loop body:
+For: loop body with i = $${.TARGET}:
 # ${:U$${.TARGET\}}
 For: end for 1
-For: loop body:
+For: loop body with i = (((:
 # ${:U(((}
-For: loop body:
+For: loop body with i = {{{:
 # ${:U{{{}
-For: loop body:
+For: loop body with i = ))):
 # ${:U)))}
-For: loop body:
+For: loop body with i = }}}:
 # ${:U\}\}\}}
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/directive-for-escape.mk
diff -u src/usr.bin/make/unit-tests/directive-for-escape.mk:1.18 src/usr.bin/make/unit-tests/directive-for-escape.mk:1.19
--- src/usr.bin/make/unit-tests/directive-for-escape.mk:1.18	Tue May  9 19:43:12 2023
+++ src/usr.bin/make/unit-tests/directive-for-escape.mk	Thu Jun  1 09:02:14 2023
@@ -1,4 +1,4 @@
-# $NetBSD: directive-for-escape.mk,v 1.18 2023/05/09 19:43:12 rillig Exp $
+# $NetBSD: directive-for-escape.mk,v 1.19 2023/06/01 09:02:14 rillig Exp $
 #
 # Test escaping of special characters in the iteration values of a .for loop.
 # These values get expanded later using the :U variable modifier, and this
@@ -74,11 +74,11 @@ VALUES=		$${UNDEF:U\$$\$$ {{}} end}
 # When these words are injected into the body of the .for loop, each inside a
 # '${:U...}' expression, the result is:
 #
-# expect: For: loop body:
+# expect: For: loop body with i = ${UNDEF:U\$\$:
 # expect: # ${:U\${UNDEF\:U\\$\\$}
-# expect: For: loop body:
+# expect: For: loop body with i = {{}}:
 # expect: # ${:U{{\}\}}
-# expect: For: loop body:
+# expect: For: loop body with i = end}:
 # expect: # ${:Uend\}}
 # expect: For: end for 1
 #

Index: src/usr.bin/make/unit-tests/directive-for.exp
diff -u src/usr.bin/make/unit-tests/directive-for.exp:1.17 src/usr.bin/make/unit-tests/directive-for.exp:1.18
--- src/usr.bin/make/unit-tests/directive-for.exp:1.17	Wed May 10 13:03:06 2023
+++ src/usr.bin/make/unit-tests/directive-for.exp	Thu Jun  1 09:02:14 2023
@@ -28,13 +28,13 @@ make: "directive-for.mk" line 257: if-le
 For: new loop 2
 For: end for 2
 For: end for 1
-For: loop body:
+For: loop body with outer = o:
 .\
    for inner in i
 .\
    endfor
 For: end for 1
-For: loop body:
+For: loop body with inner = i:
 make: "directive-for.mk" line 305: newline-item=(a)
 make: Fatal errors encountered -- cannot continue
 make: stopped in unit-tests

Index: src/usr.bin/make/unit-tests/opt-debug-for.exp
diff -u src/usr.bin/make/unit-tests/opt-debug-for.exp:1.4 src/usr.bin/make/unit-tests/opt-debug-for.exp:1.5
--- src/usr.bin/make/unit-tests/opt-debug-for.exp:1.4	Mon Oct  5 19:27:48 2020
+++ src/usr.bin/make/unit-tests/opt-debug-for.exp	Thu Jun  1 09:02:14 2023
@@ -1,22 +1,22 @@
 For: new loop 2
 For: end for 2
 For: end for 1
-For: loop body:
+For: loop body with outer = a:
 .  for inner in 1 2
 VAR.${:Ua}${inner}=	value
 .  endfor
 For: end for 1
-For: loop body:
+For: loop body with inner = 1:
 VAR.${:Ua}${:U1}=	value
-For: loop body:
+For: loop body with inner = 2:
 VAR.${:Ua}${:U2}=	value
-For: loop body:
+For: loop body with outer = b:
 .  for inner in 1 2
 VAR.${:Ub}${inner}=	value
 .  endfor
 For: end for 1
-For: loop body:
+For: loop body with inner = 1:
 VAR.${:Ub}${:U1}=	value
-For: loop body:
+For: loop body with inner = 2:
 VAR.${:Ub}${:U2}=	value
 exit status 0

Reply via email to