mirror of
https://github.com/mirror/make.git
synced 2026-08-23 18:33:28 +08:00
Support "unexport" in target-specific variables.
Rewrite the environment variable algorithm to correctly inherit export settings from parent variable sets. The new algorithm for computing the table of environment variables is: - Start with the most local variable set and proceed to global. - If the variable already exists in the table and we don't know its export status, update it with the current variable's status. - If the variable is not in the table and it's not global, add it regardless of its status so if it's unexported we remember that. - If the variable is not in the table and is global, check its export status and don't add it if we won't export it. Then when generating the environment variables, check the export status of each variable in case it was a target-specific variable and we have determined it should not be exported. Rework SHELL handling to check at the end whether we added it or not and if we didn't, add the value from the environment. * NEWS: Announce support for target-specific "unexport"." * doc/make.texi (Target-specific): Document the support. * src/variable.h (enum variable_export): Make into a global type. * src/read.c (struct vmodifiers): Use enum variable_export rather than individual booleans. (parse_var_assignment): Parse the "unexport" keyword. (eval): Remember the vmodifier value in the variable. (record_target_var): Ditto. * src/variable.c (should_export): Check if the variable should be exported. (target_environment): Implement the above algorithm. * tests/scripts/features/export: Test export/unexport with variable assignments on the same line. * tests/scripts/features/targetvars: Add a comprehensive suite of tests for different types of target-specific export / unexport. * tests/scripts/variables/SHELL: Update the comment.
This commit is contained in:
@@ -178,7 +178,7 @@ a: ; @echo "\$$(export)=$(export) / \$$export=$$export"
|
||||
',
|
||||
'', "\$(export)=456 / \$export=456\n");
|
||||
|
||||
# TEST 9: Check "export" as a target
|
||||
# TEST 10: Check "export" as a target
|
||||
|
||||
&run_make_test('
|
||||
a: export
|
||||
@@ -186,5 +186,25 @@ export: ; @echo "$@"
|
||||
',
|
||||
'', "export\n");
|
||||
|
||||
# Check export and assignment of a variable on the same line
|
||||
|
||||
$ENV{hello} = 'moon';
|
||||
|
||||
run_make_test(q!
|
||||
all: ; @echo hello=$(hello) hello=$$hello
|
||||
export hello=sun
|
||||
!,
|
||||
'', "hello=sun hello=sun\n");
|
||||
|
||||
# Check unexport and assignment of a variable on the same line
|
||||
|
||||
$ENV{hello} = 'moon';
|
||||
|
||||
run_make_test(q!
|
||||
all: ; @echo hello=$(hello) hello=$$hello
|
||||
unexport hello=sun
|
||||
!,
|
||||
'', "hello=sun hello=\n");
|
||||
|
||||
# This tells the test driver that the perl test script executed properly.
|
||||
1;
|
||||
|
||||
@@ -12,8 +12,9 @@ export BAR = bar
|
||||
one: override FOO = one
|
||||
one two: ; @echo $(FOO) $(BAR)
|
||||
two: BAR = two
|
||||
.RECIPEPREFIX = >
|
||||
three: ; BAR=1000
|
||||
@echo $(FOO) $(BAR)
|
||||
> @echo $(FOO) $(BAR)
|
||||
# Some things that shouldn not be target vars
|
||||
funk : override
|
||||
funk : override adelic
|
||||
@@ -301,6 +302,117 @@ dummy: hello?=world
|
||||
!,
|
||||
'', 'hello=sun');
|
||||
|
||||
# Support target-specific unexport
|
||||
|
||||
$ENV{hello} = "moon";
|
||||
run_make_test(q!
|
||||
unexport hello=sun
|
||||
all: base exp
|
||||
base exp: ; @echo hello=$$hello
|
||||
exp: export hello=world
|
||||
!,
|
||||
'', "hello=\nhello=world\n");
|
||||
|
||||
$ENV{hello} = "moon";
|
||||
run_make_test(q!
|
||||
hello=sun
|
||||
all: base exp
|
||||
base exp: ; @echo hello=$$hello
|
||||
exp: unexport hello=world
|
||||
!,
|
||||
'', "hello=sun\nhello=\n");
|
||||
|
||||
run_make_test(q!
|
||||
all:; @echo hello=$$hello
|
||||
unexport hello=sun
|
||||
dummy: hello?=world
|
||||
!,
|
||||
'', 'hello=');
|
||||
|
||||
$ENV{hello} = "moon";
|
||||
run_make_test(q!
|
||||
all:; @echo hello=$$hello
|
||||
hello=sun
|
||||
dummy: unexport hello=world
|
||||
!,
|
||||
'', 'hello=sun');
|
||||
|
||||
run_make_test(q!
|
||||
all: mid
|
||||
mid: base
|
||||
|
||||
ifeq ($(midexport),export)
|
||||
mid: export hello=mid
|
||||
else ifeq ($(midexport),unexport)
|
||||
mid: unexport hello=mid
|
||||
else
|
||||
mid: hello=mid
|
||||
endif
|
||||
|
||||
ifeq ($(baseexport),export)
|
||||
base: export hello=base
|
||||
else ifeq ($(baseexport),unexport)
|
||||
base: unexport hello=base
|
||||
else
|
||||
base: hello=base
|
||||
endif
|
||||
|
||||
all mid base:; @echo $@ make=$(hello) shell=$$hello
|
||||
!,
|
||||
'', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n");
|
||||
|
||||
# Test base settings with env var
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n");
|
||||
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'baseexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n");
|
||||
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make=environ shell=environ\n");
|
||||
|
||||
# Test mid settings with env var
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'midexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make=environ shell=environ\n");
|
||||
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'midexport=export baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make=environ shell=environ\n");
|
||||
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'midexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make=environ shell=environ\n");
|
||||
|
||||
$ENV{hello} = "environ";
|
||||
run_make_test(undef,
|
||||
'midexport=unexport baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make=environ shell=environ\n");
|
||||
|
||||
# Test base settings without env var
|
||||
run_make_test(undef,
|
||||
'baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make= shell=\n");
|
||||
|
||||
run_make_test(undef,
|
||||
'baseexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n");
|
||||
|
||||
# Test mid settings with env var
|
||||
run_make_test(undef,
|
||||
'midexport=export', "base make=base shell=base\nmid make=mid shell=mid\nall make= shell=\n");
|
||||
|
||||
run_make_test(undef,
|
||||
'midexport=export baseexport=unexport', "base make=base shell=\nmid make=mid shell=mid\nall make= shell=\n");
|
||||
|
||||
run_make_test(undef,
|
||||
'midexport=unexport', "base make=base shell=\nmid make=mid shell=\nall make= shell=\n");
|
||||
|
||||
run_make_test(undef,
|
||||
'midexport=unexport baseexport=export', "base make=base shell=base\nmid make=mid shell=\nall make= shell=\n");
|
||||
|
||||
|
||||
|
||||
# TEST #19: Test define/endef variables as target-specific vars
|
||||
|
||||
# run_make_test('
|
||||
@@ -316,7 +428,3 @@ dummy: hello?=world
|
||||
# '', "local\n");
|
||||
|
||||
1;
|
||||
|
||||
### Local Variables:
|
||||
### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
|
||||
### End:
|
||||
|
||||
Reference in New Issue
Block a user