mirror of
https://git.savannah.gnu.org/git/make.git
synced 2025-01-13 01:07:36 +00:00
a382ac6cd1
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.
145 lines
4.6 KiB
Perl
145 lines
4.6 KiB
Perl
# -*-perl-*-
|
|
|
|
$description = "Test the -e (environment overrides) option";
|
|
|
|
$ENV{GOOGLE} = 'boggle';
|
|
|
|
run_make_test(q!
|
|
GOOGLE = bazzle
|
|
all:; @echo "$(GOOGLE)"
|
|
!,
|
|
'-e', "boggle\n");
|
|
|
|
# Ensure variables set on the command line have the origin correct
|
|
# See SV 61218
|
|
|
|
run_make_test(q!
|
|
$(info FOO [$(origin FOO)]: $(value FOO))
|
|
all: ;
|
|
recurse: ; @$(MAKE) -f #MAKEFILE#
|
|
!,
|
|
'-e --no-print-directory FOO=1 recurse',
|
|
"FOO [command line]: 1\nFOO [command line]: 1\n#MAKE#[1]: 'all' is up to date.");
|
|
|
|
# SV 64803.
|
|
# Test that the origin of an env variable is 'enviroment override' when -e
|
|
# is set and the makefile does not modify the variable.
|
|
# First run the test without -e and then with -e.
|
|
|
|
mkdir('lib', 0777);
|
|
|
|
create_file('lib/makefile',
|
|
'$(info in submake value=$(hello), origin=$(origin hello))
|
|
all:; @echo "value=$(hello), origin=$(origin hello)"'."\n");
|
|
|
|
# No -e.
|
|
$ENV{hello} = 'world';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -C lib
|
|
.PHONY: lib all
|
|
!,
|
|
'-s',
|
|
"value=world, origin=environment\nvalue=world, origin=environment\n".
|
|
"in submake value=world, origin=environment\nvalue=world, origin=environment");
|
|
|
|
# -e is specified on the command line.
|
|
my @opts = ('-e', '--environment-overrides');
|
|
for my $opt (@opts) {
|
|
$ENV{hello} = 'world';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -C lib
|
|
.PHONY: lib all
|
|
!,
|
|
"-s $opt",
|
|
"value=world, origin=environment override\nvalue=world, origin=environment override\n".
|
|
"in submake value=world, origin=environment override\nvalue=world, origin=environment override");
|
|
}
|
|
|
|
# MAKEFLAGS from env affects top level make.
|
|
$ENV{hello} = 'world';
|
|
$ENV{MAKEFLAGS} = 'e';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -C lib
|
|
.PHONY: lib all
|
|
!,
|
|
"-s",
|
|
"value=world, origin=environment override\nvalue=world, origin=environment override\n".
|
|
"in submake value=world, origin=environment override\nvalue=world, origin=environment override");
|
|
|
|
# -e is passed to submake on the command line.
|
|
$ENV{hello} = 'world';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -e -C lib
|
|
.PHONY: lib all
|
|
!,
|
|
"-s",
|
|
"value=world, origin=environment\nvalue=world, origin=environment\n".
|
|
"in submake value=world, origin=environment override\nvalue=world, origin=environment override");
|
|
|
|
# MAKEFLAGS is reset for submake.
|
|
$ENV{hello} = 'world';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -C lib MAKEFLAGS=
|
|
.PHONY: lib all
|
|
!,
|
|
"-se",
|
|
"value=world, origin=environment override\nvalue=world, origin=environment override\n".
|
|
"in submake value=world, origin=environment\nvalue=world, origin=environment");
|
|
|
|
# Some MAKEFLAGS in top make env.
|
|
# This MAKEFLAGS does not conform to the format that make itself produces for
|
|
# submake. However, make still parses and honors this MAKEFLAGS.
|
|
# This test checks that make does not confuse 'e' in 'extramk' with '-e'.
|
|
$ENV{MAKEFLAGS} = 'r -Iextramk -k bye=moon';
|
|
$ENV{hello} = 'world';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -C lib
|
|
.PHONY: lib all
|
|
!,
|
|
"-s",
|
|
"value=world, origin=environment\nvalue=world, origin=environment\n".
|
|
"in submake value=world, origin=environment\nvalue=world, origin=environment");
|
|
|
|
# Some MAKEFLAGS in top make env.
|
|
# This MAKEFLAGS does not conform to the format that make itself produces for
|
|
# submake. However, make still parses and honors this MAKEFLAGS.
|
|
# This test checks that make detects '-e' in this MAKEFLAGS.
|
|
$ENV{MAKEFLAGS} = 'r -Iextramk -ke bye=moon';
|
|
$ENV{hello} = 'world';
|
|
run_make_test(q!
|
|
.RECIPEPREFIX = >
|
|
$(info value=$(hello), origin=$(origin hello))
|
|
all:
|
|
> @echo "value=$(hello), origin=$(origin hello)"
|
|
> @$(MAKE) -C lib
|
|
.PHONY: lib all
|
|
!,
|
|
"-s",
|
|
"value=world, origin=environment override\nvalue=world, origin=environment override\n".
|
|
"in submake value=world, origin=environment override\nvalue=world, origin=environment override");
|
|
|
|
1;
|