freebsd-src/unit-tests/counter-append.mk
Simon J. Gerraty ee914ef902 Import bmake-20210621
Lots more unit tests and code cleanup

Relevant changes from ChangeLog

	o job.c: Print -de error information when running multiple jobs
	o var.c: only report error for unmatched regex subexpression
	when linting (-dL) since we cannot tell when an unmatched
	subexpression is an expected result.
	reduce memory allocations in the modifiers ':D' and ':U'
	reduce memory allocation and strlen calls in modifier ':from=to'
	in the ':Q' modifier, only allocate memory if necessary
	improve performance for LazyBuf
	reduce debug logging and memory allocation for ${:U...}
	reduce verbosity of the -dv debug logging for standard cases
	fix double varname expansion in the variable modifier '::='
	o var.c: avoid evaluating many modifiers in parse only mode
	in strict mode (-dL) many variable references are parsed twice,
	the first time just to report parse errors early, so we want to
	avoid side effects and wasted effort to the extent possible.
2021-06-25 11:16:24 -07:00

29 lines
888 B
Makefile
Executable file

# $NetBSD: counter-append.mk,v 1.5 2021/04/04 10:13:09 rillig Exp $
#
# Demonstrates how to let make count the number of times a variable
# is actually accessed, using the ::+= variable modifier.
#
# This works since 2020-09-23. Before that, the counter ended up at having
# 6 words, even though the NEXT variable was only accessed 3 times.
# The cause for this surprising behavior was that the ::= variable modifiers
# returned an error marker instead of a simple empty string.
RELEVANT= yes (load-time part) # just to filter the output
COUNTER= # zero
NEXT= ${COUNTER::+=a}${COUNTER:[#]}
# This variable is first set to empty and then expanded.
# See parse.c, function Parse_Var, keyword "!Var_Exists".
A:= ${NEXT}
B:= ${NEXT}
C:= ${NEXT}
RELEVANT= no
all:
@: ${RELEVANT::=yes (run-time part)}
@echo A=${A:Q} B=${B:Q} C=${C:Q} COUNTER=${COUNTER:[#]:Q}
@: ${RELEVANT::=no}