Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does make store its cache?

Make seems to compare a file modification time with some sort of internal cache of modification times. Does anyone know where is this cache located or how to access it?

like image 337
Matt Avatar asked Feb 23 '16 21:02

Matt


People also ask

Where does cache get stored?

The data in a cache is generally stored in fast access hardware such as RAM (Random-access memory) and may also be used in correlation with a software component. A cache's primary purpose is to increase data retrieval performance by reducing the need to access the underlying slower storage layer.

Does make have a cache?

There is no cache.

Where is cache stored on computer?

In modern computers, the cache memory is stored between the processor and DRAM; this is called Level 2 cache. On the other hand, Level 1 cache is internal memory caches which are stored directly on the processor.

Where does Python store cache?

It depends on the OS. I believe it is in ~\AppData\Local\pip\cache on Windows. A cache is not always human-readable, as in this case.


2 Answers

Use a utility such as strace to see what it's doing. Here we can follow all file actions (-e trace=file) that the make program performs.

Let's say that we have foo.c and a foo which is built from it using a simple Makefile that looks like:

$ cat Makefile
foo: foo.c

Let's run make:

$ strace -e trace=file make
execve("/usr/bin/make", ["make"], [/* 20 vars */]) = 0
...
open("Makefile", O_RDONLY)              = 3
stat("Makefile", {st_mode=S_IFREG|0644, st_size=11, ...}) = 0
...
stat("foo", 0x7ffd4373c8c0)             = -1 ENOENT (No such file or directory)
stat("foo.c", {st_mode=S_IFREG|0644, st_size=36, ...}) = 0
cc     foo.c   -o foo
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=27717, si_status=0, si_utime=0, si_stime=0} ---
stat("foo", {st_mode=S_IFREG|0755, st_size=8549, ...}) = 0
+++ exited with 0 +++

Here you see that it checks for the existence of foo and fails to find it, it checks for the existence of foo.c, and it then calls the rule to compile it.

Now you can call make again, and you get slightly different results:

$ strace -e trace=file make
...
stat("foo", {st_mode=S_IFREG|0755, st_size=8549, ...}) = 0
stat("foo.c", {st_mode=S_IFREG|0644, st_size=36, ...}) = 0
make: `foo' is up to date.
+++ exited with 0 +++

If there was some kind of a cache file being used, we'd expect to see an open() and a read() against it. If this cache was being used between runs, then we'd expect to see a write() to it as well.

like image 72
unpythonic Avatar answered Oct 22 '22 09:10

unpythonic


The cache as such is your file system:

  • The make program reads the makefile,
  • determines the list of targets and dependencies,
  • observes the timestamps for these targets and dependencies,
  • works backward from the target you specify (or the default target, i.e., the first one in the makefile), to find a target whose dependencies are newer.
  • it runs the rule for the out-of-date target, and repeats until everything is up to date.

As it performs rules, the target it builds is expected to be updated (newer), but it moves on to the next out-of-date target from its initial inspection of the filesystem even if the target is not actually updated.

Re-executing make forces it to start over with the analysis, using the current state of your file system.

like image 30
Thomas Dickey Avatar answered Oct 22 '22 09:10

Thomas Dickey