[SV 59230] Preserve export settings for target-specific vars

* src/read.c (record_target_var): Don't overwrite pre-existing export
flag unless we're changing it.
* tests/scripts/features/targetvars: Add a test.
This commit is contained in:
Dmitry Goncharov 2020-11-27 17:18:05 -05:00 committed by Paul Smith
parent 19ae6fe72a
commit 90959b8b70
2 changed files with 13 additions and 2 deletions

View File

@ -1832,7 +1832,8 @@ record_target_var (struct nameseq *filenames, char *defn,
/* Set up the variable to be *-specific. */
v->per_target = 1;
v->private_var = vmod->private_v;
v->export = vmod->export_v ? v_export : v_default;
if (vmod->export_v)
v->export = v_export;
/* If it's not an override, check to see if there was a command-line
setting. If so, reset the value. */

View File

@ -86,7 +86,6 @@ run_make_test(undef, "foo.q bar.q", "qvar = rvar\nqvar =\n");
run_make_test(undef, "foo.t bar.s", "qvar = qvar\nqvar =\n");
# TEST #8
# For PR/1378: Target-specific vars don't inherit correctly
@ -291,6 +290,17 @@ dummy: hello?=world
!,
'', 'hello=moon');
# SV 59230: Assignment of a global variable should not affect export of a
# target specific variable.
$ENV{hello} = "moon";
run_make_test(q!
all:; @echo hello=$$hello
hello=sun
dummy: hello?=world
!,
'', 'hello=sun');
# TEST #19: Test define/endef variables as target-specific vars
# run_make_test('