[SV 62324] Simplify set_file_variables by passing in the stem

Previously we always used the file->stem value as our stem in
set_file_variables(); when that wasn't correct we had to temporarily
set that value while the function was called, then reset it afterward.
This led to issues (for example when we assumed the stem was a cached
string but it wasn't).

Avoid this by passing in the stem as an argument so that different
values can be provided.

Add tests to verify this.

* src/commands.c (set_file_variables): Take second parameter stem to
relieve the callers of set_file_variables() from setting/restoring
file->stem.
* src/commands.h (set_file_variables): Ditto.
(execute_file_commands): Pass file->stem to set_file_variables().
* src/file.c (expand_deps): Pass d->stem to set_file_variables() and
remove set and restore of file->stem.
* src/implicit.c (pattern_search): Pass stem to set_file_variables()
and remove set and restore of file->stem.
* tests/scripts/features/se_explicit: Add new tests.
* tests/scripts/features/se_implicit: Ditto.
* tests/scripts/features/se_statpat: Ditto.
* tests/scripts/variables/automatic: Ditto.
This commit is contained in:
Dmitry Goncharov
2022-04-23 20:34:18 -04:00
committed by Paul Smith
parent bb21dd4d2d
commit 8c2aa889bb
8 changed files with 59 additions and 26 deletions

View File

@@ -91,6 +91,30 @@ mbr.src: ; @:',
'',
'mbr');
# Same as above with second expansion.
#
run_make_test('
.SECONDEXPANSION:
.SUFFIXES: .b .src
p:=mbr.src
mbr.b: $$p
@echo $*
mbr.src: ; @:',
'',
'mbr');
# Test that $* is set to empty string for unknown suffixes.
run_make_test('
mbr.b: mbr.src
@echo star=$*
mbr.src: ; @:',
'',
"star=\n");
# TEST #3 -- test for Savannah bug #8154
# Make sure that nonexistent prerequisites are listed in $?, since they are
# considered reasons for the target to be rebuilt.