make/tests/scripts/misc/general4
Paul Smith 60905a8afb [SV 56834] Support local PATH search with posix_spawnp
When using exec we install the child's environment before invoking
execlp(), so commands are found on the child's PATH.  posix_spawnp
searches on the parent's PATH, which we don't want.

Import gnulib's findprog-in module and use it to search the child's
PATH, then use posix_spawn() to run it.

Also, posix_spawn() does not fall back to trying sh on ENOEXEC, as
execlp() does, so implement that as well.

* bootstrap.conf: Add the findprog-in gnulib module
* src/job.c: Include findprog.h if we're using posix_spawn.
(start_job_command): Remove the handling of child->cmd_name,
(child_execute_job): and add it here.  Look up the command to be
run in the child's path and invoke it if found.  If it fails with
ENOEXEC then retry it as an argument to the default shell.
* tests/scripts/misc/general4: Test makefile PATH assignments.
* tests/scripts/features/targetvars: Ditto, for target variables.
2019-09-08 15:12:40 -04:00

124 lines
2.7 KiB
Perl

# -*-perl-*-
$description = "\
This tests random features of make's algorithms, often somewhat obscure,
which have either broken at some point in the past or seem likely to
break.";
run_make_test('
# Make sure that subdirectories built as prerequisites are actually handled
# properly.
all: dir/subdir/file.a
dir/subdir: ; @echo mkdir -p dir/subdir
dir/subdir/file.b: dir/subdir ; @echo touch dir/subdir/file.b
dir/subdir/%.a: dir/subdir/%.b ; @echo cp $< $@',
'', "mkdir -p dir/subdir\ntouch dir/subdir/file.b\ncp dir/subdir/file.b dir/subdir/file.a\n");
# Test implicit rules
&touch('foo.c');
run_make_test('foo: foo.o',
'CC="@echo cc" OUTPUT_OPTION=',
'cc -c foo.c
cc foo.o -o foo');
unlink('foo.c');
# Test implicit rules with '$' in the name (see se_implicit)
run_make_test(q!
%.foo : baz$$bar ; @echo 'done $<'
%.foo : bar$$baz ; @echo 'done $<'
test.foo:
baz$$bar bar$$baz: ; @echo '$@'
!,
'',
"baz\$bar\ndone baz\$bar");
# Test implicit rules with '$' in the name (see se_implicit)
# Use the '$' in the pattern.
run_make_test(q!
%.foo : %$$bar ; @echo 'done $<'
test.foo:
test$$bar: ; @echo '$@'
!,
'',
"test\$bar\ndone test\$bar");
# Make sure that subdirectories built as prerequisites are actually handled
# properly... this time with '$'
run_make_test(q!
all: dir/subdir/file.$$a
dir/subdir: ; @echo mkdir -p '$@'
dir/subdir/file.$$b: dir/subdir ; @echo touch '$@'
dir/subdir/%.$$a: dir/subdir/%.$$b ; @echo 'cp $< $@'
!,
'', "mkdir -p dir/subdir\ntouch dir/subdir/file.\$b\ncp dir/subdir/file.\$b dir/subdir/file.\$a\n");
# Test odd whitespace at the beginning of a line
run_make_test("
all:
\f
\\
\f \\
\013 \\
all: ; \@echo hi
",
'', "hi\n");
# SV-56834 Ensure setting PATH in the makefile works properly
mkdir('sd', 0775);
open(my $fh, '>', 'sd/foobar');
print $fh "exit 0\n";
close($fh);
chmod 0755, 'sd/foobar';
run_make_test(q!
PATH := sd
all: ; foobar
!,
'', "foobar\n");
# Don't use the general PATH if not found on the target path
$extraENV{PATH} = "$ENV{PATH}:sd";
run_make_test(q!
PATH := ..
all: ; foobar
!,
'', "foobar\n#MAKE#: foobar: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#;3: all] Error 127", 512);
unlink('sd/foobar');
rmdir('sd');
# Ensure that local programs are not found if "." is not on the PATH
open(my $fh, '>', 'foobar');
print $fh "exit 0\n";
close($fh);
chmod 0755, 'foobar';
run_make_test(q!
PATH := ..
all: ; foobar
!,
'', "foobar\n#MAKE#: foobar: $ERR_no_such_file\n#MAKE#: *** [#MAKEFILE#;3: all] Error 127", 512);
unlink('foobar');
1;