| 1 |
# -*-perl-*- |
| 2 |
|
| 3 |
$description = 'Test the $(shell ...) function.'; |
| 4 |
|
| 5 |
$details = ''; |
| 6 |
|
| 7 |
# Test standard shell |
| 8 |
run_make_test('.PHONY: all |
| 9 |
OUT := $(shell echo hi) |
| 10 |
all: ; @echo $(OUT) |
| 11 |
','','hi'); |
| 12 |
|
| 13 |
# Test shells inside rules. |
| 14 |
run_make_test('.PHONY: all |
| 15 |
all: ; @echo $(shell echo hi) |
| 16 |
','','hi'); |
| 17 |
|
| 18 |
# Verify .SHELLSTATUS |
| 19 |
run_make_test('.PHONY: all |
| 20 |
PRE := $(.SHELLSTATUS) |
| 21 |
$(shell exit 0) |
| 22 |
OK := $(.SHELLSTATUS) |
| 23 |
$(shell exit 1) |
| 24 |
BAD := $(.SHELLSTATUS) |
| 25 |
all: ; @echo PRE=$(PRE) OK=$(OK) BAD=$(BAD) |
| 26 |
','','PRE= OK=0 BAD=1'); |
| 27 |
|
| 28 |
# Test unescaped comment characters in shells. Savannah bug #20513 |
| 29 |
run_make_test(q! |
| 30 |
FOO := $(shell echo '#') |
| 31 |
foo: ; echo '$(FOO)' |
| 32 |
!, |
| 33 |
'', "echo '#'\n#\n"); |
| 34 |
|
| 35 |
# Test that exported variables are passed to $(shell ...) |
| 36 |
$ENV{FOO} = 'baz'; |
| 37 |
run_make_test(q! |
| 38 |
OUT = $(shell echo $$FOO) |
| 39 |
foo: ; @echo '$(OUT)' |
| 40 |
!, |
| 41 |
'', 'baz'); |
| 42 |
|
| 43 |
$ENV{FOO} = 'baz'; |
| 44 |
run_make_test(q! |
| 45 |
FOO = bar |
| 46 |
OUT = $(shell echo $$FOO) |
| 47 |
foo: ; @echo '$(OUT)' |
| 48 |
!, |
| 49 |
'', 'bar'); |
| 50 |
|
| 51 |
run_make_test(q! |
| 52 |
export FOO = bar |
| 53 |
OUT = $(shell echo $$FOO) |
| 54 |
foo: ; @echo '$(OUT)' |
| 55 |
!, |
| 56 |
'', 'bar'); |
| 57 |
|
| 58 |
# Test shells inside exported environment variables, simply expanded. |
| 59 |
run_make_test(' |
| 60 |
export HI := $(shell echo hi) |
| 61 |
.PHONY: all |
| 62 |
all: ; @echo $$HI |
| 63 |
', |
| 64 |
'','hi'); |
| 65 |
|
| 66 |
# Test shells inside exported environment variables. See SV 10593 |
| 67 |
run_make_test(' |
| 68 |
export HI = $(shell echo hi) |
| 69 |
.PHONY: all |
| 70 |
all: ; @echo $$HI |
| 71 |
', |
| 72 |
'',"hi"); |
| 73 |
|
| 74 |
$ENV{HI} = 'foo'; |
| 75 |
run_make_test(' |
| 76 |
HI = $(shell echo hi) |
| 77 |
.PHONY: all |
| 78 |
all: ; @echo $$HI |
| 79 |
', |
| 80 |
'',"hi"); |
| 81 |
|
| 82 |
$ENV{HI} = 'foo'; |
| 83 |
run_make_test(' |
| 84 |
HI = $(shell echo hi) |
| 85 |
bad := $(HI) |
| 86 |
.PHONY: all |
| 87 |
all: ; @echo $$HI $(bad) |
| 88 |
', |
| 89 |
'',"hi hi"); |
| 90 |
|
| 91 |
# SV 63016: Exported variable that contains a variable containing $(shell...) |
| 92 |
|
| 93 |
run_make_test(' |
| 94 |
HI = $(shell echo hi) |
| 95 |
export bad = $(HI) |
| 96 |
.PHONY: all |
| 97 |
all:; : $(HI) |
| 98 |
', |
| 99 |
'',": hi"); |
| 100 |
|
| 101 |
$ENV{HI} = 'outer'; |
| 102 |
run_make_test(' |
| 103 |
export HI = $(shell echo $$HI) |
| 104 |
.PHONY: all |
| 105 |
all:; @echo $$HI |
| 106 |
', |
| 107 |
'',"outer"); |
| 108 |
|
| 109 |
$ENV{HI} = 'outer'; |
| 110 |
run_make_test(' |
| 111 |
export HI = $(shell echo $$HI) |
| 112 |
.PHONY: all |
| 113 |
all:; : $(HI) |
| 114 |
', |
| 115 |
'',": outer"); |
| 116 |
|
| 117 |
if ($port_type ne 'W32') { |
| 118 |
# Test shell errors in recipes including offset |
| 119 |
# This needs to be ported to Windows, or else Windows error messages |
| 120 |
# need to converted to look like more normal make errors. |
| 121 |
run_make_test(' |
| 122 |
.RECIPEPREFIX = > |
| 123 |
all: |
| 124 |
>@echo hi |
| 125 |
>$(shell ./basdfdfsed there) |
| 126 |
>@echo $(.SHELLSTATUS) |
| 127 |
', |
| 128 |
'', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\nhi\n127\n"); |
| 129 |
|
| 130 |
run_make_test(' |
| 131 |
$(shell ./basdfdfsed where) |
| 132 |
all: ; @echo $(.SHELLSTATUS) |
| 133 |
', |
| 134 |
'', "#MAKE#: ./basdfdfsed: $ERR_no_such_file\n127\n"); |
| 135 |
|
| 136 |
# Test SHELLSTATUS for kill. |
| 137 |
# This test could be ported to Windows, using taskkill ... ? |
| 138 |
|
| 139 |
# Figure out the exit code for SIGINT |
| 140 |
my $pid = fork(); |
| 141 |
if (! $pid) { |
| 142 |
exec('kill -2 $$') or die "exec: Cannot execute sleep\n"; |
| 143 |
} |
| 144 |
waitpid($pid, 0); |
| 145 |
# .SHELLSTATUS for a signal gives 128 + the signal number |
| 146 |
my $ret = $?; |
| 147 |
if ($ret > 255) { |
| 148 |
# Solaris 10 perl 5.8.4 puts signal number + 128 into the high 8 bits. |
| 149 |
$ret >>= 8; |
| 150 |
} |
| 151 |
if ($osname ne 'os390') { |
| 152 |
$ret |= 128; |
| 153 |
} |
| 154 |
|
| 155 |
run_make_test('.PHONY: all |
| 156 |
$(shell kill -2 $$$$) |
| 157 |
STAT := $(.SHELLSTATUS) |
| 158 |
all: ; @echo STAT=$(STAT) |
| 159 |
','',"STAT=$ret\n"); |
| 160 |
|
| 161 |
# Test that not-found errors can be redirected |
| 162 |
if ($ERR_command_not_found) { |
| 163 |
$_ = $ERR_command_not_found; |
| 164 |
s/#CMDNAME#/bad-command/g; |
| 165 |
run_make_test(q! |
| 166 |
out := $(shell bad-command 2>&1) |
| 167 |
all: ; @echo '$(.SHELLSTATUS): $(out)' |
| 168 |
!, |
| 169 |
'', "127: $_\n"); |
| 170 |
} |
| 171 |
|
| 172 |
# If we're using pipes for jobserver, then we will close them and not |
| 173 |
# allow them to be available to sub-makes invoked via $(shell ...) |
| 174 |
if (exists $FEATURES{'jobserver'}) { |
| 175 |
run_make_test(q! |
| 176 |
ifeq ($(ELT),) |
| 177 |
default:; @$(MAKE) -f #MAKEFILE# ELT=1 |
| 178 |
else ifeq ($(ELT),1) |
| 179 |
OUTPUT := $(shell $(MAKE) -f #MAKEFILE# ELT=2) |
| 180 |
$(info $(OUTPUT)) |
| 181 |
default:;: $(ELT) |
| 182 |
else |
| 183 |
default:;: $(ELT) |
| 184 |
endif |
| 185 |
!, |
| 186 |
'--no-print-directory -j2 --jobserver-style=pipe', "#MAKE#[2]: warning: jobserver unavailable: using -j1. Add '+' to parent make rule.\n: 2\n: 1"); |
| 187 |
} |
| 188 |
|
| 189 |
# This crashes if we use vfork and don't reset environ properly |
| 190 |
run_make_test(q! |
| 191 |
export PATH = $(shell echo "tests:$$PATH") |
| 192 |
foo = $(shell echo yes) |
| 193 |
|
| 194 |
all:;echo $(foo) |
| 195 |
!, |
| 196 |
'', "echo yes\nyes\n"); |
| 197 |
} |
| 198 |
|
| 199 |
# If we're not using pipes for jobserver, then they are available in sub-makes |
| 200 |
# invoked by $(shell ...) |
| 201 |
if ($port_type eq 'W32' || exists $FEATURES{'jobserver-fifo'}) { |
| 202 |
run_make_test(q! |
| 203 |
ifeq ($(ELT),) |
| 204 |
default:; @$(MAKE) -f #MAKEFILE# ELT=1 |
| 205 |
else ifeq ($(ELT),1) |
| 206 |
OUTPUT := $(shell $(MAKE) -f #MAKEFILE# ELT=2) |
| 207 |
$(info $(OUTPUT)) |
| 208 |
default:;: $(ELT) |
| 209 |
else |
| 210 |
default:;: $(ELT) |
| 211 |
endif |
| 212 |
!, |
| 213 |
'--no-print-directory -j2', ": 2\n: 1"); |
| 214 |
} |
| 215 |
|
| 216 |
1; |