Home | History | Annotate | Download | only in unit-tests
History log of /src/usr.bin/make/unit-tests/varmod-loop.exp
RevisionDateAuthorComments
 1.22  31-Oct-2024  rillig make: in the debug log, always qualify line number with filename

Previously, to find out the filename corresponding to a line number from
a 'Parsing' line, it was necessary to find the preceding
'SetFilenameVars' line, which was unnecessarily time-consuming and
distracting.

The 'filename:line' format matches the one used in PrintStackTrace, and
it differs from the one used in PrintLocation, as the former format is
more common in other tools.

Most of the affected unit tests only use the 'Parsing' lines to give
additional context to their debug log, so no structural changes there.
 1.21  01-Jun-2024  rillig branches: 1.21.2;
make: remove unused VARE_EVAL_KEEP_DOLLAR
 1.20  14-Apr-2024  rillig make: add debug logging for .if and .for lines in -dp mode

This helps track down in which line a condition is evaluated.
 1.19  18-Feb-2023  rillig tests/make: document the modifier ':@var@body@'
 1.18  23-Aug-2022  rillig tests/make: document how the modifier ':@' works
 1.17  23-Aug-2022  rillig make: revert parsing of modifier parts (since 2022-08-08)

The modifier ':@var@body@' parses the body in parse-only mode and later
uses Var_Subst on it, in which each literal '$' must be written as '$$'.

Trying to parse the loop body using Var_Parse treated the text
'$${var:-0}' as a single '$' followed by the expression '${var:-0}',
wrongly complaining about the 'Unknown modifier "-0"'.

Found by sjg.
 1.16  23-Aug-2022  rillig tests/make: demonstrate parse error in ':@' modifier (since 2022-08-08)

Reported by sjg via private mail.
 1.15  03-Mar-2022  rillig make: make debug logging for comparisons less technical
 1.14  28-Dec-2021  rillig make: make debug logging a bit more human-friendly

The previous log format "ParseReadLine (%d): '%s'" focused on the
implementation, it was not immediately obvious to a casual reader that
the number in parentheses was the line number. Additionally, having
both a colon and quotes in a log message is uncommon. The quotes have
been added in parse.c 1.127 from 2007-01-01.

The new log format "Parsing line %d: %s" is meant to be easier readable
by humans. The quotes are not needed since ParseReadLine always strips
trailing whitespace, leaving no room for ambiguities. The other log
messages follow common punctuation rules, which makes the beginning of
the line equally unambiguous. Before var.c 1.911 from 2021-04-05,
variable assignments were logged with the format "%s:%s = %s", without a
space after the colon.
 1.13  05-Dec-2021  rillig make: fix use-after-free in modifier ':@'

Without memory allocator debugging, the newly added test doesn't show
any obvious failure.

With memory allocator debugging enabled, all make versions since
2016.02.27.16.20.06 crash with a segmentation fault.
 1.12  05-Dec-2021  rillig tests/make: demonstrate use-after-free in modifier ':@'
 1.11  30-Nov-2021  rillig tests/make: test and document .MAKE.SAVE_DOLLARS and ':='
 1.10  04-Apr-2021  rillig tests/make: split test for modifier ':@' into separate files

The file varmod-loop.mk has grown too large to be single-purpose, plus
it combined parse-time and run-time tests. This has the downside that
as soon as a parse-time test results in an error, the run-time tests are
not run anymore.
 1.9  04-Apr-2021  rillig make: remove filler word 'Do' from function names for parsing

No functional change, except for debug logging.
 1.8  15-Mar-2021  rillig tests/make: convert varmod-loop to parse-time

In case of unexpected failures, this provides the line number of the
'.error' directive.
 1.7  15-Mar-2021  rillig tests/make: add position marker in test 'varmod-loop'
 1.6  23-Feb-2021  rillig make: demonstrate how to undefine variables during evaluation

For a very long time now, I had thought that it would be impossible to
undefine global variables during the evaluation of variable expressions.
This is something that the memory management in Var_Parse relies upon,
see the comment 'the value of the variable must not change'.

After several unsuccessful attempts at referring to an already freed
previous value of a variable, today I discovered how to unset a global
variable while evaluating an expression, which has the same effect. To
demonstrate that this use-after-free can reliably crash make, it would
need a memory allocator with a debug mode that never re-allocates the
same memory block after it has been used once. This is something that
jemalloc cannot do at the moment. Valgrind would be another idea, but
that has not been ported to NetBSD.

Undefining a global variable while evaluating an expression is made
possible by an implementation detail of the modifier ':@'. That
modifier undefines the loop variable, without restoring its previous
value, see ApplyModifier_Loop.

By the very old conventions of ODE Make, these loop variables are named
'.V.' and thus do not conflict with variables from other naming
conventions. In NetBSD and pkgsrc, these loop variables are typically
called 'var', sometimes '_var' with a leading underscore, which also
doesn't conflict with the typical form 'VAR' of variables in the global
namespace. Therefore, in practice these loop variables don't interfere
with other variables.

One case that can practically arise is when an outer variable has a
modifier ':@word@${VAR.${word}}@' and one of the referenced variables
uses the same variable name in the modifier, see varmod-loop.mk 1.10
line 91 for a detailed explanation.

By using the ${:@VAR@@} modifier in a place that is evaluated with
cmdline scope, it is not only possible to undefine global variables, it
is possible to undefine cmdline variables as well. When evaluated in a
specific make target, the expression ${:@\@@@} can even be used to
undefine the variable '.TARGET', which will probably crash make with an
assertion failure.
 1.5  12-Nov-2020  rillig make(1): fix tests varmod-defined and varmod-loop regarding dollars

Some derived versions of NetBSD's make set .MAKE.SAVE_DOLLARS to no. In
these versions, running the tests would fail. Therefore better set
.MAKE.SAVE_DOLLARS to yes explicitly as far as necessary.

Suggested by sjg.
 1.4  08-Nov-2020  rillig make(1): add test demonstrating how ':=' and ':@var@' interact
 1.3  13-Sep-2020  rillig make(1): add test for empty variable name in :@var@...@ modifier
 1.2  16-Aug-2020  rillig make(1): move tests for :S, :C, :@ from modmisc to their separate tests
 1.1  16-Aug-2020  rillig make(1): add dummies for fine-grained tests, one per single feature

The test names have been derived from the current manual page.

All these tests are dummies right now, and the code from the existing
tests will be moved into the new tests step by step.

This is done to prevent modmisc, escape, varmod-edge and varmisc from
growing without any bounds, and to reduce the side-effects of one test
to the others.
 1.21.2.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed