make/tests/scripts/functions/origin
Dmitry Goncharov a382ac6cd1 [SV 64803] Set origin for unmodified variables after -e
Ensure the origin of all variables inherited from the environment is
"environment override" if -e is given.  Previously only variables
that were set in the makefile had this origin.

PDS: Most of these changes are from Dmitry but I slightly modified
the algorithm: instead of rearranging the way in which MAKEFLAGS is
parsed we reset the env_override value to the default before we
re-parse MAKEFLAGS, then we set the origin of all env vars to the
correct value based on the new setting.

* NEWS: Mention the change for backward-compatibility.
* src/main.c (main): Ensure MAKEFLAGS is always marked special.
(reset_makeflags): Set env_overrides back to default before parsing
MAKEFLAGS.
(decode_switches): Call reset_env_override() to check for changes.
* src/variable.h (reset_env_override): Declare a new function.
* src/variable.c (reset_env_override): Go through all env variables
and ensure the origin is correct based on env_overrides.
(set_env_override): Helper function for the hash.
* tests/scripts/functions/foreach: Fix tests.
* tests/scripts/functions/let: Ditto.
* tests/scripts/functions/origin: Ditto.
* tests/scripts/options/dash-e: Add tests.
2024-02-04 11:34:49 -05:00

49 lines
1.3 KiB
Perl

# -*-perl-*-
$description = "Test the origin function.";
$details = "This is a test of the origin function in gnu make.
This function will report on where a variable was
defined per the following list:
'undefined' never defined
'default' default definition
'environment' environment var without -e
'environment override' environment var with -e
'file' defined in makefile
'command line' defined on the command line
'override' defined by override in makefile
'automatic' Automatic variable\n";
# Set an environment variable
$ENV{MAKETEST} = 1;
run_make_test('
foo := bletch garf
auto_var = undefined CC MAKETEST MAKE foo CFLAGS WHITE @
av = $(foreach var, $(auto_var), $(origin $(var)) )
override WHITE := BLACK
.RECIPEPREFIX = >
all: auto
> @echo $(origin undefined)
> @echo $(origin CC)
> @echo $(origin MAKETEST)
> @echo $(origin MAKE)
> @echo $(origin foo)
> @echo $(origin CFLAGS)
> @echo $(origin WHITE)
> @echo $(origin @)
auto :
> @echo $(av)',
'-e WHITE=WHITE CFLAGS=',
'undefined default environment override default file command line override automatic
undefined
default
environment override
default
file
command line
override
automatic');
1;