make/tests/scripts/features/dircache
Paul Smith 9e2fa24649 [SV 41273] Allow the directory cache to be invalidated
Each time we invoke a command it's possible that it will change the
filesystem in ways that were not described by the target.  If that
happens but we have cached previous directory contents then we may
make decisions or report results based on obsolete information.

Keep a count of how many commands we've invoked, and remember the
current command count every time we load the contents of a directory.
If we request the directory and the current command count has changed
we know the cache is outdated so reload from scratch.

* NEWS: Announce the change.
* src/makeint.h (command_count): Create a global counter.
* src/main.c (command_count): Ditto.
* src/job.c (reap_children): Increment the counter on job completion.
* src/function.c (func_file): Increment if we write a file.
* src/dir.c (clear_directory_contents): Clear the current contents of
a cached directory.
(struct directory_contents): Remember the counter value.
(struct directory): Remember the counter value for non-existing dirs.
(find_directory): If we have a cached directory and the count hasn't
changed then return it.  Else, clear the previous contents and re-read
from scratch.
* tests/scripts/features/dircache: Add tests of the directory cache.
2020-11-29 17:59:16 -05:00

31 lines
714 B
Perl

# -*-mode: perl-*-
$description = "Test the directory cache behavior.";
# The first wildcard should bring the entire directory into the cache Then we
# create a new file "behind make's back" then see if the next wildcard detects
# it.
run_make_test(q!
_orig := $(wildcard ./*)
$(shell echo > anewfile)
_new := $(wildcard ./*)
$(info diff=$(filter-out $(_orig),$(_new)))
all:;@:
!,
'', "diff=./anewfile\n");
rmfiles('anewfile');
run_make_test(q!
_orig := $(wildcard ./*)
$(file >anewfile)
_new := $(wildcard ./*)
$(info diff=$(filter-out $(_orig),$(_new)))
all:;@:
!,
'', "diff=./anewfile\n");
rmfiles('anewfile');
1;