mirror of
https://git.savannah.gnu.org/git/make.git
synced 2024-12-27 06:27:51 +00:00
2dc0280d82
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.
110 lines
2.7 KiB
Perl
110 lines
2.7 KiB
Perl
# -*-perl-*-
|
|
|
|
$description = "Test proper handling of SHELL.";
|
|
|
|
# If we don't have a POSIX shell available, never mind
|
|
$is_posix_sh or return -1;
|
|
|
|
# On Windows, shell names might not match
|
|
if ($port_type eq 'W32') {
|
|
return -1;
|
|
}
|
|
|
|
$mshell = $sh_name;
|
|
|
|
# According to POSIX, the value of SHELL in the environment has no impact on
|
|
# the value in the makefile.
|
|
|
|
$ENV{SHELL} = '/dev/null';
|
|
run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
|
|
|
|
# According to POSIX, any value of SHELL set in the makefile should not be
|
|
# exported to the subshell. A more portable option might be to set SHELL to
|
|
# be $^X (perl) in the makefile, and set .SHELLFLAGS to -e.
|
|
|
|
$ENV{SHELL} = $mshell;
|
|
|
|
my $altshell = "/./$mshell";
|
|
my $altshell2 = "/././$mshell";
|
|
|
|
if ($mshell =~ m,^([a-zA-Z]:)([\\/])(.*),) {
|
|
$altshell = "$1$2.$2$3";
|
|
$altshell2 = "$1$2.$2.$2$3";
|
|
}
|
|
|
|
run_make_test("SHELL := $altshell\n".'
|
|
all:;@echo "$(SHELL) $$SHELL"
|
|
', '', "$altshell $mshell");
|
|
|
|
# As a GNU make extension, if make's SHELL variable is explicitly exported,
|
|
# then we really _DO_ export it.
|
|
|
|
$ENV{SHELL} = $mshell;
|
|
|
|
run_make_test("export SHELL := $altshell\n".'
|
|
all:;@echo "$(SHELL) $$SHELL"
|
|
', '', "$altshell $altshell");
|
|
|
|
|
|
# Test out setting of SHELL, both exported and not, as a target-specific
|
|
# variable.
|
|
|
|
$ENV{SHELL} = $mshell;
|
|
|
|
run_make_test("all: SHELL := $altshell\n".'
|
|
all:;@echo "$(SHELL) $$SHELL"
|
|
', '', "$altshell $mshell");
|
|
|
|
$ENV{SHELL} = $mshell;
|
|
|
|
run_make_test("
|
|
SHELL := $altshell2
|
|
one: two
|
|
two: export SHELL := $altshell\n".'
|
|
one two:;@echo "$@: $(SHELL) $$SHELL"
|
|
', '', "two: $altshell $altshell\none: $altshell2 $mshell\n");
|
|
|
|
# Test .SHELLFLAGS
|
|
|
|
# We don't know the output here: on Solaris for example, every line printed
|
|
# by the shell in -x mode has a trailing space (!!)
|
|
my $script = 'true; true';
|
|
my $flags = '-xc';
|
|
my $out = `$sh_name $flags '$script' 2>&1`;
|
|
|
|
run_make_test(qq!
|
|
.SHELLFLAGS = $flags
|
|
all: ; \@$script
|
|
!,
|
|
'', $out);
|
|
|
|
# Do it again but add spaces to SHELLFLAGS
|
|
|
|
# Some shells (*shakes fist at Solaris*) cannot handle multiple flags in
|
|
# separate arguments.
|
|
my $t = `$sh_name -e -c true 2>/dev/null`;
|
|
my $multi_ok = $? == 0;
|
|
|
|
if ($multi_ok) {
|
|
$flags = '-x -c';
|
|
run_make_test(qq!
|
|
.SHELLFLAGS = $flags
|
|
all: ; \@$script
|
|
!,
|
|
'', $out);
|
|
}
|
|
|
|
# We can't just use "false" because on different systems it provides a
|
|
# different exit code--once again Solaris: false exits with 255 not 1
|
|
$script = 'true; false; true';
|
|
$flags = '-xec';
|
|
$out = `$sh_name $flags '$script' 2>&1`;
|
|
my $err = $? >> 8;
|
|
|
|
run_make_test(qq!
|
|
.SHELLFLAGS = $flags
|
|
all: ; \@$script
|
|
!,
|
|
'', "$out#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512);
|
|
|
|
1;
|