diff options
author | Paul Smith <psmith@gnu.org> | 2023-01-02 11:23:09 -0500 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2023-01-02 23:02:33 -0500 |
commit | 8791d2b38ec916ea4206d5cae3b0036bb440c918 (patch) | |
tree | 31cfa2e686c1924b26b32636fca03b4b32c9be86 /tests | |
parent | f91b8bbb34ff210ad72bc529c9bd5c6102e27adc (diff) | |
download | make-git-8791d2b38ec916ea4206d5cae3b0036bb440c918.tar.gz |
[SV 61463] Don't export inherited private variables
If a parent target has an exported variable that is private, don't
export it in child targets.
* NEWS: Mention this change.
* src/variable.c (target_environment): Ignore private inherited
variables.
* tests/thelp.pl: Add a new "env" operation to show env.var. values.
* tests/scripts/variables/private: Verify this new behavior.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/scripts/variables/private | 55 | ||||
-rwxr-xr-x | tests/thelp.pl | 13 |
2 files changed, 67 insertions, 1 deletions
diff --git a/tests/scripts/variables/private b/tests/scripts/variables/private index 8967ffb5..16a34c7d 100644 --- a/tests/scripts/variables/private +++ b/tests/scripts/variables/private @@ -47,6 +47,17 @@ a: b ', '', "b: F=b / G=g\na: F= / G=g\n"); +# Exported private global variables +run_make_test(' +private export F = global +$(info $(shell #HELPER# env F)) +a: b +b: export F=b +a b: ; @#HELPER# raw $@ env F +', + '', "F=global\nbF=b\naF=<unset>"); + + # 5: Multiple conditions on the same variable. Test export. delete $ENV{'_X'}; &run_make_test(' @@ -119,4 +130,48 @@ bar: IA=global b% bar bar: PA=global b% bar bar: PS=bar\n"); +# SV 61463: Private parent variables should not be exported + +run_make_test(q! +a: private export FOO := a +a: b +b: ; @#HELPER# env FOO +!, + '', 'FOO=<unset>'); + +run_make_test(q! +a: private export FOO := a +a: b +b: FOO := b +b: ; @#HELPER# env FOO +!, + '', 'FOO=<unset>'); + +run_make_test(q! +export FOO := g +a: private export FOO := a +a: b +b: +b: ; @#HELPER# env FOO +!, + '', 'FOO=g'); + +run_make_test(q! +export FOO := g +a: private export FOO := a +a: b +b: FOO := b +b: ; @#HELPER# env FOO +!, + '', 'FOO=b'); + +run_make_test(q! +private export FOO := g +a: private export FOO := a +a: b +b: FOO := b +b: ; @#HELPER# env FOO +!, + '', 'FOO=<unset>'); + 1; diff --git a/tests/thelp.pl b/tests/thelp.pl index 8d29e5c3..c95b54ae 100755 --- a/tests/thelp.pl +++ b/tests/thelp.pl @@ -10,6 +10,7 @@ # It supports the following operators: # out <word> : echo <word> to stdout with a newline # raw <word> : echo <word> to stdout without adding anything +# env <word> : echo the value of the env.var. <word>, or "<unset>" # file <word> : echo <word> to stdout AND create the file <word> # dir <word> : echo <word> to stdout AND create the directory <word> # rm <word> : echo <word> to stdout AND delete the file/directory <word> @@ -19,7 +20,7 @@ # term <pid> : send SIGTERM to PID <pid> # fail <err> : echo <err> to stdout then exit with error code err # -# If given -q only the "out" command generates output. +# If given -q only the "out", "raw", and "env" commands generate output. # Force flush $| = 1; @@ -41,6 +42,16 @@ sub op { return 1; } + if ($op eq 'env') { + print "$nm=" unless $quiet; + if (exists $ENV{$nm}) { + print "$ENV{$nm}\n"; + } else { + print "<unset>\n"; + } + return 1; + } + # Show the output before creating the file if ($op eq 'file') { print "file $nm\n" unless $quiet; |