summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2022-06-18 20:25:30 -0400
committerPaul Smith <psmith@gnu.org>2022-07-09 10:44:21 -0400
commit98da874c43035a490cdca81331724f233a3d0c9a (patch)
tree1894a4e883fd03ff762dfcfe4357cf1d68de483f /tests
parent88d6c22a487cc45b6d615d5c055ced5c9d5cb56d (diff)
downloadmake-git-98da874c43035a490cdca81331724f233a3d0c9a.tar.gz
[SV 10593] Export variables to $(shell ...) commands
Export all variables, including exported makefile variables, when invoking a shell for the $(shell ...) function. If we detect a recursive variable expansion, silently ignore that variable and do not export it. We do print a debug message. * NEWS: Announce the potential backward-incompatibility. * doc/make.texi (Shell Function): Document the export behavior. * src/main.c (main): Add "shell-export" to .FEATURES. * src/job.h: New function to free struct childbase. * src/job.c (free_childbase): Implement it; call from free_child. * src/function.c (func_shell_base): Use target_environment() to obtain the proper environment for the shell function. Use free_childbase() to free memory. (windows32_openpipe): Don't reset the environment: the caller already provided a proper PATH variable in envp. * src/variable.c (target_environment): If we detect a recursive expansion and we're called from func_shell, ignore the variable. (sync_Path_environment): Simplify and reduce memory allocation. * tests/scripts/functions/shell: Add tests for this.
Diffstat (limited to 'tests')
-rw-r--r--tests/scripts/functions/shell55
1 files changed, 51 insertions, 4 deletions
diff --git a/tests/scripts/functions/shell b/tests/scripts/functions/shell
index 63320a2b..80425172 100644
--- a/tests/scripts/functions/shell
+++ b/tests/scripts/functions/shell
@@ -32,14 +32,61 @@ foo: ; echo '$(FOO)'
!,
'', "echo '#'\n#\n");
-# Test shells inside exported environment variables.
-# This is the test that fails if we try to put make exported variables into
-# the environment for a $(shell ...) call.
+# Test that exported variables are passed to $(shell ...)
+$ENV{FOO} = 'baz';
+run_make_test(q!
+OUT = $(shell echo $$FOO)
+foo: ; @echo '$(OUT)'
+!,
+ '', 'baz');
+
+$ENV{FOO} = 'baz';
+run_make_test(q!
+FOO = bar
+OUT = $(shell echo $$FOO)
+foo: ; @echo '$(OUT)'
+!,
+ '', 'bar');
+
+run_make_test(q!
+export FOO = bar
+OUT = $(shell echo $$FOO)
+foo: ; @echo '$(OUT)'
+!,
+ '', 'bar');
+
+# Test shells inside exported environment variables, simply expanded.
+run_make_test('
+export HI := $(shell echo hi)
+.PHONY: all
+all: ; @echo $$HI
+',
+ '','hi');
+
+# Test shells inside exported environment variables. See SV 10593
run_make_test('
export HI = $(shell echo hi)
.PHONY: all
all: ; @echo $$HI
- ','','hi');
+',
+ '',"hi");
+
+$ENV{HI} = 'foo';
+run_make_test('
+HI = $(shell echo hi)
+.PHONY: all
+all: ; @echo $$HI
+',
+ '',"hi");
+
+$ENV{HI} = 'foo';
+run_make_test('
+HI = $(shell echo hi)
+bad := $(HI)
+.PHONY: all
+all: ; @echo $$HI $(bad)
+',
+ '',"hi hi");
if ($port_type ne 'W32') {
# Test shell errors in recipes including offset