make(1): add debugging output for :@ modifier

The inner working of the :@ modifier is quite tricky.  To understand what
really happens, it helps to look at each word as it is being modified.
This commit is contained in:
rillig 2020-07-04 17:10:33 +00:00
parent a08fee7be0
commit 41de654ca4
3 changed files with 22 additions and 5 deletions

View File

@ -31,4 +31,5 @@ make: Unclosed substitution for (, missing)
:a c:
:x__ 3 x__ 3:
:+one+ +two+ +three+:
mod-at-resolve:w1a2w w1b2w w1a2 1b${RES2}w:
exit status 0

View File

@ -1,4 +1,4 @@
# $Id: modmisc.mk,v 1.9 2020/07/04 16:15:21 rillig Exp $
# $Id: modmisc.mk,v 1.10 2020/07/04 17:10:33 rillig Exp $
#
# miscellaneous modifier tests
@ -16,7 +16,7 @@ MOD_OPT=@d@$${exists($$d):?$$d:$${d:S,/usr,/opt,}}@
MOD_SEP=S,:, ,g
all: modvar modvarloop modsysv mod-HTE emptyvar undefvar
all: mod-S mod-C mod-at-varname
all: mod-S mod-C mod-at-varname mod-at-resolve
modsysv:
@echo "The answer is ${libfoo.a:L:libfoo.a=42}"
@ -80,3 +80,13 @@ mod-C:
# will ever depend on this, but technically it's possible.
mod-at-varname:
@echo :${:Uone two three:@${:Ubar:S,b,v,}@+${var}+@:Q}:
# The :@ modifier resolves the variables a little more often than expected.
# In particular, it resolves _all_ variables from the context, and not only
# the loop variable (in this case v).
RESOLVE= ${RES1} $${RES1}
RES1= 1a${RES2} 1b$${RES2}
RES2= 2
mod-at-resolve:
@echo $@:${RESOLVE:@v@w${v}w@:Q}:

View File

@ -1,4 +1,4 @@
/* $NetBSD: var.c,v 1.253 2020/07/04 16:30:47 rillig Exp $ */
/* $NetBSD: var.c,v 1.254 2020/07/04 17:10:33 rillig Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1993
@ -69,14 +69,14 @@
*/
#ifndef MAKE_NATIVE
static char rcsid[] = "$NetBSD: var.c,v 1.253 2020/07/04 16:30:47 rillig Exp $";
static char rcsid[] = "$NetBSD: var.c,v 1.254 2020/07/04 17:10:33 rillig Exp $";
#else
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)var.c 8.3 (Berkeley) 3/19/94";
#else
__RCSID("$NetBSD: var.c,v 1.253 2020/07/04 16:30:47 rillig Exp $");
__RCSID("$NetBSD: var.c,v 1.254 2020/07/04 17:10:33 rillig Exp $");
#endif
#endif /* not lint */
#endif
@ -1567,6 +1567,12 @@ VarLoopExpand(GNode *ctx MAKE_ATTR_UNUSED,
if (*word) {
Var_Set_with_flags(loop->tvar, word, loop->ctxt, VAR_NO_EXPORT);
s = Var_Subst(NULL, loop->str, loop->ctxt, loop->flags);
if (DEBUG(VAR)) {
fprintf(debug_file,
"VarLoopExpand: in \"%s\", replace \"%s\" with \"%s\" "
"to \"%s\"\n",
word, loop->tvar, loop->str, s ? s : "(null)");
}
if (s != NULL && *s != '\0') {
if (addSpace && *s != '\n')
Buf_AddByte(buf, ' ');